Chinaunix首页 | 论坛 | 博客
  • 博客访问: 21299
  • 博文数量: 7
  • 博客积分: 154
  • 博客等级: 入伍新兵
  • 技术积分: 71
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-14 21:23
文章分类

全部博文(7)

文章存档

2012年(7)

我的朋友

分类: LINUX

2012-06-17 23:50:17

嘿嘿,原帖在这里 http://www.cnblogs.com/dubingsky/archive/2010/01/21/1653650.html
我这里自己参考修改了下↖(^ω^)↗

点击(此处)折叠或打开

  1. //Mac头部,总长度14字节
  2. typedef struct eth_hdr
  3. {
  4.     unsigned char dstmac[6]; //目标mac地址
  5.     unsigned char srcmac[6]; //源mac地址
  6.     unsigned short eth_type; //以太网类型
  7. }eth_hdr;


点击(此处)折叠或打开

  1. //IP头部,总长度20字节
  2. struct ip_hdr{
  3. #if BYTE_ORDER == LITTLE_ENDIAN
  4.     unsigned char    ip_hl:4,    /*header length*/
  5.                     ip_v:4;        /*version */
  6. #endif
  7. #if BYTE_ORDER == BIG_ENDIAN
  8.     unsigned char    ip_v:4,        /*version */
  9.                     ip_hl:4;    /*header length*/
  10. #endif
  11.     unsigned char    ip_tos;        /*type of service */
  12.     short    ip_len;        /*total length */
  13.     unsigned short    ip_id;        /*identification */
  14.     short    ip_off;        /*fragment offset field */
  15. #define    IP_DF    0x4000    /*dont fragment flag */
  16. #define    IP_MF    0x2000    /*more fragments flag*/
  17. #define IP_OFFMASK 0x1fff    /*mask for fragment bits*/
  18.     unsigned char    ip_ttl;        /*time to live*/
  19.     unsigned char    ip_p;        /*protocol */
  20.     unsigned short    ip_sum;        /*checksum*/
  21.     struct in_addr ip_src,ip_dst;    /*source and dest address */
  22. };


点击(此处)折叠或打开

  1. //TCP头部,总长度20字节
  2. struct tcp_hdr{
  3.     unsigned short th_sport;    /*source port*/
  4.     unsigned short th_dport;    /*destination port*/
  5.     unsigned int th_seq;        /*sequence number*/
  6.     unsigned int th_ack;        /*acknowledgement number*/
  7. #if BYTE_ORDER == LITTLE_ENDIAN
  8.     unsigned char     th_x2:4,    /*(unused)*/
  9.                     th_off:4;    /*data offset*/
  10. #endif
  11. #if BYTE_ORDER == BIG_ENDIAN
  12.     unsigned char     th_off:4,    /*data offset */
  13.                     th_x2:4;    /*(unused)*/
  14. #endif
  15.     unsigned char    th_flags;    /*ACK,FIN,PUSH,RST,SYN,URG*/
  16.     unsigned short    th_win;        /*advertised window */
  17.     unsigned short     th_sum;        /*checksum*/
  18.     unsigned short     th_urp;        /*urgent offset*/
  19. };


点击(此处)折叠或打开

  1. //UDP头部,总长度8字节
  2. typedef struct udp_hdr
  3. {
  4. unsigned short src_port; //远端口号
  5. unsigned short dst_port; //目的端口号
  6. unsigned short uhl; //udp头部长度
  7. unsigned short chk_sum; //16位udp检验和
  8. }udp_hdr;

点击(此处)折叠或打开

  1. //ICMP头部,总长度4字节
  2. typedef struct icmp_hdr
  3. {
  4.     unsigned char icmp_type; //类型
  5.     unsigned char code; //代码
  6.     unsigned short chk_sum; //16位检验和
  7. }icmp_hdr;

阅读(536) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~