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