fixes init script for non ipv6 enabled systems #472755
[packages/xinetd.git] / xinetd / defs.h
1 /*
2  * (c) Copyright 1992 by Panagiotis Tsirigotis
3  * (c) Sections Copyright 1998-2001 by Rob Braun
4  * All rights reserved.  The file named COPYRIGHT specifies the terms 
5  * and conditions for redistribution.
6  */
7
8 #ifndef DEFS_H
9 #define DEFS_H
10
11 /*
12  * $Id: defs.h,v 1.3 2005/03/29 15:50:34 bbraun Exp $
13  */
14
15
16 #include "config.h"
17 #include <memory.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22
23 union xsockaddr {
24    struct sockaddr     sa;
25    struct sockaddr_in  sa_in;
26    struct sockaddr_in6 sa_in6;
27    char                pad[128];
28 };
29
30 #ifndef FALSE
31 #define FALSE                           0
32 #define TRUE                            1
33 #endif
34
35 #define NUL                             '\0'
36
37 #define ES_NOMEM                        "out of memory"
38
39 #define INT_NULL                        ((int *)0)
40 #define CHAR_NULL                       ((char *)0)
41 #define VOID_NULL                       ((void *)0)
42 #define FD_SET_NULL                     ((fd_set *)0)
43 #define RUSAGE_NULL                     ((struct rusage *)0)
44 #define TIMEVAL_NULL                    ((struct timeval *)0)
45
46 #define EQ( s1, s2 )          ( strcasecmp( s1, s2 ) == 0 )
47 #define CLEAR( x )            (void) memset( (char *)&(x), 0, sizeof( x ) )
48 /* Apparently, some tcp wrapper header files export an SA definition.
49  * make sure we use ours instead of some other one.
50  */
51 #undef SA
52
53 #define SA( p )               ( (struct sockaddr *) (p) )
54 #define SAIN( p )             ( (struct sockaddr_in *) (p) )
55 #define SAIN6( p )            ( (struct sockaddr_in6 *) (p) )
56 #define NEW( type )           (type *) malloc( sizeof( type ) )
57 #define FREE( p )             (void) free( (char *)(p) )
58
59 /*
60  * Value for unlimited server instances
61  */
62 #define UNLIMITED                  (-1)
63
64 /*
65  * We pass to the child the descriptors 0..MAX_PASS_FD
66  */
67 #define MAX_PASS_FD                2
68
69 /*
70  * Service port for the identification service
71  */
72 #define IDENTITY_SERVICE_PORT      113
73
74 /*
75  * This is the signal sent to interceptor processes to tell them
76  * to stop intercepting
77  */
78 #define INTERCEPT_SIG              SIGUSR1
79
80 /*
81  * This is how many descriptors we reserve for ourselves:
82  *
83  *      3    for stdin, stdout, stderr
84  *      1    for syslog/debug
85  *
86  * For the rest we just need to reserve the maximum of each category.
87  *
88  *   1    for doing accepts
89  *   1    for registering rpc services (initialization phase)
90  *   4    for reading the configuration file during reconfiguration
91  *      1 for the configuration file
92  *      1 for /etc/passwd
93  *      1 for /etc/group
94  *      1 for /etc/services, /etc/protocols, /etc/rpc
95  *      NOTE: We need only 1 descriptor for the last 3 files because
96  *         the functions get{serv,proto,rpc}byname close the
97  *         respective files after accessing them.
98  *      1    for dumping the internal state
99  *      1   for talking to the portmapper (reconfiguration phase)
100  *      1   for doing identification
101  *
102  * NOTE: we assume that the socket used for pmap_{set,unset} is closed
103  *      after the operation is completed. If it stays open, then we
104  *      need to increase DESCRIPTORS_RESERVED.
105  */
106 #define DESCRIPTORS_RESERVED         8
107
108 /*
109  * Used for listen(2)
110  */
111 #define LISTEN_BACKLOG               64
112
113 /*
114  * When explicit values are given for enum's, that is because the structures 
115  * that the enum's are in may be initialized by a memory clear operation.
116  */
117
118 typedef enum { FAILED = 0, OK } status_e ;
119 typedef enum { NO = 0, YES } boolean_e ;
120
121 /*
122  * Possible outcomes of an identification attempt
123  */
124 typedef enum
125    {
126       IDR_OK,
127       IDR_NOSERVER,
128       IDR_TIMEDOUT,
129       IDR_RESPERR,
130       IDR_BADRESP,
131       IDR_ERROR
132    } idresult_e ;
133
134 typedef int bool_int ;
135
136 typedef void (*voidfunc)() ;
137 typedef status_e (*statfunc)() ;
138
139
140 /*
141  * A name-value list is exactly what its name says.
142  * The functions nv_get_name() and nv_get_value() return a pointer to
143  * the entry with the specified value or name respectively.
144  * The list ends when an antry with a NULL name is encountered.
145  * The value field of that entry is treated in a special manner: if it
146  * is non-zero, it is assumed that there exists one more entry whose
147  * name field will be returned by the nv_get_name function if it can't
148  * find an entry whose value field is equal to its 2nd parameter.
149  * If the value field of the NULL entry is 0, then nv_get_name() will
150  * return NULL.
151  */
152 struct name_value
153 {
154    const char   *name ;
155    int          value ;
156 } ;
157
158 struct protocol_name_value
159 {
160    char   *name ;
161    int    value ;
162 } ;
163
164 struct debug
165 {
166    bool_int on ;
167    int fd ;
168 } ;
169
170 /* This is some forward prototypes to work out a couple
171  * circular dependencies in the data structures */
172 struct service;
173 struct server;
174 struct connection;
175 typedef struct connection connection_s ;
176
177
178 extern struct debug debug ;
179
180 #endif   /* DEFS_H */