1 /*
2  *  config-unix.h
3  *
4  *  Unix specific definitions and includes
5  *
6  *  $Revision: 1.24 $
7  *  $Date: 2002/04/01 22:14:32 $
8  *
9  * Copyright (c) 1995-2000 University College London
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, is permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *      This product includes software developed by the Computer Science
23  *      Department at University College London
24  * 4. Neither the name of the University nor of the Department may be used
25  *    to endorse or promote products derived from this software without
26  *    specific prior written permission.
27  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  */
39 
40 #ifndef WIN32
41 #ifndef _CONFIG_UNIX_H
42 #define _CONFIG_UNIX_H
43 
44 #include "uclconf.h"
45 
46 #include <limits.h>
47 #include <sys/types.h>
48 #if TIME_WITH_SYS_TIME
49 #include <sys/time.h>
50 #include <time.h>
51 #else
52 #if HAVE_SYS_TIME_H
53 #include <sys/time.h>
54 #else
55 #include <time.h>
56 #endif
57 #endif
58 #include <sys/resource.h>
59 
60 #include <pwd.h>
61 #include <signal.h>
62 #include <ctype.h>
63 
64 #include <stdio.h>
65 #include <stdarg.h>
66 #include <memory.h>
67 #include <errno.h>
68 #include <math.h>
69 #include <stdlib.h>   /* abs() */
70 #include <string.h>
71 #include <fcntl.h>
72 #include <sys/types.h>
73 #include <sys/socket.h>
74 #include <sys/stat.h>
75 #include <sys/uio.h>
76 #include <netinet/in.h>
77 #include <unistd.h>
78 #include <sys/param.h>
79 #include <sys/fcntl.h>
80 #include <sys/ioctl.h>
81 #include <netdb.h>
82 #include <arpa/inet.h>
83 
84 #ifdef __APPLE__
85 #define NEED_DRAND48
86 #define srand48 srand
87 #define lrand48 rand() * rand
88 #endif
89 
90 #ifdef HAVE_SYS_WAIT_H
91 #include <sys/wait.h>
92 #endif
93 #ifndef WEXITSTATUS
94 #define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
95 #endif
96 #ifndef WIFEXITED
97 #define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
98 #endif
99 
100 #ifdef HAVE_STDINT_H
101 #include <stdint.h>
102 #endif
103 
104 #ifdef HAVE_INTTYPES_H
105 #include <inttypes.h>
106 #endif
107 
108 #ifdef HAVE_STROPTS_H
109 #include <stropts.h>
110 #endif /* HAVE_STROPTS_H */
111 
112 #ifdef HAVE_SYS_FILIO_H
113 #include <sys/filio.h>
114 #endif /* HAVE_SYS_FILIO_H */
115 
116 #ifdef HAVE_IPv6
117 
118 #ifdef HAVE_NETINET6_IN6_H
119 /* Expect IPV6_{JOIN,LEAVE}_GROUP in in6.h, otherwise expect                 */
120 /* IPV_{ADD,DROP}_MEMBERSHIP in in.h                                         */
121 #include <netinet6/in6.h>
122 #else
123 #include <netinet/in.h>
124 #endif /* HAVE_NETINET_IN6_H */
125 
126 #ifndef IPV6_ADD_MEMBERSHIP
127 #ifdef  IPV6_JOIN_GROUP
128 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
129 #else
130 #error  No definition of IPV6_ADD_MEMBERSHIP, please report to mm-tools@cs.ucl.ac.uk.
131 #endif /* IPV6_JOIN_GROUP     */
132 #endif /* IPV6_ADD_MEMBERSHIP */
133 
134 #ifndef IPV6_DROP_MEMBERSHIP
135 #ifdef  IPV6_LEAVE_GROUP
136 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
137 #else
138 #error  No definition of IPV6_LEAVE_GROUP, please report to mm-tools@cs.ucl.ac.uk.
139 #endif  /* IPV6_LEAVE_GROUP     */
140 #endif  /* IPV6_DROP_MEMBERSHIP */
141 
142 #endif /* HAVE_IPv6 */
143 
144 #include <net/if.h>
145 
146 typedef u_char	ttl_t;
147 typedef int	fd_t;
148 
149 #ifndef FALSE
150 #define FALSE	0
151 #endif
152 #ifndef TRUE
153 #define	TRUE	1
154 #endif /* TRUE */
155 
156 #define USERNAMELEN	8
157 
158 #ifndef max
159 #define max(a, b)	(((a) > (b))? (a): (b))
160 #endif
161 #ifndef min
162 #define min(a, b)	(((a) < (b))? (a): (b))
163 #endif
164 
165 #ifdef NDEBUG
166 #define assert(x) if ((x) == 0) fprintf(stderr, "%s:%u: failed assertion\n", __FILE__, __LINE__)
167 #else
168 #include <assert.h>
169 #endif
170 
171 #ifdef Solaris
172 #ifdef __cplusplus
173 extern "C" {
174 #endif
175 int gettimeofday(struct timeval *tp, void * );
176 int gethostname(char *name, int namelen);
177 #ifdef __cplusplus
178 }
179 #endif
180 #endif
181 
182 #ifndef EXIT_SUCCESS
183 #define EXIT_SUCCESS 0
184 #endif /* EXIT_SUCCESS */
185 
186 #ifndef EXIT_FAILURE
187 #define EXIT_FAILURE 7
188 #endif /* EXIT_FAILURE */
189 
190 #endif /* _CONFIG_UNIX_H_ */
191 #endif /* WIN32 */
192