- Main Page
- Files

# libnet-structures.h

    00001 /*
    00002  *  $Id: libnet-structures.h,v 1.19 2004/11/09 07:05:07 mike Exp $
    00003  *
    00004  *  libnet-structures.h - Network routine library structures header file
    00005  *
    00006  *  Copyright (c) 1998 - 2004 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_STRUCTURES_H
    00033 #define __LIBNET_STRUCTURES_H
    00034
    00035 #if ((__WIN32__) && !(__CYGWIN__))
    00036 #include "Packet32.h"
    00037 #endif
    00038
    00039 /* port list chain structure */
    00040 typedef struct libnet_port_list_chain libnet_plist_t;
    00041 struct libnet_port_list_chain
    00042 {
    00043     uint16_t node;                     /* node number */
    00044     uint16_t bport;                    /* beggining port */
    00045     uint16_t eport;                    /* terminating port */
    00046     uint8_t  id;                       /* global array offset */
    00047     libnet_plist_t *next;               /* next node in the list */
    00048 };
    00049
    00050
    00051 /* libnet statistics structure */
    00052 struct libnet_stats
    00053 {
    00054 #if (!defined(__WIN32__) || (__CYGWIN__))
    00055     uint64_t packets_sent;             /* packets sent */
    00056     uint64_t packet_errors;            /* packets errors */
    00057     uint64_t bytes_written;            /* bytes written */
    00058 #else
    00059     __int64 packets_sent;               /* packets sent */
    00060     __int64 packet_errors;              /* packets errors */
    00061     __int64 bytes_written;              /* bytes written */
    00062 #endif
    00063 };
    00064
    00065
    00066 /*
    00067  *  Libnet ptags are how we identify specific protocol blocks inside the
    00068  *  list.
    00069  */
    00070 typedef int32_t libnet_ptag_t;
    00071 #define LIBNET_PTAG_INITIALIZER         0
    00072
    00073
    00074 /*
    00075  *  Libnet generic protocol block memory object.  Sort of a poor man's mbuf.
    00076  */
    00077 struct libnet_protocol_block
    00078 {
    00079     uint8_t *buf;                      /* protocol buffer */
    00080     uint32_t b_len;                    /* length of buf */
    00081     uint16_t h_len;                    /* header length */
    00082        /* Passed as last argument to libnet_do_checksum(). Not necessarily used
    00083         * by that function, it is essentially a pblock specific number, passed
    00084         * from _builder to the _do_checksum
    00085         *
    00086         * Unused for IPV4_H block types.
    00087         *
    00088         * For protocols that sit on top of IP, it should be the the amount of
    00089         * buf that will be included in the checksum, starting from the beginning
    00090         * of the header.
    00091         */
    00092     uint32_t copied;                   /* bytes copied - the amount of data copied into buf */
    00093        /* Used and updated by libnet_pblock_append(). */
    00094     uint8_t type;                      /* type of pblock */
    00095 /* this needs to be updated every time a new packet builder is added */
    00096 /* libnet_diag_dump_pblock_type() also needs updating for every new pblock tag */
    00097 #define LIBNET_PBLOCK_ARP_H             0x01    /* ARP header */
    00098 #define LIBNET_PBLOCK_DHCPV4_H          0x02    /* DHCP v4 header */
    00099 #define LIBNET_PBLOCK_DNSV4_H           0x03    /* DNS v4 header */
    00100 #define LIBNET_PBLOCK_ETH_H             0x04    /* Ethernet header */
    00101 #define LIBNET_PBLOCK_ICMPV4_H          0x05    /* ICMP v4 base header */
    00102 #define LIBNET_PBLOCK_ICMPV4_ECHO_H     0x06    /* ICMP v4 echo header */
    00103 #define LIBNET_PBLOCK_ICMPV4_MASK_H     0x07    /* ICMP v4 mask header */
    00104 #define LIBNET_PBLOCK_ICMPV4_UNREACH_H  0x08    /* ICMP v4 unreach header */
    00105 #define LIBNET_PBLOCK_ICMPV4_TIMXCEED_H 0x09    /* ICMP v4 exceed header */
    00106 #define LIBNET_PBLOCK_ICMPV4_REDIRECT_H 0x0a    /* ICMP v4 redirect header */
    00107 #define LIBNET_PBLOCK_ICMPV4_TS_H       0x0b    /* ICMP v4 timestamp header */
    00108 #define LIBNET_PBLOCK_IGMP_H            0x0c    /* IGMP header */
    00109 #define LIBNET_PBLOCK_IPV4_H            0x0d    /* IP v4 header */
    00110 #define LIBNET_PBLOCK_IPO_H             0x0e    /* IP v4 options */
    00111 #define LIBNET_PBLOCK_IPDATA            0x0f    /* IP data */
    00112 #define LIBNET_PBLOCK_OSPF_H            0x10    /* OSPF base header */
    00113 #define LIBNET_PBLOCK_OSPF_HELLO_H      0x11    /* OSPF hello header */
    00114 #define LIBNET_PBLOCK_OSPF_DBD_H        0x12    /* OSPF dbd header */
    00115 #define LIBNET_PBLOCK_OSPF_LSR_H        0x13    /* OSPF lsr header */
    00116 #define LIBNET_PBLOCK_OSPF_LSU_H        0x14    /* OSPF lsu header */
    00117 #define LIBNET_PBLOCK_OSPF_LSA_H        0x15    /* OSPF lsa header */
    00118 #define LIBNET_PBLOCK_OSPF_AUTH_H       0x16    /* OSPF auth header */
    00119 #define LIBNET_PBLOCK_OSPF_CKSUM        0x17    /* OSPF checksum header */
    00120 #define LIBNET_PBLOCK_LS_RTR_H          0x18    /* linkstate rtr header */
    00121 #define LIBNET_PBLOCK_LS_NET_H          0x19    /* linkstate net header */
    00122 #define LIBNET_PBLOCK_LS_SUM_H          0x1a    /* linkstate as sum header */
    00123 #define LIBNET_PBLOCK_LS_AS_EXT_H       0x1b    /* linkstate as ext header */
    00124 #define LIBNET_PBLOCK_NTP_H             0x1c    /* NTP header */
    00125 #define LIBNET_PBLOCK_RIP_H             0x1d    /* RIP header */
    00126 #define LIBNET_PBLOCK_TCP_H             0x1e    /* TCP header */
    00127 #define LIBNET_PBLOCK_TCPO_H            0x1f    /* TCP options */
    00128 #define LIBNET_PBLOCK_TCPDATA           0x20    /* TCP data */
    00129 #define LIBNET_PBLOCK_UDP_H             0x21    /* UDP header */
    00130 #define LIBNET_PBLOCK_VRRP_H            0x22    /* VRRP header */
    00131 #define LIBNET_PBLOCK_DATA_H            0x23    /* generic data */
    00132 #define LIBNET_PBLOCK_CDP_H             0x24    /* CDP header */
    00133 #define LIBNET_PBLOCK_IPSEC_ESP_HDR_H   0x25    /* IPSEC ESP header */
    00134 #define LIBNET_PBLOCK_IPSEC_ESP_FTR_H   0x26    /* IPSEC ESP footer */
    00135 #define LIBNET_PBLOCK_IPSEC_AH_H        0x27    /* IPSEC AH header */
    00136 #define LIBNET_PBLOCK_802_1Q_H          0x28    /* 802.1q header */
    00137 #define LIBNET_PBLOCK_802_2_H           0x29    /* 802.2 header */
    00138 #define LIBNET_PBLOCK_802_2SNAP_H       0x2a    /* 802.2 SNAP header */
    00139 #define LIBNET_PBLOCK_802_3_H           0x2b    /* 802.3 header */
    00140 #define LIBNET_PBLOCK_STP_CONF_H        0x2c    /* STP configuration header */
    00141 #define LIBNET_PBLOCK_STP_TCN_H         0x2d    /* STP TCN header */
    00142 #define LIBNET_PBLOCK_ISL_H             0x2e    /* ISL header */
    00143 #define LIBNET_PBLOCK_IPV6_H            0x2f    /* IP v6 header */
    00144 #define LIBNET_PBLOCK_802_1X_H          0x30    /* 802.1x header */
    00145 #define LIBNET_PBLOCK_RPC_CALL_H        0x31    /* RPC Call header */
    00146 #define LIBNET_PBLOCK_MPLS_H            0x32    /* MPLS header */
    00147 #define LIBNET_PBLOCK_FDDI_H            0x33    /* FDDI header */
    00148 #define LIBNET_PBLOCK_TOKEN_RING_H      0x34    /* TOKEN RING header */
    00149 #define LIBNET_PBLOCK_BGP4_HEADER_H     0x35    /* BGP4 header */
    00150 #define LIBNET_PBLOCK_BGP4_OPEN_H       0x36    /* BGP4 open header */
    00151 #define LIBNET_PBLOCK_BGP4_UPDATE_H     0x37    /* BGP4 update header */
    00152 #define LIBNET_PBLOCK_BGP4_NOTIFICATION_H 0x38  /* BGP4 notification header */
    00153 #define LIBNET_PBLOCK_GRE_H             0x39    /* GRE header */
    00154 #define LIBNET_PBLOCK_GRE_SRE_H         0x3a    /* GRE SRE header */
    00155 #define LIBNET_PBLOCK_IPV6_FRAG_H       0x3b    /* IPv6 frag header */
    00156 #define LIBNET_PBLOCK_IPV6_ROUTING_H    0x3c    /* IPv6 routing header */
    00157 #define LIBNET_PBLOCK_IPV6_DESTOPTS_H   0x3d    /* IPv6 dest opts header */
    00158 #define LIBNET_PBLOCK_IPV6_HBHOPTS_H    0x3e    /* IPv6 hop/hop opts header */
    00159 #define LIBNET_PBLOCK_SEBEK_H           0x3f    /* Sebek header */
    00160 #define LIBNET_PBLOCK_HSRP_H            0x40    /* HSRP header */
    00161 #define LIBNET_PBLOCK_ICMPV6_H          0x41    /* ICMPv6 header */
    00162 #define LIBNET_PBLOCK_ICMPV6_UNREACH_H  0x42    /* ICMPv6 unreach header */
    00163
    00164     uint8_t flags;                             /* control flags */
    00165 #define LIBNET_PBLOCK_DO_CHECKSUM       0x01    /* needs a checksum */
    00166     libnet_ptag_t ptag;                 /* protocol block tag */
    00167     /* Chains are built from highest level protocol, towards the link level, so
    00168      * prev traverses away from link level, and next traverses towards the
    00169      * link level.
    00170      */
    00171     struct libnet_protocol_block *next; /* next pblock */
    00172     struct libnet_protocol_block *prev; /* prev pblock */
    00173 };
    00174 typedef struct libnet_protocol_block libnet_pblock_t;
    00175
    00176
    00177 /*
    00178  *  Libnet context
    00179  *  Opaque structure.  Nothing in here should ever been touched first hand by
    00180  *  the applications programmer.
    00181  */
    00182 struct libnet_context
    00183 {
    00184 #if ((__WIN32__) && !(__CYGWIN__))
    00185     SOCKET fd;
    00186     LPADAPTER  lpAdapter;
    00187 #else
    00188     int fd;                             /* file descriptor of packet device */
    00189 #endif
    00190     int injection_type;                 /* one of: */
    00191 #define LIBNET_NONE     0xf8            /* no injection type, only construct packets */
    00192 #define LIBNET_LINK     0x00            /* link-layer interface */
    00193 #define LIBNET_RAW4     0x01            /* raw socket interface (ipv4) */
    00194 #define LIBNET_RAW6     0x02            /* raw socket interface (ipv6) */
    00195 /* the following should actually set a flag in the flags variable above */
    00196 #define LIBNET_LINK_ADV 0x08            /* advanced mode link-layer */
    00197 #define LIBNET_RAW4_ADV 0x09            /* advanced mode raw socket (ipv4) */
    00198 #define LIBNET_RAW6_ADV 0x0a            /* advanced mode raw socket (ipv6) */
    00199 #define LIBNET_ADV_MASK 0x08            /* mask to determine adv mode */
    00200
    00201     /* _blocks is the highest level, and _end is closest to link-level */
    00202     libnet_pblock_t *protocol_blocks;   /* protocol headers / data */
    00203     libnet_pblock_t *pblock_end;        /* last node in list */
    00204     uint32_t n_pblocks;                /* number of pblocks */
    00205
    00206     int link_type;                      /* link-layer type, a DLT_ value. */
    00207     /* These are the only values used by libnet (see libnet_build_arp and
    00208      * libnet_build_link).  Other values are assigned by the various
    00209      * libnet_link_*.c OS support functions, but are not yet used or supported,
    00210      * they are effectively dead code. <pcap.h> claims these two are invariant
    00211      * across operating systems... hopefully it is correct!
    00212      */
    00213 #ifndef DLT_EN10MB
    00214 # define DLT_EN10MB      1       /* Ethernet (10Mb) */
    00215 #endif
    00216 #ifndef DLT_IEEE802
    00217 # define DLT_IEEE802     6       /* IEEE 802 Networks */
    00218 #endif
    00219
    00220     int link_offset;                    /* link-layer header size */
    00221     int aligner;                        /* used to align packets */
    00222     char *device;                       /* device name */
    00223
    00224     struct libnet_stats stats;          /* statistics */
    00225     libnet_ptag_t ptag_state;           /* state holder for pblock tag */
    00226     char label[LIBNET_LABEL_SIZE];      /* textual label for cq interface */
    00227
    00228     char err_buf[LIBNET_ERRBUF_SIZE];   /* error buffer */
    00229     uint32_t total_size;               /* total size */
    00230 };
    00231 typedef struct libnet_context libnet_t;
    00232
    00233 /*
    00234  *  Libnet context queue structure
    00235  *  Opaque structure.  Nothing in here should ever been touched first hand by
    00236  *  the applications programmer.
    00237  */
    00238 typedef struct _libnet_context_queue libnet_cq_t;
    00239 struct _libnet_context_queue
    00240 {
    00241     libnet_t *context;                  /* pointer to libnet context */
    00242     libnet_cq_t *next;                  /* next node in the list */
    00243     libnet_cq_t *prev;                  /* previous node in the list */
    00244 };
    00245
    00246 struct _libnet_context_queue_descriptor
    00247 {
    00248     uint32_t node;                     /* number of nodes in the list */
    00249     uint32_t cq_lock;                  /* lock status */
    00250     libnet_cq_t *current;               /* current context */
    00251 };
    00252 typedef struct _libnet_context_queue_descriptor libnet_cqd_t;
    00253
    00254 #endif  /* __LIBNET_STRUCTURES_H */
    00255
    00256 /* EOF */