"Fossies" - the Fresh Open Source Software Archive

Member "ngrep-1_47/win32/support/types.h" (7 Sep 2017, 6226 Bytes) of package /linux/misc/ngrep-1_47.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "types.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1_45_vs_1_47.

    1 /*
    2  * Because Windows standard headers are woefully inadequate for (real)
    3  * network application development, and because I'm basically lazy, I
    4  * created this header as a container for the types ngrep needs.
    5  *
    6  * These include standard types like u*int*_t's, as well as network
    7  * protocol-specific structures and types.
    8  */
    9 
   10 typedef unsigned char      u_int8_t;
   11 typedef unsigned short int u_int16_t;
   12 typedef unsigned int       u_int32_t;
   13 
   14 typedef unsigned char      uint8_t;
   15 typedef unsigned short int uint16_t;
   16 typedef unsigned int       uint32_t;
   17 
   18 typedef signed char        int8_t;
   19 typedef signed short int   int16_t;
   20 typedef signed int         int32_t;
   21 
   22 
   23 
   24 #define IP_RF 0x8000                            /* reserved fragment flag */
   25 #define IP_DF 0x4000                            /* dont fragment flag */
   26 #define IP_MF 0x2000                            /* more fragments flag */
   27 #define IP_OFFMASK 0x1fff                       /* mask for fragmenting bits */
   28 
   29 struct ip {
   30     u_int8_t ip_hl:4;                   /* header length */
   31     u_int8_t ip_v:4;                    /* version */
   32     u_int8_t ip_tos;                            /* type of service */
   33     u_int16_t ip_len;                                   /* total length */
   34     u_int16_t ip_id;                                    /* identification */
   35     u_int16_t ip_off;                                   /* fragment offset field */
   36     u_int8_t ip_ttl;                            /* time to live */
   37     u_int8_t ip_p;                                      /* protocol */
   38     u_int16_t ip_sum;                                   /* checksum */
   39     struct in_addr ip_src, ip_dst;      /* source and dest address */
   40 };
   41 
   42 #define TH_FIN  0x01
   43 #define TH_SYN  0x02
   44 #define TH_RST  0x04
   45 #define TH_PUSH 0x08
   46 #define TH_ACK  0x10
   47 #define TH_URG  0x20
   48 
   49 typedef u_int32_t tcp_seq;
   50 
   51 struct tcphdr {
   52     u_int16_t th_sport;                         /* source port */
   53     u_int16_t th_dport;                         /* destination port */
   54     tcp_seq th_seq;                                     /* sequence number */
   55     tcp_seq th_ack;                                     /* acknowledgement number */
   56     u_int8_t th_x2:4;                           /* (unused) */
   57     u_int8_t th_off:4;                          /* data offset */
   58     u_int8_t th_flags;
   59     u_int16_t th_win;                           /* window */
   60     u_int16_t th_sum;                           /* checksum */
   61     u_int16_t th_urp;                           /* urgent pointer */
   62 };
   63 
   64 struct udphdr {
   65         u_int16_t uh_sport;                             /* source port */
   66     u_int16_t uh_dport;             /* destination port */
   67     u_int16_t uh_ulen;              /* udp length */
   68     u_int16_t uh_sum;               /* udp checksum */
   69 };
   70 
   71 
   72 struct icmp {
   73         u_int8_t  icmp_type;
   74         u_int8_t  icmp_code;
   75         u_int16_t icmp_cksum;
   76 
   77         union {
   78                 u_int8_t ih_pptr;
   79                 struct in_addr ih_gwaddr;
   80                 struct ih_idseq {
   81                         u_int16_t icd_id;
   82                         u_int16_t icd_seq;
   83                 } ih_idseq;
   84                 u_int32_t ih_void;
   85 
   86                 struct ih_pmtu {
   87                         u_int16_t ipm_void;
   88                         u_int16_t ipm_nextmtu;
   89                 } ih_pmtu;
   90 
   91                 struct ih_rtradv {
   92                         u_int8_t irt_num_addrs;
   93                         u_int8_t irt_wpa;
   94                         u_int16_t irt_lifetime;
   95                 } ih_rtradv;
   96         } icmp_hun;
   97 };
   98 
   99 struct igmp {
  100   u_int8_t igmp_type;             /* IGMP type */
  101   u_int8_t igmp_code;             /* routing code */
  102   u_int16_t igmp_cksum;           /* checksum */
  103   struct in_addr igmp_group;      /* group address */
  104 };
  105 
  106 /*
  107  * Taken from arpa/namser.h, used by inet_?to?() (Win32 support).
  108  */
  109 
  110 #define NS_INADDRSZ      4
  111 #define NS_IN6ADDRSZ     16      /* IPv6 T_AAAA */
  112 #define NS_INT16SZ       2       /* #/bytes of data in a u_int16_t */
  113 
  114 /*
  115  * IPv6 and ICMPv6 declarations.
  116  */
  117 
  118 /* IPv6 address */
  119 struct UNIX_in6_addr {
  120     union {
  121         uint8_t u6_addr8[16];
  122         uint16_t u6_addr16[8];
  123         uint32_t u6_addr32[4];
  124     } in6_u;
  125 };
  126 
  127 struct ip6_hdr {
  128     union {
  129         struct ip6_hdrctl {
  130             uint32_t ip6_un1_flow;   /* 4 bits version, 8 bits TC,
  131                                         20 bits flow-ID */
  132             uint16_t ip6_un1_plen;   /* payload length */
  133             uint8_t  ip6_un1_nxt;    /* next header */
  134             uint8_t  ip6_un1_hlim;   /* hop limit */
  135           } ip6_un1;
  136 
  137         uint8_t ip6_un2_vfc;       /* 4 bits version, top 4 bits tclass */
  138 
  139         } ip6_ctlun;
  140 
  141     struct UNIX_in6_addr ip6_src;      /* source address */
  142     struct UNIX_in6_addr ip6_dst;      /* destination address */
  143 };
  144 
  145 #define ip6_vfc   ip6_ctlun.ip6_un2_vfc
  146 #define ip6_flow  ip6_ctlun.ip6_un1.ip6_un1_flow
  147 #define ip6_plen  ip6_ctlun.ip6_un1.ip6_un1_plen
  148 #define ip6_nxt   ip6_ctlun.ip6_un1.ip6_un1_nxt
  149 #define ip6_hlim  ip6_ctlun.ip6_un1.ip6_un1_hlim
  150 #define ip6_hops  ip6_ctlun.ip6_un1.ip6_un1_hlim
  151 
  152 /* Fragment header */
  153 struct ip6_frag {
  154     uint8_t   ip6f_nxt;         /* next header */
  155     uint8_t   ip6f_reserved;    /* reserved field */
  156     uint16_t  ip6f_offlg;       /* offset, reserved, and flag */
  157     uint32_t  ip6f_ident;       /* identification */
  158 };
  159 
  160 #if     BYTE_ORDER == BIG_ENDIAN
  161 #define IP6F_OFF_MASK       0xfff8  /* mask out offset from _offlg */
  162 #define IP6F_RESERVED_MASK  0x0006  /* reserved bits in ip6f_offlg */
  163 #define IP6F_MORE_FRAG      0x0001  /* more-fragments flag */
  164 #else   /* BYTE_ORDER == LITTLE_ENDIAN */
  165 #define IP6F_OFF_MASK       0xf8ff  /* mask out offset from _offlg */
  166 #define IP6F_RESERVED_MASK  0x0600  /* reserved bits in ip6f_offlg */
  167 #define IP6F_MORE_FRAG      0x0100  /* more-fragments flag */
  168 #endif
  169 
  170 struct icmp6_hdr {
  171     uint8_t     icmp6_type;   /* type field */
  172     uint8_t     icmp6_code;   /* code field */
  173     uint16_t    icmp6_cksum;  /* checksum field */
  174     union {
  175                 uint32_t  icmp6_un_data32[1]; /* type-specific field */
  176                 uint16_t  icmp6_un_data16[2]; /* type-specific field */
  177                 uint8_t   icmp6_un_data8[4];  /* type-specific field */
  178         } icmp6_dataun;
  179 };