UDP 协议的实现


#pragma pack(1)

#define ETH_ALEN	6


struct ethhdr_t {
	unsigned char	h_dest[ETH_ALEN];	/* destination eth addr	*/
	unsigned char	h_source[ETH_ALEN];	/* source ether addr	*/
	unsigned short	h_proto;            /* packet type ID field	*/
} __attribute__((packed));


struct iphdr_t {
	unsigned char	version:4,          /* Version (4 digits) */
  		            ihl:4;              /* The head length (4 digits) */
	unsigned char	tos;                /* Service Type Field (8-bit) */
	unsigned short	tot_len;            /* The total length field (16) */
	unsigned short	id;                 /* Identification field (16bit) */
	unsigned short	frag_off;           /* The Fragment Offset domain indicates what location in the current datagram */
	unsigned char	ttl;                /* TTL (TIME TO LIVE) 8-bit */
	unsigned char	protocol;           /* Protocol field (8 digits) */
	unsigned short	check;              /* The header checksum field (16) */
	unsigned int	saddr;              /* 32 source IP address */
	unsigned int	daddr;              /* 32-bit IP address */
};


struct udphdr_t {
	unsigned short	source;             /* 16-bit source port */
	unsigned short	dest;               /* 16-bit destination port */
	unsigned short	len;                /* Represents the length, 16 bits of the data reported */
	unsigned short	check;              /* Check and verify */
};


struct udppkt_t {
	struct ethhdr_t ethhdr;
	struct iphdr_t  iphdr;
	struct udphdr_t udphdr;
	unsigned char   userdata[0];
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值