本文,集中汇集了各个协议头部,通过理解头部,可以帮助理解网络协议的组成,或者应用开发等。
然而,一开始学习的时候,发现在/usr/include目录里面,子目录Linux和netinet都分别有定义网络协议的相关文件。后来:whats-the-practical-difference-between-the-headers-linux-in-h-and-netinet-in,
链接
结论:
Linux子目录是给
内核开发
使用,而我们一般
应用开发
是使用netinet目录下的头文件。
为什么要写这篇文章?上面已经给出了一部分原因了,还有就是,作为嵌入式工程师或者是网络工程师,我确实感受到了网络的需求,有一次实现多网卡切换,就需要修改MAC帧结构。
Linux网络结构体与定义文件,
链接:帮助搜索文件位置
顺序
- MAC帧
- ARP协议结构
- IP帧
- ICMP协议结构
- UDP帧
- TCP帧
MAC帧
net/ethernet.h
/* This is a name for the 48 bit ethernet address available on many systems. */
struct ether_addr
{
u_int8_t ether_addr_octet[ETH_ALEN];
} __attribute__ ((__packed__));
struct ether_header
{
u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */
u_int16_t ether_type; /* packet type ID field */
} __attribute__ ((__packed__));
ARP协议结构
net/if_ether.h