您的位置:首页 > 理论基础 > 计算机网络

TCP UDP IP报文头结构

2012-07-24 11:43 423 查看
在/usr/src/linux-headers-3.2.0-23/include/linux目录下tcp.h udp.h ip.h中定义如下结构

struct tcphdr {

        __be16  source;

        __be16  dest;

        __be32  seq;

        __be32  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 <asm/byteorder.h> defines"

#endif

        __be16  window;

        __sum16 check;

        __be16  urg_ptr;

};







#include <linux/types.h>

struct udphdr {

        __be16  source;

        __be16  dest;

        __be16  len;

        __sum16 check;

};




struct iphdr {

#if defined(__LITTLE_ENDIAN_BITFIELD)

        __u8    ihl:4,

                version:4;

#elif defined (__BIG_ENDIAN_BITFIELD)

        __u8    version:4,

                ihl:4;

#else

#error  "Please fix <asm/byteorder.h>"

#endif

        __u8    tos;

        __be16  tot_len;

        __be16  id;

        __be16  frag_off;

        __u8    ttl;

        __u8    protocol;

        __sum16 check;

        __be32  saddr;

        __be32  daddr;

        /*The options start here. */

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tcp struct