mbuf Structures

An mbuf structure is a memory buffer for network data. Commonly, this data spans multiple mbuf structures, which are arranged into a linked list known as an mbuf chain.

struct mbuf is defined in the <sys/mbuf.h> header as follows:

struct mbuf {
      struct m_hdr m_hdr;
      union {
                struct {
                        struct pkthdr MH_pkthdr;
                        union {
                                struct m_ext MH_ext;
                                char MH_databuf[MHLEN];
                        } MH_dat;
                } MH;
                char M_databuf[MLEN];
        } M_dat;
};

Every mbuf structure contains a buffer for data and a header, which looks like this:

struct m_hdr { struct mbuf *mh_next; /* Next ...

Get FreeBSD Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.