mbuf结构体
2009-05-13 08:00:24来源:未知 阅读 ()
TCP/IP详解第二卷实现主要讲的是BSD的协议栈实现。看协议栈代码,首先看的就是经典的mbuf结构了。原来觉得mbuf结构比较复杂,硬着头皮看了几天后,感觉思路上清晰了一些。于是准备写点东西把理解到的一点点先记下来,省得以后忘记了。
书上是以4.4BSDlite源代码为基础讲的。可以说是目前各个bsd发行版的基础。在此基础上,FreeBSD、NetBSD、OpenBSD做了稍许的改动。下面是lite版的mbuf声明代码:
/*
* Mbufs are of a single size, MSIZE (machine/machparam.h), which
* includes overhead. An mbuf may add a single "mbuf cluster" of size
* MCLBYTES (also in machine/machparam.h), which has no additional overhead
* and is used instead of the internal data area; this is done when
* at least MINCLSIZE of data must be stored.
*/
#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
/* header at beginning of each mbuf: */
struct m_hdr {
struct mbuf *mh_next; /* next buffer in chain */
struct mbuf *mh_nextpkt; /* next chain in queue/record */
caddr_t mh_data; /* location of data */
int mh_len; /* amount of data in this mbuf */
short mh_type; /* type of data in this mbuf */
short mh_flags; /* flags; see below */
};
/* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
struct pkthdr {
struct ifnet *rcvif; /* rcv interface */
int len; /* total packet length */
};
/* description of external storage mapped into mbuf, valid if M_EXT set */
struct m_ext {
caddr_t ext_buf; /* start of buffer */
void (*ext_free)(); /* free routine if not the usual */
u_int ext_size; /* size of buffer, for ext_free */
};
struct mbuf {
struct m_hdr m_hdr;
union {
struct {
struct pkthdr MH_pkthdr; /* M_PKTHDR set */
union {
struct m_ext MH_ext; /* M_EXT set */
char MH_databuf[MHLEN];
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:一些KDE编程的资源
下一篇:FreeBSD的起源
- OpenBSD 4.5 2009-05-13
- NetBSD 5.0发布 2009-05-13
- 为Bash shell定义Home, Del, Insert热键 2009-05-13
- freebsd的目录结构 2009-05-13
- Tips for Running Linux Binaries on FreeBSD 2009-05-13
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash