xref: /freebsd/crypto/heimdal/lib/roken/roken-common.h (revision b52b9d56d4e96089873a75f9e29062eec19fabba)
1 /*
2  * Copyright (c) 1995 - 2001 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.48 2001/09/03 12:04:34 joda Exp $ */
35 
36 #ifndef __ROKEN_COMMON_H__
37 #define __ROKEN_COMMON_H__
38 
39 #ifdef __cplusplus
40 #define ROKEN_CPP_START	extern "C" {
41 #define ROKEN_CPP_END	}
42 #else
43 #define ROKEN_CPP_START
44 #define ROKEN_CPP_END
45 #endif
46 
47 #ifndef INADDR_NONE
48 #define INADDR_NONE 0xffffffff
49 #endif
50 
51 #ifndef INADDR_LOOPBACK
52 #define INADDR_LOOPBACK 0x7f000001
53 #endif
54 
55 #ifndef SOMAXCONN
56 #define SOMAXCONN 5
57 #endif
58 
59 #ifndef STDIN_FILENO
60 #define STDIN_FILENO 0
61 #endif
62 
63 #ifndef STDOUT_FILENO
64 #define STDOUT_FILENO 1
65 #endif
66 
67 #ifndef STDERR_FILENO
68 #define STDERR_FILENO 2
69 #endif
70 
71 #ifndef max
72 #define max(a,b) (((a)>(b))?(a):(b))
73 #endif
74 
75 #ifndef min
76 #define min(a,b) (((a)<(b))?(a):(b))
77 #endif
78 
79 #ifndef TRUE
80 #define TRUE 1
81 #endif
82 
83 #ifndef FALSE
84 #define FALSE 0
85 #endif
86 
87 #ifndef LOG_DAEMON
88 #define openlog(id,option,facility) openlog((id),(option))
89 #define	LOG_DAEMON	0
90 #endif
91 #ifndef LOG_ODELAY
92 #define LOG_ODELAY 0
93 #endif
94 #ifndef LOG_NDELAY
95 #define LOG_NDELAY 0x08
96 #endif
97 #ifndef LOG_CONS
98 #define LOG_CONS 0
99 #endif
100 #ifndef LOG_AUTH
101 #define LOG_AUTH 0
102 #endif
103 #ifndef LOG_AUTHPRIV
104 #define LOG_AUTHPRIV LOG_AUTH
105 #endif
106 
107 #ifndef F_OK
108 #define F_OK 0
109 #endif
110 
111 #ifndef O_ACCMODE
112 #define O_ACCMODE	003
113 #endif
114 
115 #ifndef _PATH_DEV
116 #define _PATH_DEV "/dev/"
117 #endif
118 
119 #ifndef _PATH_DEVNULL
120 #define _PATH_DEVNULL "/dev/null"
121 #endif
122 
123 #ifndef _PATH_HEQUIV
124 #define _PATH_HEQUIV "/etc/hosts.equiv"
125 #endif
126 
127 #ifndef _PATH_VARRUN
128 #define _PATH_VARRUN "/var/run/"
129 #endif
130 
131 #ifndef _PATH_BSHELL
132 #define _PATH_BSHELL "/bin/sh"
133 #endif
134 
135 #ifndef MAXPATHLEN
136 #define MAXPATHLEN (1024+4)
137 #endif
138 
139 #ifndef SIG_ERR
140 #define SIG_ERR ((RETSIGTYPE (*)(int))-1)
141 #endif
142 
143 /*
144  * error code for getipnodeby{name,addr}
145  */
146 
147 #ifndef HOST_NOT_FOUND
148 #define HOST_NOT_FOUND 1
149 #endif
150 
151 #ifndef TRY_AGAIN
152 #define TRY_AGAIN 2
153 #endif
154 
155 #ifndef NO_RECOVERY
156 #define NO_RECOVERY 3
157 #endif
158 
159 #ifndef NO_DATA
160 #define NO_DATA 4
161 #endif
162 
163 #ifndef NO_ADDRESS
164 #define NO_ADDRESS NO_DATA
165 #endif
166 
167 /*
168  * error code for getaddrinfo
169  */
170 
171 #ifndef EAI_NOERROR
172 #define EAI_NOERROR	0	/* no error */
173 #endif
174 
175 #ifndef EAI_ADDRFAMILY
176 
177 #define EAI_ADDRFAMILY	1	/* address family for nodename not supported */
178 #define EAI_AGAIN	2	/* temporary failure in name resolution */
179 #define EAI_BADFLAGS	3	/* invalid value for ai_flags */
180 #define EAI_FAIL	4	/* non-recoverable failure in name resolution */
181 #define EAI_FAMILY	5	/* ai_family not supported */
182 #define EAI_MEMORY	6	/* memory allocation failure */
183 #define EAI_NODATA	7	/* no address associated with nodename */
184 #define EAI_NONAME	8	/* nodename nor servname provided, or not known */
185 #define EAI_SERVICE	9	/* servname not supported for ai_socktype */
186 #define EAI_SOCKTYPE   10	/* ai_socktype not supported */
187 #define EAI_SYSTEM     11	/* system error returned in errno */
188 
189 #endif /* EAI_ADDRFAMILY */
190 
191 /* flags for getaddrinfo() */
192 
193 #ifndef AI_PASSIVE
194 
195 #define AI_PASSIVE	0x01
196 #define AI_CANONNAME	0x02
197 #define AI_NUMERICHOST	0x04
198 
199 #endif /* AI_PASSIVE */
200 
201 /* flags for getnameinfo() */
202 
203 #ifndef NI_DGRAM
204 #define NI_DGRAM	0x01
205 #define NI_NAMEREQD	0x02
206 #define NI_NOFQDN	0x04
207 #define NI_NUMERICHOST	0x08
208 #define NI_NUMERICSERV	0x10
209 #endif
210 
211 /*
212  * constants for getnameinfo
213  */
214 
215 #ifndef NI_MAXHOST
216 #define NI_MAXHOST  1025
217 #define NI_MAXSERV    32
218 #endif
219 
220 /*
221  * constants for inet_ntop
222  */
223 
224 #ifndef INET_ADDRSTRLEN
225 #define INET_ADDRSTRLEN    16
226 #endif
227 
228 #ifndef INET6_ADDRSTRLEN
229 #define INET6_ADDRSTRLEN   46
230 #endif
231 
232 /*
233  * for shutdown(2)
234  */
235 
236 #ifndef SHUT_RD
237 #define SHUT_RD 0
238 #endif
239 
240 #ifndef SHUT_WR
241 #define SHUT_WR 1
242 #endif
243 
244 #ifndef SHUT_RDWR
245 #define SHUT_RDWR 2
246 #endif
247 
248 #ifndef HAVE___ATTRIBUTE__
249 #define __attribute__(x)
250 #endif
251 
252 ROKEN_CPP_START
253 
254 #if IRIX != 4 /* fix for compiler bug */
255 #ifdef RETSIGTYPE
256 typedef RETSIGTYPE (*SigAction)(int);
257 SigAction signal(int iSig, SigAction pAction); /* BSD compatible */
258 #endif
259 #endif
260 
261 int ROKEN_LIB_FUNCTION simple_execve(const char*, char*const[], char*const[]);
262 int ROKEN_LIB_FUNCTION simple_execvp(const char*, char *const[]);
263 int ROKEN_LIB_FUNCTION simple_execlp(const char*, ...);
264 int ROKEN_LIB_FUNCTION simple_execle(const char*, ...);
265 int ROKEN_LIB_FUNCTION simple_execl(const char *file, ...);
266 
267 int ROKEN_LIB_FUNCTION wait_for_process(pid_t);
268 int ROKEN_LIB_FUNCTION pipe_execv(FILE**, FILE**, FILE**, const char*, ...);
269 
270 void ROKEN_LIB_FUNCTION print_version(const char *);
271 
272 ssize_t ROKEN_LIB_FUNCTION eread (int fd, void *buf, size_t nbytes);
273 ssize_t ROKEN_LIB_FUNCTION ewrite (int fd, const void *buf, size_t nbytes);
274 
275 struct hostent;
276 
277 const char *
278 hostent_find_fqdn (const struct hostent *he);
279 
280 void
281 esetenv(const char *var, const char *val, int rewrite);
282 
283 void
284 socket_set_address_and_port (struct sockaddr *sa, const void *ptr, int port);
285 
286 size_t
287 socket_addr_size (const struct sockaddr *sa);
288 
289 void
290 socket_set_any (struct sockaddr *sa, int af);
291 
292 size_t
293 socket_sockaddr_size (const struct sockaddr *sa);
294 
295 void *
296 socket_get_address (struct sockaddr *sa);
297 
298 int
299 socket_get_port (const struct sockaddr *sa);
300 
301 void
302 socket_set_port (struct sockaddr *sa, int port);
303 
304 void
305 socket_set_portrange (int sock, int restr, int af);
306 
307 void
308 socket_set_debug (int sock);
309 
310 void
311 socket_set_tos (int sock, int tos);
312 
313 void
314 socket_set_reuseaddr (int sock, int val);
315 
316 char **
317 vstrcollect(va_list *ap);
318 
319 char **
320 strcollect(char *first, ...);
321 
322 void timevalfix(struct timeval *t1);
323 void timevaladd(struct timeval *t1, const struct timeval *t2);
324 void timevalsub(struct timeval *t1, const struct timeval *t2);
325 
326 char *pid_file_write (const char *progname);
327 void pid_file_delete (char **);
328 
329 int
330 read_environment(const char *file, char ***env);
331 
332 void warnerr(int doerrno, const char *fmt, va_list ap)
333     __attribute__ ((format (printf, 2, 0)));
334 
335 ROKEN_CPP_END
336 
337 #endif /* __ROKEN_COMMON_H__ */
338