linux ip 包头 代码修改,linux 编程ip包头结构大全

struct ether_header

{

u_int8_t  ether_dhost[ETH_ALEN];      /* destination eth addr */

u_int8_t  ether_shost[ETH_ALEN];      /* source ether addr    */

u_int16_t ether_type;                 /* packet type ID field */

} __attribute__ ((__packed__));

------------------------------------------------------------------------------------

struct udphdr {

__u16   source;

__u16   dest;

__u16   len;

__u16   check;

};

**********************************

#ifdef __FAVOR_BSD

struct udphdr {

u_int16_t uh_sport;           /* source port */

u_int16_t uh_dport;           /* destination port */

u_int16_t uh_ulen;            /* udp length */

u_int16_t uh_sum;             /* udp checksum */

};

#else

struct udphdr {

u_int16_t     source;

u_int16_t     dest;

u_int16_t     len;

u_int16_t     check;

};

#endif

--------------------------------------------------------------------------------------------------------

# ifdef __FAVOR_BSD

typedef u_int32_t tcp_seq;

/*

* TCP header.

* Per RFC 793, September, 1981.

*/

struct tcphdr

{

u_int16_t th_sport;         /* source port */

u_int16_t th_dport;         /* destination port */

tcp_seq th_seq;             /* sequence number */

tcp_seq th_ack;             /* acknowledgement number */

#  if __BYTE_ORDER == __LITTLE_ENDIAN

u_int8_t th_x2:4;           /* (unused) */

u_int8_t th_off:4;          /* data offset */

#  endif

#  if __BYTE_ORDER == __BIG_ENDIAN

u_int8_t th_off:4;          /* data offset */

u_int8_t th_x2:4;           /* (unused) */

#  endif

u_int8_t th_flags;

#  define TH_FIN        0x01

#  define TH_SYN        0x02

#  define TH_RST        0x04

#  define TH_PUSH       0x08

#  define TH_ACK        0x10

#  define TH_URG        0x20

u_int16_t th_win;           /* window */

u_int16_t th_sum;           /* checksum */

u_int16_t th_urp;           /* urgent pointer */

};

# else /* !__FAVOR_BSD */

struct tcphdr

{

u_int16_t source;

u_int16_t dest;

u_int32_t seq;

u_int32_t ack_seq;

#  if __BYTE_ORDER == __LITTLE_ENDIAN

u_int16_t res1:4;

u_int16_t doff:4;

u_int16_t fin:1;

u_int16_t syn:1;

u_int16_t rst:1;

u_int16_t psh:1;

u_int16_t ack:1;

u_int16_t urg:1;

u_int16_t res2:2;

#  elif __BYTE_ORDER == __BIG_ENDIAN

u_int16_t doff:4;

u_int16_t res1:4;

u_int16_t res2:2;

u_int16_t urg:1;

u_int16_t ack:1;

u_int16_t psh:1;

u_int16_t rst:1;

u_int16_t syn:1;

u_int16_t fin:1;

#  else

#   error "Adjust your defines"

#  endif

u_int16_t window;

u_int16_t check;

u_int16_t urg_ptr;

};

# endif /* __FAVOR_BSD */

*****************************************************

struct tcphdr {

__u16   source;

__u16   dest;

__u32   seq;

__u32   ack_seq;

#if defined(__LITTLE_ENDIAN_BITFIELD)

__u16   res1:4,

doff:4,

fin:1,

syn:1,

rst:1,

psh:1,

ack:1,

urg:1,

ece:1,

cwr:1;

#elif defined(__BIG_ENDIAN_BITFIELD)

__u16   doff:4,

res1:4,

cwr:1,

ece:1,

urg:1,

ack:1,

psh:1,

rst:1,

syn:1,

fin:1;

#else

#error  "Adjust your defines"

#endif

__u16   window;

__u16   check;

__u16   urg_ptr;

};

---------------------------------------------------------------------------------------------

struct iphdr {

#if defined(__LITTLE_ENDIAN)

__u8    ihl:4,

version:4;

#elif defined (__BIG_ENDIAN)

__u8    version:4,

ihl:4;

#endif

__u8    tos;

__u16   tot_len;

__u16   id;

__u16   frag_off;

__u8    ttl;

__u8    protocol;

__u16   check;

__u32   saddr;

__u32   daddr;

/*The options start here. */

};

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值