Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 1 | #ifndef _DEFINES_H |
| 2 | #define _DEFINES_H |
| 3 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 4 | /* Necessary headers */ |
| 5 | |
Damien Miller | 1c67c99 | 2000-03-14 10:16:34 +1100 | [diff] [blame] | 6 | #include <sys/types.h> /* For [u]intxx_t */ |
| 7 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 8 | #include <sys/socket.h> /* For SHUT_XXXX */ |
| 9 | |
Damien Miller | fc0b11b | 2000-05-02 00:03:55 +1000 | [diff] [blame] | 10 | # include <netinet/in_systm.h> /* For typedefs */ |
Damien Miller | 1c67c99 | 2000-03-14 10:16:34 +1100 | [diff] [blame] | 11 | #include <netinet/in.h> /* For IPv6 macros */ |
Damien Miller | bc7c7cc | 2000-04-08 17:48:56 +1000 | [diff] [blame] | 12 | #include <netinet/ip.h> /* For IPTOS macros */ |
| 13 | |
Damien Miller | b29ea91 | 2000-01-15 14:12:03 +1100 | [diff] [blame] | 14 | #ifdef HAVE_SYS_BITYPES_H |
| 15 | # include <sys/bitypes.h> /* For u_intXX_t */ |
| 16 | #endif |
| 17 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 18 | #ifdef HAVE_PATHS_H |
| 19 | # include <paths.h> /* For _PATH_XXX */ |
| 20 | #endif |
| 21 | |
| 22 | #ifdef HAVE_UTMP_H |
| 23 | # include <utmp.h> /* For _PATH_XXX */ |
| 24 | #endif |
| 25 | |
| 26 | #if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) |
| 27 | # include <utmpx.h> /* For _PATH_XXX */ |
| 28 | #endif |
| 29 | |
| 30 | #ifdef HAVE_SYS_TIME_H |
| 31 | # include <sys/time.h> /* For timersub */ |
| 32 | #endif |
| 33 | |
| 34 | #ifdef HAVE_MAILLOCK_H |
Damien Miller | beb4ba5 | 1999-12-28 15:09:35 +1100 | [diff] [blame] | 35 | # include <maillock.h> /* For _PATH_MAILDIR */ |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 36 | #endif |
| 37 | |
Damien Miller | beb4ba5 | 1999-12-28 15:09:35 +1100 | [diff] [blame] | 38 | #ifdef HAVE_SYS_CDEFS_H |
| 39 | # include <sys/cdefs.h> /* For __P() */ |
| 40 | #endif |
| 41 | |
Damien Miller | ee1c0b3 | 2000-01-21 00:18:15 +1100 | [diff] [blame] | 42 | #ifdef HAVE_SYS_SYSMACROS_H |
| 43 | # include <sys/sysmacros.h> /* For MIN, MAX, etc */ |
| 44 | #endif |
| 45 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 46 | /* Constants */ |
| 47 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 48 | #ifndef SHUT_RDWR |
| 49 | enum |
| 50 | { |
| 51 | SHUT_RD = 0, /* No more receptions. */ |
| 52 | SHUT_WR, /* No more transmissions. */ |
| 53 | SHUT_RDWR /* No more receptions or transmissions. */ |
| 54 | }; |
| 55 | # define SHUT_RD SHUT_RD |
| 56 | # define SHUT_WR SHUT_WR |
| 57 | # define SHUT_RDWR SHUT_RDWR |
| 58 | #endif |
| 59 | |
Damien Miller | bc7c7cc | 2000-04-08 17:48:56 +1000 | [diff] [blame] | 60 | #ifndef IPTOS_LOWDELAY |
| 61 | # define IPTOS_LOWDELAY 0x10 |
| 62 | # define IPTOS_THROUGHPUT 0x08 |
| 63 | # define IPTOS_RELIABILITY 0x04 |
| 64 | # define IPTOS_LOWCOST 0x02 |
| 65 | # define IPTOS_MINCOST IPTOS_LOWCOST |
| 66 | #endif /* IPTOS_LOWDELAY */ |
| 67 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 68 | /* Types */ |
| 69 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 70 | /* If sys/types.h does not supply intXX_t, supply them ourselves */ |
| 71 | /* (or die trying) */ |
| 72 | #ifndef HAVE_INTXX_T |
Damien Miller | e0f4574 | 2000-01-18 09:12:06 +1100 | [diff] [blame] | 73 | # if (SIZEOF_CHAR == 1) |
| 74 | typedef char int8_t; |
| 75 | # else |
| 76 | # error "8 bit int type not found." |
| 77 | # endif |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 78 | # if (SIZEOF_SHORT_INT == 2) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 79 | typedef short int int16_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 80 | # else |
| 81 | # error "16 bit int type not found." |
| 82 | # endif |
| 83 | # if (SIZEOF_INT == 4) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 84 | typedef int int32_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 85 | # else |
| 86 | # error "32 bit int type not found." |
| 87 | # endif |
Damien Miller | 70494d1 | 2000-04-03 15:57:06 +1000 | [diff] [blame] | 88 | /* |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 89 | # if (SIZEOF_LONG_INT == 8) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 90 | typedef long int int64_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 91 | # else |
| 92 | # if (SIZEOF_LONG_LONG_INT == 8) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 93 | typedef long long int int64_t; |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 94 | # define HAVE_INTXX_T 1 |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 95 | # else |
| 96 | # error "64 bit int type not found." |
| 97 | # endif |
| 98 | # endif |
Damien Miller | 70494d1 | 2000-04-03 15:57:06 +1000 | [diff] [blame] | 99 | */ |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 100 | #endif |
| 101 | |
| 102 | /* If sys/types.h does not supply u_intXX_t, supply them ourselves */ |
| 103 | #ifndef HAVE_U_INTXX_T |
| 104 | # ifdef HAVE_UINTXX_T |
Damien Miller | e0f4574 | 2000-01-18 09:12:06 +1100 | [diff] [blame] | 105 | typedef uint8_t u_int8_t; |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 106 | typedef uint16_t u_int16_t; |
| 107 | typedef uint32_t u_int32_t; |
Damien Miller | 70494d1 | 2000-04-03 15:57:06 +1000 | [diff] [blame] | 108 | /* |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 109 | typedef uint64_t u_int64_t; |
Damien Miller | 70494d1 | 2000-04-03 15:57:06 +1000 | [diff] [blame] | 110 | */ |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 111 | # define HAVE_U_INTXX_T 1 |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 112 | # else |
Damien Miller | e0f4574 | 2000-01-18 09:12:06 +1100 | [diff] [blame] | 113 | # if (SIZEOF_CHAR == 1) |
| 114 | typedef unsigned char u_int8_t; |
| 115 | # else |
| 116 | # error "8 bit int type not found." |
| 117 | # endif |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 118 | # if (SIZEOF_SHORT_INT == 2) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 119 | typedef unsigned short int u_int16_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 120 | # else |
| 121 | # error "16 bit int type not found." |
| 122 | # endif |
| 123 | # if (SIZEOF_INT == 4) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 124 | typedef unsigned int u_int32_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 125 | # else |
| 126 | # error "32 bit int type not found." |
| 127 | # endif |
Damien Miller | 70494d1 | 2000-04-03 15:57:06 +1000 | [diff] [blame] | 128 | /* |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 129 | # if (SIZEOF_LONG_INT == 8) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 130 | typedef unsigned long int u_int64_t; |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 131 | # else |
| 132 | # if (SIZEOF_LONG_LONG_INT == 8) |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 133 | typedef unsigned long long int u_int64_t; |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 134 | # define HAVE_U_INTXX_T 1 |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 135 | # else |
| 136 | # error "64 bit int type not found." |
| 137 | # endif |
| 138 | # endif |
Damien Miller | 70494d1 | 2000-04-03 15:57:06 +1000 | [diff] [blame] | 139 | */ |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 140 | # endif |
| 141 | #endif |
| 142 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 143 | #ifndef HAVE_SOCKLEN_T |
| 144 | typedef unsigned int socklen_t; |
Damien Miller | b2532b3 | 1999-12-31 09:18:12 +1100 | [diff] [blame] | 145 | # define HAVE_SOCKLEN_T |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 146 | #endif /* HAVE_SOCKLEN_T */ |
| 147 | |
Damien Miller | 9505851 | 1999-12-29 10:36:45 +1100 | [diff] [blame] | 148 | #ifndef HAVE_SIZE_T |
| 149 | typedef unsigned int size_t; |
Damien Miller | b2532b3 | 1999-12-31 09:18:12 +1100 | [diff] [blame] | 150 | # define HAVE_SIZE_T |
Damien Miller | 9505851 | 1999-12-29 10:36:45 +1100 | [diff] [blame] | 151 | #endif /* HAVE_SIZE_T */ |
| 152 | |
Damien Miller | 615f939 | 2000-05-17 22:53:33 +1000 | [diff] [blame^] | 153 | #ifndef HAVE_SSIZE_T |
| 154 | typedef int ssize_t; |
| 155 | # define HAVE_SSIZE_T |
| 156 | #endif /* HAVE_SSIZE_T */ |
| 157 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 158 | #if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS) |
| 159 | # define ss_family __ss_family |
| 160 | #endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */ |
| 161 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 162 | /* Paths */ |
| 163 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 164 | /* If _PATH_LASTLOG is not defined by system headers, set it to the */ |
| 165 | /* lastlog file detected by autoconf */ |
| 166 | #ifndef _PATH_LASTLOG |
| 167 | # ifdef LASTLOG_LOCATION |
| 168 | # define _PATH_LASTLOG LASTLOG_LOCATION |
| 169 | # endif |
| 170 | #endif |
| 171 | |
| 172 | #ifndef _PATH_UTMP |
| 173 | # ifdef UTMP_FILE |
| 174 | # define _PATH_UTMP UTMP_FILE |
| 175 | # else |
| 176 | # define _PATH_UTMP "/var/adm/utmp" |
| 177 | # endif |
| 178 | #endif |
| 179 | |
| 180 | #ifndef _PATH_WTMP |
| 181 | # ifdef WTMP_FILE |
| 182 | # define _PATH_WTMP WTMP_FILE |
| 183 | # else |
| 184 | # define _PATH_WTMP "/var/adm/wtmp" |
| 185 | # endif |
| 186 | #endif |
| 187 | |
| 188 | #if defined(HAVE_UTMPX_H) && defined(USE_UTMPX) |
| 189 | # ifndef _PATH_UTMPX |
| 190 | # ifdef UTMPX_FILE |
| 191 | # define _PATH_UTMPX UTMPX_FILE |
| 192 | # else |
| 193 | # define _PATH_UTMPX "/var/adm/utmpx" |
| 194 | # endif |
| 195 | # endif |
| 196 | # ifndef _PATH_WTMPX |
| 197 | # ifdef WTMPX_FILE |
| 198 | # define _PATH_WTMPX WTMPX_FILE |
| 199 | # else |
| 200 | # define _PATH_WTMPX "/var/adm/wtmp" |
| 201 | # endif |
| 202 | # endif |
| 203 | #endif |
| 204 | |
| 205 | #ifndef _PATH_BSHELL |
| 206 | # define _PATH_BSHELL "/bin/sh" |
| 207 | #endif |
| 208 | |
| 209 | #ifdef USER_PATH |
| 210 | # ifdef _PATH_STDPATH |
| 211 | # undef _PATH_STDPATH |
| 212 | # endif |
| 213 | # define _PATH_STDPATH USER_PATH |
| 214 | #endif |
| 215 | |
| 216 | #ifndef _PATH_STDPATH |
| 217 | # define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" |
| 218 | #endif |
| 219 | |
| 220 | #ifndef _PATH_DEVNULL |
| 221 | # define _PATH_DEVNULL "/dev/null" |
| 222 | #endif |
| 223 | |
Damien Miller | 615f939 | 2000-05-17 22:53:33 +1000 | [diff] [blame^] | 224 | #ifndef MAIL_DIRECTORY |
| 225 | # define MAIL_DIRECTORY "/var/spool/mail" |
| 226 | #endif |
| 227 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 228 | #ifndef MAILDIR |
| 229 | # define MAILDIR MAIL_DIRECTORY |
| 230 | #endif |
| 231 | |
| 232 | #if !defined(_PATH_MAILDIR) && defined(MAILDIR) |
| 233 | # define _PATH_MAILDIR MAILDIR |
| 234 | #endif /* !defined(_PATH_MAILDIR) && defined(MAILDIR) */ |
| 235 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 236 | #ifndef _PATH_RSH |
| 237 | # ifdef RSH_PATH |
| 238 | # define _PATH_RSH RSH_PATH |
| 239 | # endif /* RSH_PATH */ |
| 240 | #endif /* _PATH_RSH */ |
| 241 | |
| 242 | /* Macros */ |
| 243 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 244 | #ifndef MAX |
| 245 | # define MAX(a,b) (((a)>(b))?(a):(b)) |
| 246 | # define MIN(a,b) (((a)<(b))?(a):(b)) |
| 247 | #endif |
| 248 | |
| 249 | #ifndef timersub |
| 250 | #define timersub(a, b, result) \ |
| 251 | do { \ |
| 252 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ |
| 253 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ |
| 254 | if ((result)->tv_usec < 0) { \ |
| 255 | --(result)->tv_sec; \ |
| 256 | (result)->tv_usec += 1000000; \ |
| 257 | } \ |
| 258 | } while (0) |
| 259 | #endif |
| 260 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 261 | #ifndef __P |
| 262 | # define __P(x) x |
| 263 | #endif |
| 264 | |
Damien Miller | 1c67c99 | 2000-03-14 10:16:34 +1100 | [diff] [blame] | 265 | #if !defined(IN6_IS_ADDR_V4MAPPED) |
| 266 | # define IN6_IS_ADDR_V4MAPPED(a) \ |
Damien Miller | db81959 | 2000-03-14 13:44:01 +1100 | [diff] [blame] | 267 | ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \ |
| 268 | (((u_int32_t *) (a))[2] == htonl (0xffff))) |
Damien Miller | 1c67c99 | 2000-03-14 10:16:34 +1100 | [diff] [blame] | 269 | #endif /* !defined(IN6_IS_ADDR_V4MAPPED) */ |
| 270 | |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 271 | #if !defined(__GNUC__) || (__GNUC__ < 2) |
Damien Miller | e0f4574 | 2000-01-18 09:12:06 +1100 | [diff] [blame] | 272 | # define __attribute__(x) |
Damien Miller | 5a3e683 | 1999-12-27 09:48:56 +1100 | [diff] [blame] | 273 | #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */ |
| 274 | |
Damien Miller | 74d0d4a | 1999-12-29 02:24:35 +1100 | [diff] [blame] | 275 | #if defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM) |
| 276 | # define USE_PAM |
| 277 | #endif /* defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM) */ |
| 278 | |
| 279 | /* Function replacement / compatibility hacks */ |
| 280 | |
| 281 | /* In older versions of libpam, pam_strerror takes a single argument */ |
| 282 | #ifdef HAVE_OLD_PAM |
| 283 | # define PAM_STRERROR(a,b) pam_strerror((b)) |
| 284 | #else |
| 285 | # define PAM_STRERROR(a,b) pam_strerror((a),(b)) |
| 286 | #endif |
| 287 | |
Damien Miller | eca71f8 | 2000-01-20 22:38:27 +1100 | [diff] [blame] | 288 | #if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO) |
| 289 | # undef HAVE_GETADDRINFO |
| 290 | #endif /* defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO) */ |
| 291 | |
Damien Miller | 615f939 | 2000-05-17 22:53:33 +1000 | [diff] [blame^] | 292 | #if !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) |
| 293 | # define memmove(s1, s2, n) bcopy((s2), (s1), (n)) |
| 294 | #endif /* !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) */ |
| 295 | |
Damien Miller | 6b85a7f | 2000-01-02 11:45:33 +1100 | [diff] [blame] | 296 | #endif /* _DEFINES_H */ |