Ethernet IP TCP UDP 协议头部格式

简介:

The Ethernet header structure is shown in the illustration below:

以太网头部14 bytes

Destination
Source
Len
Data unit + pad
FCS
(6 bytes)
(6 bytes)
(2)
(46-1500 bytes)
(4 bytes)
Ethernet header structure

The IP header structure is as follows:

IP头部20 bytes

4
8
16
32 bits
Ver.
IHL
Type of service
Total length
Identification
Flags
Fragment offset
Time to live
Protocol
Header checksum
Source address
Destination address
Option + Padding
Data
IP header structure

The TCP header structure is as follows:

TCP头部20 bytes

16
32 bits
Source port
Destination port
Sequence number
Acknowledgement number
Offset
Resrvd
U
A
P
R
S
F
Window
Checksum
Urgent pointer
Option + Padding
Data
TCP header structure

The UDP header structure is shown as follows:

UDP头部8 bytes

16
32 bits
Source port
Destination port
Length
Checksum

Data
UDP header structure

一些协议头部的定义:

复制代码
struct ip 
{
#if BYTE_ORDER == LITTLE_ENDIAN
    u_char    ip_hl:4,        /* header length */
              ip_v:4;            /* version */
#endif
#if BYTE_ORDER == BIG_ENDIAN
    u_char    ip_v:4,            /* version */
              ip_hl:4;        /* header length */
#endif
    u_char    ip_tos;            /* type of service */
    short    ip_len;            /* total length */
    u_short    ip_id;            /* identification */
    short    ip_off;            /* fragment offset field */
    u_char    ip_ttl;            /* time to live */
    u_char    ip_p;            /* protocol */
    u_short    ip_sum;            /* checksum */
    struct    in_addr ip_src,ip_dst;    /* source and dest address */
};

struct udphdr 
{
    u_short    uh_sport;        /* source port */
    u_short    uh_dport;        /* destination port */
    short    uh_ulen;        /* udp length */
    u_short    uh_sum;            /* udp checksum */
};

struct tcphdr 
{
    u_short    th_sport;        /* source port */
    u_short    th_dport;        /* destination port */
    tcp_seq    th_seq;            /* sequence number */
    tcp_seq    th_ack;            /* acknowledgement number */
#if BYTE_ORDER == LITTLE_ENDIAN
    u_char    th_x2:4,        /* (unused) */
              th_off:4;        /* data offset */
#endif
#if BYTE_ORDER == BIG_ENDIAN
    u_char    th_off:4,        /* data offset */
              th_x2:4;        /* (unused) */
#endif
    u_char    th_flags;
    u_short    th_win;            /* window */
    u_short    th_sum;            /* checksum */
    u_short    th_urp;            /* urgent pointer */
};
复制代码

更多网络协议格式细节参考:http://www.protocols.com/pbook/

 

作者: 阿凡卢
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
http://www.cnblogs.com/luxiaoxun/archive/2012/08/08/2628627.html
相关文章
|
12月前
|
网络协议
TCP/IP与OPC协议的深度比较
总的来说,TCP/IP和OPC协议各有其优点和应用场景。TCP/IP协议是网络通信的基础,而OPC协议则是工业自动化领域的重要工具。在实际应用中,我们需要根据具体的需求和场景,选择合适的协议。
446 11
|
网络协议 网络安全 网络虚拟化
本文介绍了十个重要的网络技术术语,包括IP地址、子网掩码、域名系统(DNS)、防火墙、虚拟专用网络(VPN)、路由器、交换机、超文本传输协议(HTTP)、传输控制协议/网际协议(TCP/IP)和云计算
本文介绍了十个重要的网络技术术语,包括IP地址、子网掩码、域名系统(DNS)、防火墙、虚拟专用网络(VPN)、路由器、交换机、超文本传输协议(HTTP)、传输控制协议/网际协议(TCP/IP)和云计算。通过这些术语的详细解释,帮助读者更好地理解和应用网络技术,应对数字化时代的挑战和机遇。
1417 3
|
网络协议 安全 Go
Go语言进行网络编程可以通过**使用TCP/IP协议栈、并发模型、HTTP协议等**方式
【10月更文挑战第28天】Go语言进行网络编程可以通过**使用TCP/IP协议栈、并发模型、HTTP协议等**方式
329 13
|
网络协议 算法 网络性能优化
计算机网络常见面试题(一):TCP/IP五层模型、TCP三次握手、四次挥手,TCP传输可靠性保障、ARQ协议
计算机网络常见面试题(一):TCP/IP五层模型、应用层常见的协议、TCP与UDP的区别,TCP三次握手、四次挥手,TCP传输可靠性保障、ARQ协议、ARP协议
|
网络协议 网络性能优化
详解TCP/IP协议以及UDP
详解TCP/IP协议以及UDP
415 0
|
网络协议 算法 数据格式
【TCP/IP】UDP协议数据格式和报文格式
【TCP/IP】UDP协议数据格式和报文格式
1767 3
|
XML JSON 网络协议
【TCP/IP】自定义应用层协议,常见端口号
【TCP/IP】自定义应用层协议,常见端口号
585 3
|
网络协议 网络架构 数据格式
TCP/IP基础:工作原理、协议栈与网络层
TCP/IP(传输控制协议/互联网协议)是互联网通信的基础协议,支持数据传输和网络连接。本文详细阐述了其工作原理、协议栈构成及网络层功能。TCP/IP采用客户端/服务器模型,通过四个层次——应用层、传输层、网络层和数据链路层,确保数据可靠传输。网络层负责IP寻址、路由选择、分片重组及数据包传输,是TCP/IP的核心部分。理解TCP/IP有助于深入掌握互联网底层机制。
2066 2
|
网络协议 Java API
TCP/IP协议以及UDP(超详细,看这一篇就够了)
TCP/IP协议以及UDP(超详细,看这一篇就够了)
1180 0
|
网络协议 网络架构
计算机网络——计算机网络体系结构(1/4)-常见的计算机网络体系结构(OSI体系、TCP/IP体系、原理体系五层协议)
计算机网络——计算机网络体系结构(1/4)-常见的计算机网络体系结构(OSI体系、TCP/IP体系、原理体系五层协议)
615 0
下一篇
开通oss服务