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_ENDIANu_char    ip_hl:4,        /* header length */ip_v:4;            /* version */
#endif
#if BYTE_ORDER == BIG_ENDIANu_char    ip_v:4,            /* version */ip_hl:4;        /* header length */
#endifu_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_ENDIANu_char    th_x2:4,        /* (unused) */th_off:4;        /* data offset */
#endif
#if BYTE_ORDER == BIG_ENDIANu_char    th_off:4,        /* data offset */th_x2:4;        /* (unused) */
#endifu_char    th_flags;u_short    th_win;            /* window */u_short    th_sum;            /* checksum */u_short    th_urp;            /* urgent pointer */
};

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

转载于:https://www.cnblogs.com/qq76211822/p/5137043.html

Ethernet IP TCP UDP 协议头部格式相关推荐

  1. TCP/UDP协议首部格式

    1. UDP协议首部格式 UDP首部有8个字节,由4个字段构成,每个字段都是两个字节, 1.源端口号: 可有可无,需要对方回信时选用,不需要时全部置0. 2.目的端口号:必须有,在终点交付报文的时候需 ...

  2. 《深入浅出DPDK》读书笔记(十):硬件加速与功能卸载(VLAN、IEEE1588、IP TCP/UDP/SCTP checksum、Tunnel)

    Table of Contents 109.硬件卸载简介 110.网卡硬件卸载功能 111.DPDK软件接口 接收侧: 发送侧: 112.硬件与软件功能实现 113.VLAN硬件卸载 1. 收包时VL ...

  3. RAW 原始套接字 TCP UDP协议解析

    前言 公司的项目终于告一段落了,终于有时间了 - - leetcode 终于又可以 提上日程了 rust 驱动开发,也可以继续做了 kernel的驱动开发,也得继续进行了 驱动框架我又回来了 RFC ...

  4. 网络原理之TCP/UDP协议

    UDP协议 UDP协议端格式 16位UDP长度, 表示整个数据报(UDP首部+UDP数据)的最大长度; 如果校验和出错, 就会直接丢弃 UDP的特点 UDP传输的过程类似于寄信. 无连接: 知道对端的 ...

  5. 网络编程培训之一 编程实现IP/TCP/UDP报文

    系列博客参考:http://blog.csdn.net/zy416548283/article/category/1108400 代码以编号对应放在Github上:https://github.com ...

  6. 最全的TCP/UDP 协议知识点整理

    关于计算机网络的基础知识,我前面写的两篇文章是入门文章,可以帮你构建一个计算机网络的基础架构,有了这个基础架构,后面的学习会很简单.下面是两篇文章的连接~~ 计算机网络体系结构与参考模型(1) 计算机 ...

  7. Ethernet/IP和cip协议的介绍与分析

    一. CIP协议簇介绍 CIP 协议族是由 ODVA .CI 等机构联合推出的应用层协议标准, 又称为控制与信息协议, 它为采用不同物理层和数据链路层的各层网络提供了统一的应用层协议标准, 使得各层网 ...

  8. 网络层协议与应用及传输层TCP/UDP协议

    网络层协议与应用及传输层TCP/UDP协议 目录 一.IP数据包格式 二.ICMP协议 三.ARP协议及ARP工作原理 四.TCP协议及常用端口号 五.UDP协议及常用端口号 一.IP数据包格式 网络 ...

  9. TCP/UDP协议总结与应用层常见协议及端口

    TCP/UDP协议总结与应用层常见协议及端口 1.TCP协议 TCP协议概述 TCP的应用场景 TCP的特点 TCP的报文格式 TCP三次握手 TCP四次挥手 2.UDP协议 UDP概述 UDP的应用 ...

最新文章

  1. Python 是否是下一个 PHP?为什么?
  2. windows定时关机
  3. BERT 预训练模型及文本分类(情感分类)
  4. oracle何时使用to_date函数
  5. jQuery实例——展示表格点击变色、全选、删除
  6. axure9 邮件点击效果_EDM邮件营销,你不得不知道的8个指标?
  7. IPSEC ***两个阶段的协商过程
  8. 对PostgreSQL cmin和cmax的理解
  9. psql物化视图自动更新
  10. 深度学习TensorFlow生产环境部署(环境准备篇)
  11. AlexNet模型解读
  12. SQLyog 安装和配置教程
  13. 卡内基梅隆大学计算机科学博士,卡内基梅隆大学有哪些专业处于世界顶尖水平?...
  14. 数字IC设计学习笔记_8位7段数码管1
  15. vmware克隆centos修改mac地址
  16. linux卷空间不足问题 gparted工具重新分配根分区空间
  17. dfs、bfs的终于弄明白了
  18. 利用SMTP协议实现邮件的发送(以163和qq邮箱为例)
  19. 原生js中attributes属性
  20. 美术绘画之场景基础-张聪-专题视频课程

热门文章

  1. XMind2020的一些使用小技巧
  2. mysql -ss -e_课内资源 - 基于ssm框架和mysql的网上选课系统
  3. 数据库系统概论:第六章 关系数据库理论
  4. [OSDI 16] Wukong : 基于RDMA的高并发、快速的分布式RDF Graph Query系统
  5. Unity导出APk出错解决方法二
  6. ActiveMQ的使用
  7. Python初始环境搭建和Pycharm的安装
  8. jQuery滚动指定位置
  9. Flume概述和简单实例
  10. ubuntu安装vsftpd