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/
Ethernet IP TCP UDP 协议头部格式的更多相关文章
- java 通过TCP\UDP 协议实现多人聊天,点对点,文件传送-----分服务器端和客户端
java 通过TCP\UDP 协议实现多人聊天,点对点,文件传送-----分服务器端和客户端 启动界面如下图: 首先启动服务器: 客户端登陆,登陆成功后为: 默认发送是全部用户,是多人发送. 当在边列 ...
- 网络编程—网络基础概览、socket,TCP/UDP协议
网络基础概览 socket概览 socket模块—TCP/UDP的实现 TCP/UDP总结 网络基础概览 osi七层协议各层主要的协议 # 物理层传输电信号1010101010 # 数据链路层,以太网 ...
- QQ--基于TCP/UDP协议的通讯原理
QQ是一个基于TCP/UDP协议的通讯软件 发送消息的时候是UDP打洞,登陆的时候使用HTTP~因为登陆服务器其实就是一个HTTP服 务器,只不过不是常用的那些,那个服务器是腾讯自行开发的! 一 ...
- TCP/UDP协议简要梳理
TCP/UDP协议简要梳理 TCP TCP,Transmission Control Protocol,传输控制协议是一种面向连接的.可靠的.基于字节流的传输层通信协议.在因特网协议族中,TCP所在的 ...
- Socket(套接字) IP TCP UDP HTTP
Socket(套接字) 阮老师的微博 (转)什么是套接字(Socket)? 应用层通过传输层进行数据通信时,TCP和UDP会遇到同时为多个应用程序进程提供并发服务的问题.多个TCP连接或多个应用程序进 ...
- TCP/UDP协议(二)
面试问题:Tcp/Udp协议是什么,各有什么异同点,各自的使用场景? Tcp协议(传输控制协议) tcp是面向连接的协议,在收发数据之前,必须与对方建立可靠的连接: 三次握手:简单形象通俗描述: 主机 ...
- 以太 ip tcp udp 三次握手的理解
以太帧: 1.前导码(7字节):使接收器建立比特同步. 2.起始定界符SFD(1字节):指示一帧的开始. 3.目的地址DA(6字节):指出要接收该帧的工作站. 4.源地址SA(6字节):指示发送该帧的 ...
- TODO:Golang语言TCP/UDP协议重用地址端口
TODO:Golang语言TCP/UDP协议重用地址端口 这是一个简单的包来解决重用地址的问题. go net包(据我所知)不允许设置套接字选项. 这在尝试进行TCP NAT时尤其成问题,其需要在同一 ...
- Shell 脚本实现TCP/UDP协议通讯
Shell 脚本实现TCP/UDP协议通讯 http://www.cnblogs.com/occult/archive/2012/12/25/2832183.html
随机推荐
- 国外最受欢迎的15个BT下载网站
1.EYH.BIZ 海盗湾(The Pirate Bay)现在在中国成立的一个分部 www.eyh.biz 一个提供BT种子文件和链接,以方便使用BT协议的对等文件共享网站.该网站于2003年在瑞典创 ...
- linux环境安装包方式
概述 安装有很多种,有时我们会混淆视听不知在什么场景或什么情况下用什么命令,下面讲解下几种安装命令的使用.希望对大家有帮助~ 详解 pip install kuming或 python -m pip ...
- php 基础 PHP保留两位小数的几种方法
$num = 10.4567; //第一种:利用round()对浮点数进行四舍五入 echo round($num,2); //10.46 //第二种:利用sprintf格式化字符串 $format_ ...
- ipmitool命令
1.remote access control powerIpmitool -I lanplus -H 192.168.0.10 -U username -P Password chassis pow ...
- linux下后台执行shell脚本nohup
(一)使用nohup后台执行脚本 脚本执行结果记录到nohup.out文件中 (二)使用&后台执行脚本 使用&符号在后台执行命令或脚本后,如果你退出登录,这个命令就会被自动终止掉
- 使用pandas读取excel
使用pandas读取excel Excel是微软的经典之作,在这里我们介绍使用Python的pandas数据分析包来解决此问题. pd.read_excel(io, sheet_name = 0, h ...
- ubuntu16.04下安装docker和docker-compose
开始安装 由于apt官方库里的docker版本可能比较旧,所以先卸载可能存在的旧版本:$ sudo apt-get remove docker docker-engine docker-ce dock ...
- Week of Code:GG
题意是给出一个数n,一个长度为n-1的字符串.求的是1到n符合要求的序列的数量,该序列需要满足当该位置为G时,这个位置的数大于后面位置的数.当该位置为L时,这个位置的数要小于后面位置的数.最后数量模m ...
- 「SP10628 COT - Count on a tree」
主席树的综合运用题. 前置芝士 可持久化线段树:其实就是主席树了. LCA:最近公共祖先,本题需要在\(\log_2N\)及以内的时间复杂度内解决这个问题. 具体做法 主席树维护每个点到根节点这一条链 ...
- SWD学习笔记
SWD其实和JTAG类似,是一种调试串口. JTAG大致了解了一下.JTAG(Joint Test Action Group)主要4 lines:TMS(模式选择),TCK(时钟),TDI(数据输入) ...