1 #ifndef DEFS_H
2 #define DEFS_H
3 
4 #ifdef HAVE_CONFIG_H
5 # include "config.h"
6 #endif
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <stddef.h>
11 #include <errno.h>
12 #include <string.h>
13 #include <strings.h>
14 
15 #include <time.h>
16 
17 
18 #ifdef HAVE_SYSLOG_H
19 #include <syslog.h>
20 #endif
21 
22 #ifdef HAVE_STRING_H
23 #include <signal.h>
24 #endif
25 
26 #ifdef  STDC_HEADERS
27 #include <stdarg.h>
28 #else
29 #include <varargs.h>
30 #endif
31 
32 #ifdef HAVE_INTTYPES_H
33 # include <inttypes.h>
34 #elif defined(HAVE_STDINT_H)
35 # include <stdint.h>
36 #endif
37 
38 #ifdef HAVE_SYS_TYPES_H
39 #include <sys/types.h>
40 #endif
41 
42 #ifdef HAVE_SYS_SOCKET_H
43 /* On Solaris, you must include sys/types.h before sys/socket.h. */
44 #include <sys/socket.h>
45 #endif
46 
47 #ifdef HAVE_SYS_IOCTL_H
48 #include <sys/ioctl.h>
49 #endif
50 
51 #ifdef HAVE_SYS_SOCKIO_H
52 #include <sys/sockio.h>
53 #endif
54 
55 #if TIME_WITH_SYS_TIME
56 # include <sys/time.h>
57 # include <time.h>
58 #else
59 # if HAVE_SYS_TIME_H
60 #  include <sys/time.h>
61 # else
62 #  include <time.h>
63 # endif
64 #endif
65 
66 #include <limits.h>
67 
68 #ifdef HAVE_UNISTD_H
69 #include <unistd.h>
70 #endif
71 
72 #include <sys/wait.h>
73 
74 #ifdef HAVE_NET_IF_H
75 #include <net/if.h>
76 #endif
77 
78 #ifdef HAVE_NETINET_IN_H
79 #include <netinet/in.h>
80 #endif
81 
82 /* To get declarations of ether_aton(), ether_ntoa(), ether_ntohost(), ether_hostton() on Solaris 10,
83    we need sys/ethernet.h.  But it's not a good idea to include sys/ethernet.h directly; while that
84    would work in Solaris 10, it would break in Solaris 9 if we ever find we need to include netinet/if_ether;
85    in Solaris 9 you must not include BOTH netinet/if_ether.h and sys/ethernet.h, since there are some definitions
86    duplicated in the two files.
87    Fortunately, on Solaris 10, netinet/if_ether.h includes sys/ethernet.h for you, ultimately
88    getting the ether_aton(), ether_ntoa(), ether_ntohost(), ether_hostton() declarations we want.
89    So the result is that on Solaris 9, by including netinet/if_ether.h we avoid a potential future
90    conflict  and we don't get ether_aton(), ether_ntoa(), ether_ntohost(), ether_hostton(), but those four declarations
91    aren't available in Solaris 9 anyway.  And in Solaris 10, we get ether_aton(), ether_ntoa(), ether_ntohost(), ether_hostton().
92 */
93 #ifdef HAVE_NETINET_IF_ETHER_H
94 /* In Solaris, before using netinet/if_ether.h you need sys/socket.h and net/if.h.   We already have both above. */
95 #include <netinet/if_ether.h>
96 #endif
97 
98 #ifdef HAVE_NETINET_ETHER_H
99 /* ether_aton(), ether_ntoa(), ether_ntohost(), ether_hostton() are declared in netinet/ether.h on Redhat 9. */
100 #include <netinet/ether.h>
101 #endif
102 
103 #include <netinet/in_systm.h> /* for n_long def used by netinet/ip.h */
104 
105 /* In Linux, use the BSD flavor IP structure headers instead of the Linux flavor headers. */
106 #ifndef __FAVOR_BSD
107 #define __FAVOR_BSD 1
108 #endif
109 
110 #ifdef HAVE_NETINET_IP_H
111 #include <netinet/ip.h>
112 #endif
113 
114 #include <netinet/udp.h>
115 
116 #ifdef HAVE_ARPA_INET_H
117 #include <arpa/inet.h>
118 #endif
119 
120 #ifdef HAVE_NET_IF_ARP_H
121 #include <net/if_arp.h>
122 #endif
123 
124 #ifndef HAVE_INET_ATON_PROTO
125 # include   <sys/types.h>
126 # include   <netinet/in.h>
127 extern int inet_aton(const char *, struct in_addr *);
128 #endif /* not HAVE_INET_ATON_PROTO */
129 
130 #ifdef HAVE_SYS_RESOURCE_H
131 #include <sys/resource.h>
132 #endif
133 
134 #include <pcap.h> /* libpcap */
135 
136 #include <libnet.h> /* libnet */
137 
138 #ifndef HAVE_BCOPY
139 #define bcopy(a, b, c)  memcpy(b, a, c)
140 #endif
141 #ifndef HAVE_BCMP
142 #define bcmp(a, b, c)   memcmp(a, b, c)
143 #endif
144 #ifndef HAVE_BZERO
145 #define bzero(s, n)     memset((s), 0, (n))
146 #endif
147 
148 #ifdef HAVE_SIGNAL_SYSV
149 #define signal(s,f) sigset(s,f)
150 #endif
151 
152 
153 #define PASTE(a,b) a ## b
154 
155 /* Prototypes for these routines are missing from some systems. */
156 #if !HAVE_DECL_ETHER_NTOA
157 extern char *ether_ntoa (const struct libnet_ether_addr *e);
158 #endif
159 #if !HAVE_DECL_ETHER_ATON
160 extern struct libnet_ether_addr *ether_aton(const char *hostname);
161 #endif
162 #if !HAVE_DECL_ETHER_NTOHOST
163 extern int ether_ntohost (char *hostname, const struct libnet_ether_addr *e);
164 #endif
165 #if !HAVE_DECL_ETHER_HOSTTON
166 extern int ether_hostton (const char *hostname, struct libnet_ether_addr *e);
167 #endif
168 
169 #ifndef ETHERTYPE_IP
170 #define ETHERTYPE_IP        (0x0800)       /* IP protocol */
171 #endif
172 
173 #ifndef ETHERTYPE_VLAN
174 #define ETHERTYPE_VLAN      (0x8100)      /* IEEE 802.1Q VLAN */
175 #endif
176 
177 /* Definition of 802.1Q VLAN header fields are vary widely among platforms,
178    and often are entirely missing.
179    We'll have to rely on our own definition.
180 */
181 typedef struct my_ether_vlan_header {
182 	struct libnet_ether_addr	ether_dhost;
183 	struct libnet_ether_addr	ether_shost;
184 	uint16_t			ether_tpid; /* == 0x8100 == ETHERTYPE_VLAN */
185 	uint16_t			ether_tci;  /* user_pri, cfi, vid */
186 	uint16_t			ether_type;
187 } my_ether_vlan_header_t;
188 
189 /* libnet 1.1.3+ has ether_addr_octet in struct libnet_ether_addr{} */
190 #ifndef STRUCT_ETHER_ADDR_HAS_ETHER_ADDR_OCTET
191 #define STRUCT_ETHER_ADDR_HAS_ETHER_ADDR_OCTET 1
192 #endif
193 
194 #endif /* not DEFS_H */
195