Chinaunix首页 | 论坛 | 博客
  • 博客访问: 735331
  • 博文数量: 769
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 4985
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 16:37
文章分类

全部博文(769)

文章存档

2011年(1)

2008年(768)

我的朋友

分类:

2008-10-15 16:40:34

      #include
    #include
    #include
    #include
    #include

    #define STATUS_FAILED 0xFFFF //定义异常出错代码
    #define MAX_PACK_LEN 65535 //接收的最大IP报文
    #define MAX_ADDR_LEN 16 //点分十进制地址的最大长度
    #define MAX_PROTO_TEXT_LEN 16 //子名称(如"TCP")最大长度
    #define MAX_PROTO_NUM 12 //子数量
    #define MAX_HOSTNAME_LAN 255 //最大主机名长度
    #define CMD_PARAM_HELP true

    typedef strUCt _iphdr
    {
    unsigned char h_lenver; //4位首部长度+4位IP版本号
    unsigned char tos; //8位服务类型TOS
    unsigned short total_len; //16位总长度(字节)
    unsigned short ident; //16位标识
    unsigned short frag_and_flags; //3位标志位
    unsigned char ttl; //8位生存时间 TTL
    unsigned char proto; //8位 (TCP, UDP 或其他)
    unsigned short checksum; //16位IP首部校验和
    unsigned int sourceIP; //32位源IP地址
    unsigned int destIP; //32位目的IP地址
    }IP_HEADER;

    typedef struct _tcphdr //定义TCP首部
    {
    USHORT th_sport; //16位源端口
    USHORT th_dport; //16位目的端口
    unsigned int th_seq; //32位序列号
    unsigned int th_ack; //32位确认号
    unsigned char th_lenres; //4位首部长度/6位保留字
    unsigned char th_flag; //6位标志位
    USHORT th_win; //16位窗口大小
    USHORT th_sum; //16位校验和
    USHORT th_urp; //16位紧急数据偏移量
    }TCP_HEADER;

    typedef struct _udphdr //定义UDP首部
    {
    unsigned short uh_sport; //16位源端口
    unsigned short uh_dport; //16位目的端口
    unsigned short uh_len; //16位长度
    unsigned short uh_sum; //16位校验和
    } UDP_HEADER;

    typedef struct _icmphdr //定义ICMP首部
    {
    BYTE i_type; //8位类型
    BYTE i_code; //8位代码
    USHORT i_cksum; //16位校验和
    USHORT i_id; //识别号(一般用进程号作为识别号)

[1]    

【责编:landy】

--------------------next---------------------

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