Ethernet IP TCP UDP 协议头部格式及大小

http://www.cnblogs.com/luxiaoxun/archive/2012/08/08/2628627.html


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/

 


  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ethernet/IP是一种工业领域常用的通信协议它基于以太网技术,并使用了CIP(Common Industrial Protocol)作为应用层协议。下面是Ethernet/IP通讯协议报的格式: 1. 以太网头部Ethernet Frame Header): - 目标MAC地址(Destination MAC Address):指示数据包应该发送到哪个设备。 - 源MAC地址(Source MAC Address):指示数据包的发送者是谁。 - 类型(Type):指示上层协议的类型,对于Ethernet/IP来说,类型字段的值为0x0800。 2. IP头部IP Header): - 版本(Version):指示IP协议的版本号。 - 首部长度(Header Length):指示IP头部的长度。 - 服务类型(Service Type):指示数据包的优先级和服务质量要求。 - 总长度(Total Length):指示整个IP数据包的长度。 - 标识(Identification):用于标识IP数据包的唯一性。 - 标志(Flags):用于分片和重组IP数据包。 - 片偏移(Fragment Offset):用于指示分片后的片段在原始数据包中的位置。 - 生存时间(Time to Live):指示数据包在网络中可以存在的时间。 - 协议(Protocol):指示上层协议的类型,对于Ethernet/IP来说,协议字段的值为0x11,表示使用UDP协议。 - 校验和(Header Checksum):用于校验IP头部的完整性。 - 源IP地址(Source IP Address):指示数据包的发送者IP地址。 - 目标IP地址(Destination IP Address):指示数据包应该发送到哪个设备的IP地址。 3. UDP头部UDP Header): - 源端口号(Source Port):指示数据包的发送者端口号。 - 目标端口号(Destination Port):指示数据包应该发送到哪个设备的端口号。 - 长度(Length):指示整个UDP数据包的长度。 - 校验和(Checksum):用于校验UDP数据包的完整性。 4. CIP数据部分(CIP Data): - CIP头部(CIP Header):包含了CIP协议相关的信息,如消息类型、路径、服务代码等。 - CIP数据(CIP Data):根据具体的应用需求,可以是读取或写入的数据。 以上就是Ethernet/IP通讯协议报文的基本格式

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值