1 /* 2 * Copyright (c) 1995 - 2000 Kungliga Tekniska H�gskolan 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * 3. Neither the name of the Institute nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 /* $Id: roken-common.h,v 1.27 2000/02/14 02:24:44 assar Exp $ */ 35 36 #ifndef __ROKEN_COMMON_H__ 37 #define __ROKEN_COMMON_H__ 38 39 #ifndef INADDR_NONE 40 #define INADDR_NONE 0xffffffff 41 #endif 42 43 #ifndef INADDR_LOOPBACK 44 #define INADDR_LOOPBACK 0x7f000001 45 #endif 46 47 #ifndef SOMAXCONN 48 #define SOMAXCONN 5 49 #endif 50 51 #ifndef STDIN_FILENO 52 #define STDIN_FILENO 0 53 #endif 54 55 #ifndef STDOUT_FILENO 56 #define STDOUT_FILENO 1 57 #endif 58 59 #ifndef STDERR_FILENO 60 #define STDERR_FILENO 2 61 #endif 62 63 #ifndef max 64 #define max(a,b) (((a)>(b))?(a):(b)) 65 #endif 66 67 #ifndef min 68 #define min(a,b) (((a)<(b))?(a):(b)) 69 #endif 70 71 #ifndef TRUE 72 #define TRUE 1 73 #endif 74 75 #ifndef FALSE 76 #define FALSE 0 77 #endif 78 79 #ifndef LOG_DAEMON 80 #define openlog(id,option,facility) openlog((id),(option)) 81 #define LOG_DAEMON 0 82 #endif 83 #ifndef LOG_ODELAY 84 #define LOG_ODELAY 0 85 #endif 86 #ifndef LOG_NDELAY 87 #define LOG_NDELAY 0x08 88 #endif 89 #ifndef LOG_CONS 90 #define LOG_CONS 0 91 #endif 92 #ifndef LOG_AUTH 93 #define LOG_AUTH 0 94 #endif 95 #ifndef LOG_AUTHPRIV 96 #define LOG_AUTHPRIV LOG_AUTH 97 #endif 98 99 #ifndef F_OK 100 #define F_OK 0 101 #endif 102 103 #ifndef O_ACCMODE 104 #define O_ACCMODE 003 105 #endif 106 107 #ifndef _PATH_DEV 108 #define _PATH_DEV "/dev/" 109 #endif 110 111 #ifndef _PATH_DEVNULL 112 #define _PATH_DEVNULL "/dev/null" 113 #endif 114 115 #ifndef _PATH_HEQUIV 116 #define _PATH_HEQUIV "/etc/hosts.equiv" 117 #endif 118 119 #ifndef MAXPATHLEN 120 #define MAXPATHLEN (1024+4) 121 #endif 122 123 #ifndef SIG_ERR 124 #define SIG_ERR ((RETSIGTYPE (*)())-1) 125 #endif 126 127 /* 128 * error code for getipnodeby{name,addr} 129 */ 130 131 #ifndef HOST_NOT_FOUND 132 #define HOST_NOT_FOUND 1 133 #endif 134 135 #ifndef TRY_AGAIN 136 #define TRY_AGAIN 2 137 #endif 138 139 #ifndef NO_RECOVERY 140 #define NO_RECOVERY 3 141 #endif 142 143 #ifndef NO_DATA 144 #define NO_DATA 4 145 #endif 146 147 #ifndef NO_ADDRESS 148 #define NO_ADDRESS NO_DATA 149 #endif 150 151 /* 152 * error code for getaddrinfo 153 */ 154 155 #ifndef EAI_NOERROR 156 #define EAI_NOERROR 0 /* no error */ 157 #endif 158 159 #ifndef EAI_ADDRFAMILY 160 161 #define EAI_ADDRFAMILY 1 /* address family for nodename not supported */ 162 #define EAI_AGAIN 2 /* temporary failure in name resolution */ 163 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 164 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 165 #define EAI_FAMILY 5 /* ai_family not supported */ 166 #define EAI_MEMORY 6 /* memory allocation failure */ 167 #define EAI_NODATA 7 /* no address associated with nodename */ 168 #define EAI_NONAME 8 /* nodename nor servname provided, or not known */ 169 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 170 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 171 #define EAI_SYSTEM 11 /* system error returned in errno */ 172 173 #endif /* EAI_ADDRFAMILY */ 174 175 /* flags for getaddrinfo() */ 176 177 #ifndef AI_PASSIVE 178 179 #define AI_PASSIVE 0x01 180 #define AI_CANONNAME 0x02 181 #define AI_NUMERICHOST 0x04 182 183 #endif /* AI_PASSIVE */ 184 185 /* flags for getnameinfo() */ 186 187 #ifndef NI_DGRAM 188 #define NI_DGRAM 0x01 189 #define NI_NAMEREQD 0x02 190 #define NI_NOFQDN 0x04 191 #define NI_NUMERICHOST 0x08 192 #define NI_NUMERICSERV 0x10 193 #endif 194 195 /* 196 * constants for getnameinfo 197 */ 198 199 #ifndef NI_MAXHOST 200 #define NI_MAXHOST 1025 201 #define NI_MAXSERV 32 202 #endif 203 204 /* 205 * constants for inet_ntop 206 */ 207 208 #ifndef INET_ADDRSTRLEN 209 #define INET_ADDRSTRLEN 16 210 #endif 211 212 #ifndef INET6_ADDRSTRLEN 213 #define INET6_ADDRSTRLEN 46 214 #endif 215 216 /* 217 * for shutdown(2) 218 */ 219 220 #ifndef SHUT_RD 221 #define SHUT_RD 0 222 #endif 223 224 #ifndef SHUT_WR 225 #define SHUT_WR 1 226 #endif 227 228 #ifndef SHUT_RDWR 229 #define SHUT_RDWR 2 230 #endif 231 232 #ifndef HAVE___ATTRIBUTE__ 233 #define __attribute__(x) 234 #endif 235 236 #if IRIX != 4 /* fix for compiler bug */ 237 #ifdef RETSIGTYPE 238 typedef RETSIGTYPE (*SigAction)(/* int??? */); 239 SigAction signal(int iSig, SigAction pAction); /* BSD compatible */ 240 #endif 241 #endif 242 243 int ROKEN_LIB_FUNCTION simple_execve(const char*, char*const[], char*const[]); 244 int ROKEN_LIB_FUNCTION simple_execvp(const char*, char *const[]); 245 int ROKEN_LIB_FUNCTION simple_execlp(const char*, ...); 246 int ROKEN_LIB_FUNCTION simple_execle(const char*, ...); 247 248 void ROKEN_LIB_FUNCTION print_version(const char *); 249 250 void *ROKEN_LIB_FUNCTION emalloc (size_t); 251 void *ROKEN_LIB_FUNCTION erealloc (void *, size_t); 252 char *ROKEN_LIB_FUNCTION estrdup (const char *); 253 254 ssize_t ROKEN_LIB_FUNCTION eread (int fd, void *buf, size_t nbytes); 255 ssize_t ROKEN_LIB_FUNCTION ewrite (int fd, const void *buf, size_t nbytes); 256 257 void 258 socket_set_address_and_port (struct sockaddr *sa, const void *ptr, int port); 259 260 size_t 261 socket_addr_size (const struct sockaddr *sa); 262 263 void 264 socket_set_any (struct sockaddr *sa, int af); 265 266 size_t 267 socket_sockaddr_size (const struct sockaddr *sa); 268 269 void * 270 socket_get_address (struct sockaddr *sa); 271 272 int 273 socket_get_port (const struct sockaddr *sa); 274 275 void 276 socket_set_port (struct sockaddr *sa, int port); 277 278 void 279 socket_set_debug (int sock); 280 281 void 282 socket_set_tos (int sock, int tos); 283 284 void 285 socket_set_reuseaddr (int sock, int val); 286 287 char ** 288 vstrcollect(va_list *ap); 289 290 char ** 291 strcollect(char *first, ...); 292 293 294 #endif /* __ROKEN_COMMON_H__ */ 295