Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

libnet-headers.h

Go to the documentation of this file.
00001 /*
00002  *  $Id$
00003  *
00004  *  libnet-headers.h - Network routine library headers header file
00005  *
00006  *  Copyright (c) 1998, 1999, 2000 Mike D. Schiffman <mike@infonexus.com>
00007  *  All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the distribution.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00022  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00024  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00025  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00026  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00027  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  */
00031 
00032 #ifndef __LIBNET_HEADERS_H
00033 #define __LIBNET_HEADERS_H
00034 
00035 /* 
00036  *  Standard (IPv4) header sizes in bytes.
00037  */
00038 
00039 #define LIBNET_ARP_H           0x1c    /* ARP header:          28 bytes */
00040 #define LIBNET_DNS_H           0xc     /* DNS header base:     12 bytes */
00041 #define LIBNET_ETH_H           0xe     /* Etherner header:     14 bytes */
00042 #define LIBNET_ICMP_H          0x4     /* ICMP header base:     4 bytes */
00043 #define LIBNET_ICMP_ECHO_H     0x8     /* ICMP_ECHO header:     8 bytes */
00044 #define LIBNET_ICMP_MASK_H     0xc     /* ICMP_MASK header:    12 bytes */
00045 #define LIBNET_ICMP_UNREACH_H  0x8     /* ICMP_UNREACH header:  8 bytes */
00046 #define LIBNET_ICMP_TIMXCEED_H 0x8     /* ICMP_TIMXCEED header: 8 bytes */
00047 #define LIBNET_ICMP_REDIRECT_H 0x8     /* ICMP_REDIRECT header: 8 bytes */
00048 #define LIBNET_ICMP_TS_H       0x14    /* ICMP_TIMESTAMP headr:20 bytes */
00049 #define LIBNET_IGMP_H          0x8     /* IGMP header:          8 bytes */
00050 #define LIBNET_IP_H            0x14    /* IP header:           20 bytes */
00051 /* See libnet-ospf.h for OSPF related header sizes */
00052 #define LIBNET_RIP_H           0x18    /* RIP header base:     24 bytes */
00053 #define LIBNET_TCP_H           0x14    /* TCP header:          20 bytes */
00054 #define LIBNET_UDP_H           0x8     /* UDP header:           8 bytes */
00055 
00056 /*
00057  *  Concession to legacy naming scheme.
00058  */
00059 #define ARP_H           LIBNET_ARP_H
00060 #define DNS_H           LIBNET_DNS_H
00061 #define ETH_H           LIBNET_ETH_H
00062 #define ICMP_H          LIBNET_ICMP_H
00063 #define ICMP_ECHO_H     LIBNET_ICMP_ECHO_H
00064 #define ICMP_MASK_H     LIBNET_ICMP_MASK_H
00065 #define ICMP_UNREACH_H  LIBNET_ICMP_UNREACH_H
00066 #define ICMP_TIMXCEED_H LIBNET_ICMP_TIMXCEED_H
00067 #define ICMP_REDIRECT_H LIBNET_ICMP_REDIRECT_H
00068 #define ICMP_TS_H       LIBNET_ICMP_TS_H
00069 #define IGMP_H          LIBNET_IGMP_H
00070 #define IP_H            LIBNET_IP_H
00071 #define RIP_H           LIBNET_RIP_H
00072 #define TCP_H           LIBNET_TCP_H
00073 #define UDP_H           LIBNET_UDP_H
00074 
00075 /*
00076  *  IP packet header prototype.
00077  */
00078 struct libnet_ip_hdr
00079 {
00080 #if (LIBNET_LIL_ENDIAN)
00081     u_char ip_hl:4,         /* header length */
00082             ip_v:4;         /* version */
00083 #endif
00084 #if (LIBNET_BIG_ENDIAN)
00085     u_char ip_v:4,          /* version */
00086             ip_hl:4;        /* header length */
00087 #endif
00088     u_char ip_tos;          /* type of service */
00089     u_short ip_len;         /* total length */
00090     u_short ip_id;          /* identification */
00091     u_short ip_off;
00092 #ifndef IP_RF
00093 #define IP_RF 0x8000        /* reserved fragment flag */
00094 #endif
00095 #ifndef IP_DF
00096 #define IP_DF 0x4000        /* dont fragment flag */
00097 #endif
00098 #ifndef IP_MF
00099 #define IP_MF 0x2000        /* more fragments flag */
00100 #endif 
00101 #ifndef IP_OFFMASK
00102 #define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
00103 #endif
00104     u_char ip_ttl;          /* time to live */
00105     u_char ip_p;            /* protocol */
00106     u_short ip_sum;         /* checksum */
00107     struct in_addr ip_src, ip_dst; /* source and dest address */
00108 };
00109 
00110 #ifndef IP_MAXPACKET
00111 #define IP_MAXPACKET 65535
00112 #endif
00113 
00114 /*
00115  *  TCP packet header prototype.
00116  */
00117 struct libnet_tcp_hdr
00118 {
00119     u_short th_sport;       /* source port */
00120     u_short th_dport;       /* destination port */
00121     u_long th_seq;          /* sequence number */
00122     u_long th_ack;          /* acknowledgement number */
00123 #if (LIBNET_LIL_ENDIAN)
00124     u_char th_x2:4,         /* (unused) */
00125            th_off:4;        /* data offset */
00126 #endif
00127 #if (LIBNET_BIG_ENDIAN)
00128     u_char th_off:4,        /* data offset */
00129            th_x2:4;         /* (unused) */
00130 #endif
00131     u_char  th_flags;       /* control flags */
00132 #ifndef TH_FIN
00133 #define TH_FIN    0x01
00134 #endif
00135 #ifndef TH_SYN
00136 #define TH_SYN    0x02
00137 #endif
00138 #ifndef TH_RST
00139 #define TH_RST    0x04
00140 #endif
00141 #ifndef TH_PUSH
00142 #define TH_PUSH   0x08
00143 #endif
00144 #ifndef TH_ACK
00145 #define TH_ACK    0x10
00146 #endif
00147 #ifndef TH_URG
00148 #define TH_URG    0x20
00149 #endif
00150     u_short th_win;         /* window */
00151     u_short th_sum;         /* checksum */
00152     u_short th_urp;         /* urgent pointer */
00153 };
00154 
00155 
00156 /*
00157  *  UDP packet header prototype.
00158  */
00159 struct libnet_udp_hdr
00160 {
00161     u_short uh_sport;   /* soure port */
00162     u_short uh_dport;   /* destination port */
00163     u_short uh_ulen;    /* length */
00164     u_short uh_sum;     /* checksum */
00165 };
00166 
00167 
00168 /*
00169  *  ICMP packet header prototype.
00170  */
00171 struct libnet_icmp_hdr
00172 {
00173     u_char icmp_type;
00174 /*
00175  *  ICMP types.
00176  */
00177 #ifndef     ICMP_ECHOREPLY
00178 #define     ICMP_ECHOREPLY                  0
00179 #endif
00180 #ifndef     ICMP_UNREACH
00181 #define     ICMP_UNREACH                    3
00182 #endif
00183 #ifndef     ICMP_SOURCEQUENCH
00184 #define     ICMP_SOURCEQUENCH               4
00185 #endif
00186 #ifndef     ICMP_REDIRECT
00187 #define     ICMP_REDIRECT                   5
00188 #endif
00189 #ifndef     ICMP_ECHO
00190 #define     ICMP_ECHO                       8
00191 #endif
00192 #ifndef     ICMP_ROUTERADVERT
00193 #define     ICMP_ROUTERADVERT               9
00194 #endif
00195 #ifndef     ICMP_ROUTERSOLICIT
00196 #define     ICMP_ROUTERSOLICIT              10
00197 #endif
00198 #ifndef     ICMP_TIMXCEED
00199 #define     ICMP_TIMXCEED                   11
00200 #endif
00201 #ifndef     ICMP_PARAMPROB
00202 #define     ICMP_PARAMPROB                  12
00203 #endif
00204 #ifndef     ICMP_TSTAMP
00205 #define     ICMP_TSTAMP                     13
00206 #endif
00207 #ifndef     ICMP_TSTAMPREPLY
00208 #define     ICMP_TSTAMPREPLY                14
00209 #endif
00210 #ifndef     ICMP_IREQ
00211 #define     ICMP_IREQ                       15
00212 #endif
00213 #ifndef     ICMP_IREQREPLY
00214 #define     ICMP_IREQREPLY                  16
00215 #endif
00216 #ifndef     ICMP_MASKREQ
00217 #define     ICMP_MASKREQ                    17
00218 #endif
00219 #ifndef     ICMP_MASKREPLY
00220 #define     ICMP_MASKREPLY                  18
00221 #endif
00222     u_char icmp_code;
00223 /*
00224  *  ICMP codes.
00225  */
00226 #ifndef     ICMP_UNREACH_NET
00227 #define     ICMP_UNREACH_NET                0
00228 #endif
00229 #ifndef     ICMP_UNREACH_HOST
00230 #define     ICMP_UNREACH_HOST               1
00231 #endif
00232 #ifndef     ICMP_UNREACH_PROTOCOL
00233 #define     ICMP_UNREACH_PROTOCOL           2
00234 #endif
00235 #ifndef     ICMP_UNREACH_PORT
00236 #define     ICMP_UNREACH_PORT               3
00237 #endif
00238 #ifndef     ICMP_UNREACH_NEEDFRAG
00239 #define     ICMP_UNREACH_NEEDFRAG           4
00240 #endif
00241 #ifndef     ICMP_UNREACH_SRCFAIL
00242 #define     ICMP_UNREACH_SRCFAIL            5
00243 #endif
00244 #ifndef     ICMP_UNREACH_NET_UNKNOWN
00245 #define     ICMP_UNREACH_NET_UNKNOWN        6
00246 #endif
00247 #ifndef     ICMP_UNREACH_HOST_UNKNOWN
00248 #define     ICMP_UNREACH_HOST_UNKNOWN       7
00249 #endif
00250 #ifndef     ICMP_UNREACH_ISOLATED
00251 #define     ICMP_UNREACH_ISOLATED           8
00252 #endif
00253 #ifndef     ICMP_UNREACH_NET_PROHIB
00254 #define     ICMP_UNREACH_NET_PROHIB         9
00255 #endif
00256 #ifndef     ICMP_UNREACH_HOST_PROHIB
00257 #define     ICMP_UNREACH_HOST_PROHIB        10
00258 #endif
00259 #ifndef     ICMP_UNREACH_TOSNET
00260 #define     ICMP_UNREACH_TOSNET             11
00261 #endif
00262 #ifndef     ICMP_UNREACH_TOSHOST
00263 #define     ICMP_UNREACH_TOSHOST            12
00264 #endif
00265 #ifndef     ICMP_UNREACH_FILTER_PROHIB
00266 #define     ICMP_UNREACH_FILTER_PROHIB      13
00267 #endif
00268 #ifndef     ICMP_UNREACH_HOST_PRECEDENCE
00269 #define     ICMP_UNREACH_HOST_PRECEDENCE    14
00270 #endif
00271 #ifndef     ICMP_UNREACH_PRECEDENCE_CUTOFF
00272 #define     ICMP_UNREACH_PRECEDENCE_CUTOFF  15
00273 #endif
00274 #ifndef     ICMP_REDIRECT_NET
00275 #define     ICMP_REDIRECT_NET               0
00276 #endif
00277 #ifndef     ICMP_REDIRECT_HOST
00278 #define     ICMP_REDIRECT_HOST              1
00279 #endif
00280 #ifndef     ICMP_REDIRECT_TOSNET
00281 #define     ICMP_REDIRECT_TOSNET            2
00282 #endif
00283 #ifndef     ICMP_REDIRECT_TOSHOST
00284 #define     ICMP_REDIRECT_TOSHOST           3
00285 #endif
00286 #ifndef     ICMP_TIMXCEED_INTRANS
00287 #define     ICMP_TIMXCEED_INTRANS           0
00288 #endif
00289 #ifndef     ICMP_TIMXCEED_REASS
00290 #define     ICMP_TIMXCEED_REASS             1
00291 #endif
00292 #ifndef     ICMP_PARAMPROB_OPTABSENT
00293 #define     ICMP_PARAMPROB_OPTABSENT        1
00294 #endif
00295 
00296     u_short icmp_sum;
00297 
00298     union
00299     {
00300         struct
00301         {
00302             u_short id;
00303             u_short seq;
00304         }echo;
00305 
00306 #undef icmp_id
00307 #undef icmp_seq
00308 #define icmp_id     hun.echo.id
00309 #define icmp_seq    hun.echo.seq
00310  
00311         u_long gateway;
00312         struct
00313         {
00314             u_short pad;
00315             u_short mtu;
00316         }frag;
00317     }hun;
00318     union
00319     {
00320         struct
00321         {
00322             n_time its_otime;
00323             n_time its_rtime;
00324             n_time its_ttime;
00325         }ts;
00326         struct
00327         {
00328             struct ip idi_ip;
00329             /* options and then 64 bits of data */
00330         }ip;
00331         u_long mask;
00332         char data[1];
00333 
00334 #undef icmp_mask
00335 #define icmp_mask    dun.mask
00336 #undef icmp_data
00337 #define icmp_data    dun.data
00338 
00339 #undef icmp_otime
00340 #define icmp_otime   dun.ts.its_otime
00341 #undef icmp_rtime
00342 #define icmp_rtime   dun.ts.its_rtime
00343 #undef icmp_ttime
00344 #define icmp_ttime   dun.ts.its_ttime
00345     }dun;
00346 };
00347 
00348 
00349 /*
00350  *  IGMP header.
00351  */
00352 struct libnet_igmp_hdr
00353 {
00354     u_char igmp_type;
00355 #ifndef IGMP_MEMBERSHIP_QUERY
00356 #define IGMP_MEMBERSHIP_QUERY           0x11    /* membership query */
00357 #endif
00358 #ifndef IGMP_V1_MEMBERSHIP_REPORT
00359 #define IGMP_V1_MEMBERSHIP_REPORT       0x12    /* Ver. 1 membership report */
00360 #endif
00361 #ifndef IGMP_V2_MEMBERSHIP_REPORT
00362 #define IGMP_V2_MEMBERSHIP_REPORT       0x16    /* Ver. 2 membership report */
00363 #endif
00364 #ifndef IGMP_LEAVE_GROUP
00365 #define IGMP_LEAVE_GROUP                0x17    /* Leave-group message */
00366 #endif
00367     u_char igmp_code;
00368     u_short igmp_sum;
00369     struct in_addr igmp_group;
00370 };
00371 
00372 
00373 /* 
00374  *  Ethernet packet header prototype.  Too many O/S's define this differently.
00375  *  Easy enough to solve that and define it here.
00376  */
00377 struct libnet_ethernet_hdr
00378 {
00379 #ifndef ETHER_ADDR_LEN
00380 #define ETHER_ADDR_LEN 6
00381 #endif
00382     u_char  ether_dhost[ETHER_ADDR_LEN];    /* destination ethernet address */
00383     u_char  ether_shost[ETHER_ADDR_LEN];    /* source ethernet address */
00384     u_short ether_type;                     /* packet type ID */
00385 };
00386 
00387 #define ETHERTYPE_PUP           0x0200  /* PUP protocol */
00388 #define ETHERTYPE_IP            0x0800  /* IP protocol */
00389 #define ETHERTYPE_ARP           0x0806  /* Addr. resolution protocol */
00390 #define ETHERTYPE_REVARP        0x8035  /* reverse Addr. resolution protocol */
00391 #define ETHERTYPE_VLAN          0x8100  /* IEEE 802.1Q VLAN tagging */
00392 #define ETHERTYPE_LOOPBACK      0x9000  /* used to test interfaces */
00393 
00394 #if (!__GLIBC__)
00395 struct ether_addr
00396 {
00397     u_char  ether_addr_octet[6];
00398 };
00399 #endif
00400 
00401 /* 
00402  *  ARP packet header prototype.  Too many O/S's define this differently.
00403  *  Easy enough to solve that and define it here.
00404  */
00405 struct libnet_arp_hdr
00406 {
00407     u_short ar_hrd;                         /* format of hardware address */
00408 #define ARPHRD_ETHER     1                  /* ethernet hardware format */
00409     u_short ar_pro;                         /* format of protocol address */
00410     u_char  ar_hln;                         /* length of hardware address */
00411     u_char  ar_pln;                         /* length of protocol addres */
00412     u_short ar_op;                          /* operation type */
00413 #define ARPOP_REQUEST    1                  /* req to resolve address */
00414 #define ARPOP_REPLY      2                  /* resp to previous request */
00415 #define ARPOP_REVREQUEST 3                  /* req protocol address given hardware */
00416 #define ARPOP_REVREPLY   4                  /* resp giving protocol address */
00417 #define ARPOP_INVREQUEST 8                  /* req to identify peer */
00418 #define ARPOP_INVREPLY   9                  /* resp identifying peer */
00419 
00420     /*
00421      *  These should implementation defined but I've hardcoded eth/IP.
00422      */
00423     u_char ar_sha[6];                         /* sender hardware address */
00424     u_char ar_spa[4];                         /* sender protocol address */
00425     u_char ar_tha[6];                         /* target hardware address */
00426     u_char ar_tpa[4];                         /* target protocol address */
00427 };
00428 
00429 
00430 /*
00431  *  Base DNS header.
00432  */
00433 struct libnet_dns_hdr
00434 {
00435     u_short id;             /* DNS packet ID */
00436     u_short flags;          /* DNS flags */
00437     u_short num_q;          /* Number of questions */
00438     u_short num_answ_rr;    /* Number of answer resource records */
00439     u_short num_auth_rr;    /* Number of authority resource records */
00440     u_short num_addi_rr;    /* Number of additional resource records */
00441 };
00442 
00443 
00444 /*
00445  *  Base RIP (routing information protocol) header.
00446  */
00447 struct libnet_rip_hdr
00448 {
00449     u_char cmd;             /* RIP command */
00450 #define RIPCMD_REQUEST      1   /* want info */
00451 #define RIPCMD_RESPONSE     2   /* responding to request */
00452 #define RIPCMD_TRACEON      3   /* turn tracing on */
00453 #define RIPCMD_TRACEOFF     4   /* turn it off */
00454 #define RIPCMD_POLL         5   /* like request, but anyone answers */
00455 #define RIPCMD_POLLENTRY    6   /* like poll, but for entire entry */
00456 #define RIPCMD_MAX          7
00457     u_char ver;             /* RIP version */
00458 #define RIPVER_0            0
00459 #define RIPVER_1            1
00460 #define RIPVER_2            2
00461     u_short rd;             /* Zero (v1) or Routing Domain (v2) */
00462     u_short af;             /* Address family */
00463     u_short rt;             /* Zero (v1) or Route Tag (v2) */
00464     u_long addr;            /* IP address */
00465     u_long mask;            /* Zero (v1) or Subnet Mask (v2) */
00466     u_long next_hop;        /* Zero (v1) or Next hop IP address (v2) */
00467     u_long metric;          /* Metric */
00468 };
00469 
00470 
00471 #if 0
00472 struct libnet_snmp_hdr
00473 {
00474     /* ASN.1 BER support first */
00475 };
00476 #endif
00477 
00478 
00479 /*
00480  *  TCP options structure.
00481  */
00482 struct tcpoption
00483 {
00484     u_char tcpopt_list[MAX_IPOPTLEN];
00485 };
00486 
00487 
00488 #if (__linux__  || WIN32)
00489 /*
00490  *  Linux has a radically different IP options structure from BSD.
00491  */
00492 struct ipoption
00493 {
00494     struct  in_addr ipopt_dst;          /* first-hop dst if source routed */
00495     char ipopt_list[MAX_IPOPTLEN];      /* options proper */
00496 };
00497 #endif
00498 
00499 #endif  /* __LIBNET_HEADERS_H */
00500 
00501 /* EOF */

Generated on Sun May 14 14:51:19 2006 by  doxygen 1.4.2