织梦CMS - 轻松建站从此开始!

罗索

TCP/IP协议相关协议头

jackyhwei 发布于 2010-12-08 16:18 点击:次 
TCP/IP协议的协议头在linux下的/usr/include/netinet,/usr/include/net文件夹下是存在的。那么我们离开了Linux操作系统,而在win32下系统是没有提供这些头的。那么我们就需要根据协议定义一下了
TAG:

TCP/IP协议的协议头在linux下的/usr/include/netinet,/usr/include/net文件夹下是存在的。

那么我们离开了Linux操作系统,而在win32下系统是没有提供这些头的。那么我们就需要根据协议定义一下了:

可能你会选择COPY一下LINUX下的定义。当然这也可能一种选择,但是我遇到的情况是,单纯的copy是不行的。

那么我们就只有自己写了:

ethernet(以太网)头:

  1. #define ETH_ALEN   6    /* Octets in one ethernet addr   */ 
  2. struct ether_header 
  3. u_char  ether_dhost[ETH_ALEN];    /* destination eth addr */ 
  4. u_char  ether_shost[ETH_ALEN];    /* source ether addr    */ 
  5. u_short ether_type;               /* packet type ID field */ 
  6. }; 

IP头:

  1. struct iphdr 
  2.     u_char     h_lenver; 
  3.     u_char     tos; 
  4.     u_short    total_len; 
  5.     u_short    ident; 
  6.     u_short    frag_and_flags; 
  7.     u_char     ttl; 
  8.     u_char     proto; 
  9.     u_short    checksum; 
  10.     u_int      sourceIP; 
  11.     u_int      destIP; 
  12.     /* Put options here. */ 
  13. }; 

TCP头:

  1. struct tcphdr 
  2.     u_short     th_sport; 
  3.     u_short     th_dport; 
  4.     u_int       th_seq; 
  5.     u_int       th_ack; 
  6.     u_char      th_lenres; 
  7.     u_char      th_flag; 
  8.     u_short     th_win; 
  9.     u_short     th_sum; 
  10.     u_short     th_urp; 
  11. }; 

UDP头:

  1. struct udphdr 
  2. u_short source; /* source port */ 
  3. u_short dest;   /* destination port */ 
  4. u_short len;    /* udp length */ 
  5. u_short check;  /* udp checksum */ 
  6. }; 

 

(wfqxx)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201012/10579.html]
本文出处:CSDN博客 作者:wfqxx
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容