📄 net.h
字号:
/*
* FILENAME: net.h
*
* Copyright 1996- 2000 By InterNiche Technologies Inc. All rights reserved
*
* Definitions for the basic network interface object, the NET structure.
*
* MODULE: INET
*
*
* PORTABLE: yes
*/
/* Additional Copyrights: */
/* Portions Copyright 1990-1996 by NetPort Software.
* Portions Copyright 1986 by Carnegie Mellon
* Portions Copyright 1983,1984,1985 by the Massachusetts Institute
* of Technology
*/
#ifndef _NET_H_
#define _NET_H_ 1
#include "q.h"
#include "profiler.h"
/* some SNMP-derived net interface types, per rfc 1156, pg 14 */
#define ETHERNET 6
#define TOKEN802 9
#define SLIP 28 /* SLIP, per rfc1213 */
#define PPP 23 /* PPP, per rfc1213 */
#define LOOPIFTYPE 24 /* loopback, per rfc1213 */
/* ...and a hack type for IPX tunnel... */
#define EXTERN_IPX 205 /* netx.exe, not internal IPX */
#define PPPOE 206 /* Not in RFC1156, add unique number */
/* The following structure is the iface MIB from rfc1213. Most fields are
* simple counters and are used as such by the InterNiche networking code.
* Two exceptions are ifAdminStatus and ifOperStatus. We have tried to
* keep their use consistent with the RFC.
* When an interface (NET) is created, it is marked down (i.e. the
* ifAdminStatus is set to the "down" position) so that it can safely
* be configured (a separate step), and then marked "up" once
* configuration is complete. A NET with ifAdminStatus==DOWN will
* not be used to send by the inet code.
* ifOperStatus should indicate the actual state of the link. For
* ethernet this probably means UP almost all the time. For PPP it means
* UP when connected, DOWN other wise; thus a modem in AUTOANSWER would
* have the same ifAdminStatus and ifOperStatus (UP, DOWN) as a
* disconnected modem.
*/
struct IfMib
{
u_long ifIndex; /* 1 - entry in nets[] */
u_char * ifDescr; /* 2 - string describing interface */
u_long ifType; /* 3 - Ether, token, etc */
u_long ifMtu; /* 4 - Max Transmission Unit */
u_long ifSpeed; /* 5 - Theoretical max in bits/sec */
u_char * ifPhysAddress; /* 6 - node address */
u_long ifAdminStatus; /* 7 - up=1, down=2, testing=3 */
u_long ifOperStatus; /* 8 - up=1, down=2, testing=3 */
u_long ifLastChange; /* 9 - time of current ifOperState */
u_long ifInOctets; /* 10 - bytes received */
u_long ifInUcastPkts; /* 11 - DELIVERED unicast packets */
u_long ifInNUcastPkts; /* 12 - non-unicast delivered packets */
u_long ifInDiscards; /* 13 - dropped, ie no buffers */
u_long ifInErrors; /* 14 - bad received packets */
u_long ifInUnknownProtos;/* 15 - unknown protocols */
u_long ifOutOctets; /* 16 - bytes sent */
u_long ifOutUcastPkts; /* 17 - unicasts sent */
u_long ifOutNUcastPkts; /* 18 - non-unicast packets sent */
u_long ifOutDiscards; /* 19 - send dropped - non-error */
u_long ifOutErrors; /* 20 - send dropped - errors */
u_long ifOutQLen; /* 21 - packets queued for send */
};
typedef struct IfMib * IFMIB;
extern IFMIB ifmibs[]; /* preallocated interface MIB structures */
#ifndef IF_NAMELEN
#define IF_NAMELEN 4 /* default max length for iface names */
#endif
/* The NET struct has all the actual interface characteristics which
* are visible at the internet level and has pointers to the
* interface handling routines.
*/
#ifdef IP_MULTICAST
struct in_multi;
#endif /* IP_MULTICAST */
struct net
{
struct net * n_next; /* pointer next net */
char name[IF_NAMELEN]; /* device ID name */
int (*n_init)(int); /* net initialization routine */
/* MAC drivers can set one of the next two for sending; other
* should be left as NULL:
*/
int (*raw_send)(struct net *, char*, unsigned);
/* put raw data on media */
int (*pkt_send)(struct netbuf *); /* send packet on media */
int (*n_close)(int); /* net close routine */
int (*n_reg_type)(unshort, struct net*);
/* register a MAC type, ie 0x0800 for IP */
void (*n_stats)(void * pio, int iface);
/* per device-type (ODI, pktdrv) statistics dump */
int n_lnh; /* net's local net header size */
int n_mtu; /* net's largest legal buffer size size */
ip_addr n_ipaddr; /* interface's internet address */
int n_snbits ; /* number of subnet bits */
ip_addr snmask; /* interface's subnet mask */
ip_addr n_defgw; /* the default gateway for this net */
ip_addr n_netbr; /* our network broadcast address */
ip_addr n_netbr42; /* our (4.2BSD) network broadcast */
ip_addr n_subnetbr; /* our subnetwork broadcast address */
unsigned n_hal; /* Hardware address length */
char * n_haddr; /* Pointer to hardware address, size= n_hal */
struct IfMib mib; /* the actual iface MIB image */
IFMIB n_mib; /* pointer to mib for backward compatability */
void * n_local; /* pointer to custom info, null if unused */
int n_flags; /* mask of the NF_ bits below */
#ifdef DYNAMIC_IFACES
int (*n_setstate)(struct net*, int);
/* set link state up/down */
#endif /* DYNAMIC_IFACES */
#ifdef IP_MULTICAST
/* register a multicast list */
int (*n_mcastlist)(struct in_multi *);
#endif /* IP_MULTICAST */
};
typedef struct net * NET;
extern unsigned ifNumber; /* how many links (number of nets[] used) */
/* bit definitions for net.n_flags */
#define NF_BCAST 0x0001 /* device supports broadcasts */
#define NF_MCAST 0x0002 /* device supports multicast */
#define NF_DYNIF 0x0004 /* device is a dynamic interface */
#define NF_NBPROT 0x0008 /* driver will maintain pkt->nb_prot field */
/* parameters to ni_set_state - match RFC-1213 ifXxxxStatus */
#define NI_UP 1
#define NI_DOWN 2
#ifdef DYNAMIC_IFACES
struct niconfig_0 /* struct for iface configuration info */
{
ip_addr n_ipaddr;
ip_addr snmask;
};
int ni_create(NET * ifp, /* OUT - created handle */
int (*create_device)(NET newifp, void * bindinfo), /* IN */
char * name, /* IN - short text name of device */
void * blindinfo);
int ni_get_config(NET, struct niconfig_0 *);
int ni_set_config(NET, struct niconfig_0 *);
int ni_set_state(NET, int opcode);
int ni_delete(NET ifp);
#endif /* DYNAMIC_IFACES */
extern unsigned ifNumber; /* how many ifaces in system */
/* In non-dynamic interface systems STATIC_NETS will be the same as
* MAXNETS, so don't force all the ipport.h_h files to define it.
*/
#ifndef STATIC_NETS
#define STATIC_NETS MAXNETS
#endif
extern NET nets[MAXNETS]; /* pointers to the static network structs */
extern queue netlist; /* master list of nets, static & dynamic */
#ifndef MINI_IP /* Declare things defined away in the mini version */
/* define a way to convert NET pointers to index numbers */
int if_netnumber(NET); /* get index into nets list for NET */
NET if_getbynum(int); /* get static/dynamic NET from index */
int isbcast(NET ifc, u_char * addr); /* is MAC address broadcast? */
extern int reg_type(unshort); /* register prot type with all net drivers */
extern int MaxLnh; /* Largest local net header size */
extern int MaxMtu; /* Largest net MTU (packet) size */
#endif /* MINI_IP */
/* alias macro to support older code */
#define net_num(net) if_netnumber(net)
extern queue rcvdq;
/* Macro for passing IP addresses to printf octet at a time. usage:
* printf("IP is %u.%u.%u.%u\n", PUSH_IPADDR(ip)); Since we store IP
* addresses in net endian, it's endian sensitive.
*/
#if (BYTE_ORDER==LITTLE_ENDIAN)
#define PUSH_IPADDR(ip)\
(unsigned)(ip&0xff),\
(unsigned)((ip>>8)&0xff),\
(unsigned)((ip>>16)&0xff),\
(unsigned)(ip>>24)
#else
#define PUSH_IPADDR(ip)\
(unsigned)(ip>>24),\
(unsigned)((ip>>16)&0xff),\
(unsigned)((ip>>8)&0xff),\
(unsigned)(ip&0xff)
#endif
/* Here are the debugging things. DEBUG is a global variable whose
* value determines what sort of debugging messages will be displayed
* by the system.
*/
extern unsigned NDEBUG; /* Debugging options */
/* BUGHALT on a gross applications level error
* that is detected in the network code
*/
#define BUGHALT 0x01 /* deprecated */
/* Works in conjuction with other options: BUGHALT:
* Dump all arriving packets PROTERR: Dump header for level of error
* NETTRACE, etc.: Dump headers at trace
*/
#define DUMP 0x02
#define INFOMSG 0x04 /* Print general informational messages */
#define NETERR 0x08 /* Display net interface error messages */
#define PROTERR 0x10 /* Display protocol level error messages */
#define NETRACE 0x20 /* Trace packet in link level net layer */
#define TMO 0x40 /* Print message on timeout */
#define APTRACE 0x80 /* Trace packet through application */
#define TPTRACE 0x100 /* Transport protocol (UDP/TCP/RVD) trace */
#define IPTRACE 0x200 /* Trace packet in internet layer */
#define UPCTRACE 0x400 /* trace upcall progress - DANGEROUS! */
#define LOSSY_RX 0x800 /* do lossey receive */
#define LOSSY_TX 0x1000 /* do lossey transmit */
#ifdef LOSSY_IO
/* support for an option that allows us to deliberatly loose packets */
extern int in_lastloss; /* packets since last loss */
extern int in_lossrate; /* number of packets to punt (3 is "1 in 3") */
#endif /* LOSSY_IO */
/* add prototypes -JB- */
int Netinit(void);
void netclose(void);
void net_stats(void);
/* C language misc prototypes for IP stack
* these are not strictly NET related, but have to go somewhere
*/
u_long c_older(u_long ct1, u_long ct2); /* return older ctick */
void panic(char * msg); /* call on fatal errors, like UNIX panic() */
unsigned long getipadd(char *); /* resolve hostname to IP address */
/*char * parse_ipad(unsigned long *, unsigned *, char *);*/ /* (yaxon modify) */
char * parse_ipad(ip_addr *, unsigned *, char *);
char * print_ipad(unsigned long); /* format IP addr for print */
char * startup(void); /* master network "start" cmd, in startup.c */
#ifndef MINI_IP
void exit_hook(void (*func)(void)); /* like atexit() */
void ip_exit(void); /* call exit_hook funcs */
#endif /* MINI_IP */
/* ip2mac() Trys to put IP packet on ethernet, resolving ip address via arp. */
//int ip2mac(PACKET, ip_addr);
void pktdemux(void); /* process received packets */
#endif /* _NET_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -