Settings to connect C procedures to core settings, - Getting started

xiaoxiao2021-03-06  64

Settings to connect C to core settings

Author: xie_minix

1. Settings file / sys / arch / i386 / conf / makefile

(Next to ziple.c into the core)

Add Sample.o after objs = ..., add the source file path $ s / net / sample.c at cflig = ...

Of course, it is assumed that SAMPLE.C is placed under the / sys / net directory.

There is also a description of the object file and the source file.

The following two lines describe: Sample.O: $ S / NET / SAMPLE.C

$ {Normal_c}

2. Design specification for Sample.c

The following header must be included:

#include

#include

#include

#include

#include

#include

#include

#include

#include

The above header files must be included in the editor-related core routine. And must be in order.

Some relevant header files are included when designing the network underlayer design. For the Sample.c we want to do, you need to have the following file:

#include

#include

#include

#include

#include

#include / * This is your own header file, you can put some of your own structure or predefined in this file * /

Now we use Sample.c to implement a simple monitoring network packet receiving total number.

/ * / 帖子 帖子 帖子 帖子 帖子 帖子 / * /

/ * Author: xie_minix * /

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

Int Sample (IFP)

Struct IFNet * IFP;

{

Return (INT); / * Ifp is the core data structure of the network adapter, records each statistics, if_ibytes is the total number of Input Packets of the NIC * /

}

The entire function function is just returns the number of receiving packets for the network card.

Below is the Sample.h header file, the prototype of the function must be applied in the header file.

/ * /SYS/NET/Sample.h * /

/ * Author: xie_minix * /

#ifndef _net_sample_h_

#define _net_sample_h_ # ifdef _kernel

INT Sample (struct ifnet *);

#ENDIF

#ENDIF

This document is only a simple to declare the function used in the core.

To call this function, you must know that ifnet.ifnet is more common in /sys/net/if_ethersubr.c. So we can consider calling this function here.

Note: if_ethersubr.c is an Ethernet universal code.

To reference the number of Sample (IFP), you must join the header file in if_ethersubr.c:

#include

Call can be scheduled to be in the ether_input () function, such as whether it is placed on whether the NIC is activated. which is:

IF ((ifp-> if_flags & imp_up) == 0) {

m_freem (m);

Return;

}

Add:

TMP_SAMPLE = SAMPLE (IFP);

Printf ("Device% C INPUT Packets:% D", IFP-> if_xname, TMP_SAMPLE);

Of course, the temporary variable TMP_SAMPLE should be declared in the input_ether () function.

which is:

Ether_INPUT (IFP, EH, M)

{... Other stated variables

INT TMP_SAMPLE; / * As long as this is the line. * /

...

This is just examples. In fact, we must get the number of packets that can be directly Printf ("Device% C Input Packets:% D", IFP-> if_xname, IFP-> if_ipackets);

The number of packages can be obtained.

In addition, the compilation core is read.

Take the i386 structure system:

CD / SYS / ARCH / I386 / CONF

Config Your Setup File

CD ../compile/ Your setting file

Make depe

Make

MV / NetBSD /NETBSD.OLD This is NetBSD. mv / bsd /bsd.old This is OpenBSD

MV NetBSD / NetBSD or MV BSD / BSD is the same

转载请注明原文地址:https://www.9cbs.com/read-110942.html

New Post(0)