1 /**********************************************************
2 SixXS - Automatic IPv6 Connectivity Configuration Utility
3 ***********************************************************
4 Copyright 2003-2005 SixXS - http://www.sixxs.net
5 ***********************************************************
6 common/common.h - Common Definitions
7 ***********************************************************
9 $Id: common.h,v 1.23 2007-01-11 14:50:51 jeroen Exp $
10 $Date: 2007-01-11 14:50:51 $
11 **********************************************************/
13 #ifndef AICCU_COMMON_H
14 #define AICCU_COMMON_H "H5K7:W3NDY5UU5N1K1N1C0l3"
31 #define __STRICT_ANSI__
33 /* Don't deprecate strncat etc. */
35 #define _CRT_SECURE_NO_DEPRECATE
39 #define _H_ARPA_ONAMESER_COMPAT "AICCU workaround"
40 #include <net/net_globals.h>
51 #include <sys/types.h>
55 #if defined(_SUNOS) || defined(_AIX) || defined(_DARWIN)
56 /* Include this as it knows quite a bit about endianess */
57 #include <arpa/nameser_compat.h>
60 #if defined(_OPENBSD) || defined(_DFBSD) || defined(_FREEBSD) || defined(_NETBSD)
61 #include <sys/endian.h>
68 /* For MD5 routines */
70 #include <sys/types.h>
76 #include <netinet/in_systm.h>
80 #define _BSD_SOCKLEN_T_
83 #include <sys/socket.h>
84 #include <netinet/in.h>
89 #include <arpa/inet.h>
90 #include <sys/ioctl.h>
91 #include <sys/select.h>
94 #include <netinet/if_ether.h>
96 #include <netpacket/packet.h>
97 #include <linux/if_tun.h>
100 #include <net/tun/if_tun.h>
104 * Darwin doesn't have TUN/TAP support per default
105 * It is available from http://www-user.rhrk.uni-kl.de/~nissler/tuntap/
106 * which is a port made by Mattias Nissler
107 * for compiling convienience we have included the ioctl's here
109 #define TUNSIFHEAD _IOW('t', 96, int)
110 #define TUNGIFHEAD _IOR('t', 97, int)
113 #include <net/if_tun.h>
114 /* endif for !_AIX */
116 /* endif for _DARWIN else */
118 /* endif for _DFBSD else */
120 /* endif for linux else */
122 #include <netinet/ip.h>
123 #include <netinet/ip6.h>
124 #include <netinet/icmp6.h>
125 #include <netinet/tcp.h>
126 #include <netinet/udp.h>
127 #include <netinet/ip_icmp.h>
128 #include <sys/ioctl.h>
130 #if defined(_OPENBSD) || defined(_DARWIN) || defined(_FREEBSD) || defined(_DFBSD)
137 * Windows abstracts sockets to a different
138 * type, as this is actually pretty nice
145 /* closesocket() -> close() on unices */
146 #define closesocket close
149 * Expect a BSD style in6_addr who puts
150 * this between a #ifdef _KERNEL...
151 * Probably against people doing stuff in userspace?
155 #define s6_addr __u6_addr.__u6_addr8
157 #define s6_addr _S6_un._S6_u8
163 #include <winsock2.h>
164 #include <ws2tcpip.h>
166 /* Windows Specifics */
170 * Some weird M$ person thought it was
171 * funny to underscore common functions !?
173 #define snprintf _snprintf
174 #define vsnprintf _vsnprintf
175 #define strcasecmp _stricmp
176 #define strncasecmp _strnicmp
177 #define strdup _strdup
180 * Capitalize this one
181 * Sleep() is in milliseconds
183 #define sleep(x) Sleep(x*1000)
185 /* No syslog on Windows */
188 #define LOG_WARNING 3
191 typedef unsigned long u_int32_t
;
192 typedef unsigned long long u_int64_t
;
194 typedef unsigned char u_int8_t
;
195 typedef unsigned __int16 u_int16_t
;
196 typedef unsigned __int64 u_int64_t
;
198 /* Not available in the Winsock2 includes */
199 #define IPPROTO_NONE 59 /* IPv6 no next header */
201 #define BIG_ENDIAN 4321
202 #define LITTLE_ENDIAN 1234
204 #define __BIG_ENDIAN BIG_ENDIAN
205 #define __LITTLE_ENDIAN LITTLE_ENDIAN
208 #define __BYTE_ORDER __LITTLE_ENDIAN
209 #define BYTE_ORDER LITTLE_ENDIAN
211 #define s6_addr16 _S6_un.Word
212 #define SHUT_RDWR SD_BOTH
213 #define uint8_t u_int8_t
214 #define uint16_t u_int16_t
215 #define uint32_t u_int32_t
216 #define uint64_t u_int64_t
220 uint16_t ether_dhost
[3];
221 uint16_t ether_shost
[3];
225 /* The IPv6 Header */
232 uint32_t ip6_un1_flow
; /* 4 bits version, 8 bits TC, 20 bits flow-ID */
233 uint16_t ip6_un1_plen
; /* payload length */
234 uint8_t ip6_un1_nxt
; /* next header */
235 uint8_t ip6_un1_hlim
; /* hop limit */
237 uint8_t ip6_un2_vfc
; /* 4 bits version, top 4 bits tclass */
239 struct in6_addr ip6_src
; /* source address */
240 struct in6_addr ip6_dst
; /* destination address */
246 uint8_t icmp6_type
; /* type field */
247 uint8_t icmp6_code
; /* code field */
248 uint16_t icmp6_cksum
; /* checksum field */
251 uint32_t icmp6_un_data32
[1]; /* type-specific field */
252 uint16_t icmp6_un_data16
[2]; /* type-specific field */
253 uint8_t icmp6_un_data8
[4]; /* type-specific field */
257 #define ND_NEIGHBOR_SOLICIT 135
258 #define ND_NEIGHBOR_ADVERT 136
260 struct nd_neighbor_solicit
262 struct in6_addr nd_ns_target
; /* target address */
263 /* could be followed by options */
266 struct nd_neighbor_advert
268 struct in6_addr nd_na_target
; /* target address */
269 /* could be followed by options */
270 uint8_t nd_no_type
; /* Option providing the target MAC address */
271 uint8_t nd_no_len
; /* Length (1) */
272 uint8_t nd_no_mac
[6]; /* MAC address */
276 const char *inet_ntop(int af
, const void *src
, char *dst
, socklen_t cnt
);
277 int inet_pton(int af
, const char *src
, void *dst
);
282 #define MSG_NOSIGNAL 0
285 #ifndef LITTLE_ENDIAN
286 #define LITTLE_ENDIAN __LITTLE_ENDIAN
289 #define BIG_ENDIAN __BIG_ENDIAN
292 #define PDP_ENDIAN __PDP_ENDIAN
295 #define BYTE_ORDER __BYTE_ORDER
298 /* Boolean support */
300 #define bool uint32_t
306 #define true (!false)
310 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
313 /* Include MD5 and SHA1 support */
314 #include "hash_md5.h"
315 #include "hash_sha1.h"
317 /* Resolver includes */
319 #include <netinet/in.h>
320 #include <arpa/nameser.h>
326 #include <gnutls/gnutls.h>
330 #define NS_INT32SZ 4 /* #/bytes of data in a u_int32_t */
334 #define NS_INT16SZ 2 /* #/bytes of data in a u_int16_t */
339 #define NS_GET16(s, cp) do { \
340 register u_char *t_cp = (u_char *)(cp); \
341 (s) = ((u_int16_t)t_cp[0] << 8) \
342 | ((u_int16_t)t_cp[1]) \
344 (cp) += NS_INT16SZ; \
349 #define NS_GET32(l, cp) do { \
350 register u_char *t_cp = (u_char *)(cp); \
351 (l) = ((u_int32_t)t_cp[0] << 24) \
352 | ((u_int32_t)t_cp[1] << 16) \
353 | ((u_int32_t)t_cp[2] << 8) \
354 | ((u_int32_t)t_cp[3]) \
356 (cp) += NS_INT32SZ; \
360 /* parseline() rules */
363 PLRT_STRING
, /* Offset points to a String (strdup()) */
364 PLRT_INTEGER
, /* Offset points to a Integer (unsigned int) */
365 PLRT_BOOL
, /* Offset points to a Boolean. */
366 PLRT_IPV4
, /* Offset points to a IPv4 address (inet_pton(..., AF_INET)) */
367 PLRT_IPV6
, /* Offset points to a IPv6 address (inet_pton(..., AF_INET6)) */
368 PLRT_END
/* End of rules */
383 bool tls_active
; /* TLS active? */
384 gnutls_session session
; /* The GnuTLS sesision */
388 typedef struct tlssocket
* TLSSOCKET
;
390 /* Common Functions */
391 void dologA(int level
, const char *fmt
, va_list ap
);
392 void dolog(int level
, const char *fmt
, ...);
395 void vsyslog(int priority
, const char *format
, va_list ap
);
398 /* Networking functions */
399 void sock_printf(TLSSOCKET sock
, const char *fmt
, ...);
400 int sock_getline(TLSSOCKET sock
, char *rbuf
, unsigned int rbuflen
, unsigned int *filled
, char *ubuf
, unsigned int ubuflen
);
401 TLSSOCKET
connect_client(const char *hostname
, const char *service
, int family
, int socktype
);
402 TLSSOCKET
listen_server(const char *description
, const char *hostname
, const char *service
, int family
, int socktype
);
403 void sock_free(TLSSOCKET sock
);
405 bool sock_gotls(TLSSOCKET sock
);
408 /* Parsing functions */
409 unsigned int countfields(char *s
);
410 bool copyfield(char *s
, unsigned int n
, char *buf
, unsigned int buflen
);
411 bool parseline(char *line
, const char *split
, struct pl_rule
*rules
, void *data
);
414 void MD5String(const char *sString
, char *sSignature
, unsigned int siglen
);
415 bool is_rfc1918(char *ipv4
);
417 #endif /* AICCU_COMMON_H */