这章就是从ifnet来说起的,每个网络设备都有一个自己的ifnet结构,这个结构里有ifaddr链表,也就是每个接口的
所有地址,可以是一个,也可以是多个形成的链表。然后下面有一个ifqueue这就是指向mbuf链表的;然后还有很多
处理函数指针,来初始化接口、发送分组等功能。
struct ifnet {
/* 这是记录接口类型的,这里的接口类型就是以太网/或者
* SLIP或者环回接口 */
char *if_name; /* name, e.g. ``en‘‘ or ``lo‘‘ */
/* 这是要形成ifnet结构链表的,因为每个接口都有自己的ifnet结构,
* 比如有两个以太网卡,就有两个这个结构,用这个指针连起来*/
struct ifnet *if_next; /* all struct ifnets are chained */
/* 然后每个接口可以有多个地址可能,比如以太网的,
* 我们可以设置多个IP地址给它,形成一个链 */
struct ifaddr *if_addrlist; /* linked list of addresses per if */
/* 这个还不知道具体是什么,但是混杂看侦听个数,让我想起libpcap库
* 设置混杂模式了*/
int if_pcount; /* number of promiscuous listeners */
/* 包过滤使用,以后再看看 */
caddr_t if_bpf; /* packet filter structure */
/* 这个和下面那个差不多不过它不管什么接口类型了,都统一编号了
* 所以编号是唯一的*/
u_short if_index; /* numeric abbreviation for this if */
/*前面有这个接口的类型了,万一要是这种接口有多个,
* 然后它再标识为0/1/...*/
short if_unit; /* sub-unit for lower level driver */
/*这个记录时间但具体细节不清楚*/
short if_timer; /* time ‘til if_watchdog called */
/* 这个接口的状态和属性,比如工没工作,能干什么 */
short if_flags; /* up/down, broadcast, etc. */
struct if_data {
/* generic interface information */
u_char ifi_type; /* ethernet, tokenring, etc */
u_char ifi_addrlen; /* media address length */
u_char ifi_hdrlen; /* media header length */
u_long ifi_mtu; /* maximum transmission unit */
u_long ifi_metric; /* routing metric (external only) */
u_long ifi_baudrate; /* linespeed */
/* volatile statistics */
u_long ifi_ipackets; /* packets received on interface */
u_long ifi_ierrors; /* input errors on interface */
u_long ifi_opackets; /* packets sent on interface */
u_long ifi_oerrors; /* output errors on interface */
u_long ifi_collisions; /* collisions on csma interfaces */
u_long ifi_ibytes; /* total number of octets received */
u_long ifi_obytes; /* total number of octets sent */
u_long ifi_imcasts; /* packets received via multicast */
u_long ifi_omcasts; /* packets sent via multicast */
u_long ifi_iqdrops; /* dropped on input, this interface */
u_long ifi_noproto; /* destined for unsupported protocol */
struct timeval ifi_lastchange;/* last updated */
} if_data;
/* procedure handles */
/* 这是初始化等处理函数 */
int (*if_init) /* init routine */
__P((int));
int (*if_output) /* output routine (enqueue) */
__P((struct ifnet *, struct mbuf *, struct sockaddr *,
struct rtentry *));
int (*if_start) /* initiate output routine */
__P((struct ifnet *));
int (*if_done) /* output complete routine */
__P((struct ifnet *)); /* (XXX not used; fake prototype) */
int (*if_ioctl) /* ioctl routine */
__P((struct ifnet *, u_long, caddr_t));
int (*if_reset)
__P((int)); /* new autoconfig will permit removal */
int (*if_watchdog) /* timer routine */
__P((int));
/* 这就是指向mbuf链表的结构 */
struct ifqueue {
struct mbuf *ifq_head;
struct mbuf *ifq_tail;
int ifq_len;
int ifq_maxlen;
int ifq_drops;
} if_snd; /* output queue */
};
原文:http://my.oschina.net/bxxfighting/blog/381122