fgms 0.11.8
The
FlightGear MultiPlayer Server
project
fgt_common.h
Go to the documentation of this file.
1 /*
2  * common.h - common headers, based on Richard Stevens' book
3  *
4  * Author: Gabor Toth <tgbp@freemail.hu>
5  * License: GPL
6  *
7  * $Log: common.h,v $
8  * Revision 1.2 2006/05/10 21:22:34 koversrac
9  * Comment with author and license has been added.
10  *
11  */
12 
13 #ifndef __common_h
14 #define __common_h
15 
16 #include "fgt_config.h"
17 #include "fgt_error.h"
18 
19 #ifndef _MSC_VER
20 #include <sys/time.h>
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <sys/stat.h>
24 #include <sys/uio.h>
25 #include <sys/un.h>
26 #include <sys/wait.h>
27 #include <time.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <netdb.h>
33 #include <signal.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <stdarg.h>
37 #include <syslog.h>
38 #include <string.h>
39 #include <unistd.h>
40 #endif // _MSC_VER
41 
42 #ifdef HAVE_SYS_SELECT_H
43 #include <sys/select.h>
44 #endif
45 
46 #ifdef HAVE_SYS_SYSCTL_H
47 #include <sys/sysctl.h>
48 #endif
49 
50 #ifdef HAVE_POLL_H
51 #include <poll.h>
52 #endif
53 
54 #ifdef HAVE_SYS_EVENT_H
55 #include <sys/event.h>
56 #endif
57 
58 #ifdef HAVE_STRINGS_H
59 #include <strings.h>
60 #endif
61 
62 #ifdef HAVE_SYS_IOCTL_H
63 #include <sys/ioctl.h>
64 #endif
65 
66 #ifdef HAVE_SYS_FILIO_H
67 #include <sys/filio.h>
68 #endif
69 
70 #ifdef HAVE_SYS_SOCKIO_H
71 #include <sys/sockio.h>
72 #endif
73 
74 #ifdef HAVE_PTHREAD_H
75 #include <pthread.h>
76 #endif
77 
78 #ifdef HAVE_NET_IF_DL_H
79 #include <net/if_dl.h>
80 #endif
81 
82 #ifdef HAVE_NETINET_SCTP_H
83 #include <netinet/sctp.h>
84 #endif
85 
86 
87 /* OSF/1 actually disables recv() and send() in <sys/socket.h> */
88 #ifdef __osf__
89 #undef recv
90 #undef send
91 #define recv(a,b,c,d) recvfrom(a,b,c,d,0,0)
92 #define send(a,b,c,d) sendto(a,b,c,d,0,0)
93 #endif
94 
95 #ifndef INADDR_NONE
96 #define INADDR_NONE 0xffffffff /* should have been in <netinet/in.h> */
97 #endif
98 
99 #ifndef SHUT_RD /* these three POSIX names are new */
100 #define SHUT_RD 0 /* shutdown for reading */
101 #define SHUT_WR 1 /* shutdown for writing */
102 #define SHUT_RDWR 2 /* shutdown for reading and writing */
103 #endif
104 
105 #ifndef INET_ADDRSTRLEN
106 #define INET_ADDRSTRLEN 16 /* "ddd.ddd.ddd.ddd\0"
107  1234567890123456 */
108 #endif
109 
110 /* Define following even if IPv6 not supported, so we can always allocate
111  an adequately sized buffer without #ifdefs in the code. */
112 #ifndef INET6_ADDRSTRLEN
113 #define INET6_ADDRSTRLEN 46 /* max size of IPv6 address string:
114  "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx" or
115  "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:ddd.ddd.ddd.ddd\0"
116  1234567890123456789012345678901234567890123456 */
117 #endif
118 
119 /* Define bzero() as a macro if it's not in standard C library. */
120 #ifndef HAVE_BZERO
121 #define bzero(ptr,n) memset (ptr, 0, n)
122 #endif
123 
124 /* Older resolvers do not have gethostbyname2() */
125 #ifndef HAVE_GETHOSTBYNAME2
126 #define gethostbyname2(host,family) gethostbyname((host))
127 #endif
128 
129 /* The structure returned by recvfrom_flags() */
130 struct unp_in_pktinfo {
131  struct in_addr ipi_addr; /* dst IPv4 address */
132  int ipi_ifindex; /* received interface index */
133 };
134 
135 /* We need the newer CMSG_LEN() and CMSG_SPACE() macros, but few
136  implementations support them today. These two macros really need
137  an ALIGN() macro, but each implementation does this differently. */
138 #ifndef CMSG_LEN
139 #define CMSG_LEN(size) (sizeof(struct cmsghdr) + (size))
140 #endif
141 #ifndef CMSG_SPACE
142 #define CMSG_SPACE(size) (sizeof(struct cmsghdr) + (size))
143 #endif
144 
145 /* POSIX requires the SUN_LEN() macro, but not all implementations define
146  it (yet). Note that this 4.4BSD macro works regardless whether there is
147  a length field or not. */
148 #ifndef SUN_LEN
149 # define SUN_LEN (su) \
150  (sizeof (*(su)) - sizeof ((su)->sun_path) + strlen((su)->sun_path))
151 #endif
152 
153 /* POSIX renames "Unix domain" as "local IPC."
154  Not all systems define AF_LOCAL and PF_LOCAL (yet). */
155 #ifndef AF_LOCAL
156 #define AF_LOCAL AF_UNIX
157 #endif
158 #ifndef PF_LOCAL
159 #define PF_LOCAL PF_UNIX
160 #endif
161 
162 /* POSIX requires that an #include of <poll.h> define INFTIM, but many
163  systems still define it in <sys/stropts.h>. We don't want to include
164  all the STREAMS stuff if it's not needed, so we just define INFTIM here.
165  This is the standard value, but there's no guarantee it is -1. */
166 #ifndef INFTIM
167 #define INFTIM (-1) /* infinite poll timeout */
168 #ifdef HAVE_POLL_H
169 #define INFTIM_UNPH /* tell unpxti.h we defined it */
170 #endif
171 #endif
172 
173 /* Following could be derived from SOMAXCONN in <sys/socket.h>, but many
174  kernels still #define it as 5, while actually supporting many more */
175 #define LISTENQ 1024 /* 2nd argument to listen () */
176 
177 /* Miscellaneous constants */
178 #define MAXLINE 4096 /* max text line length */
179 #define MSGMAXLINE 512 /*Maximun character in msg: 511. char in [512] = '\0'*/
180 #define BUFFSIZE 8192 /* buffer size for reads and writes */
181 
182 /* Define some port number that can be used for our examples */
183 #define SERV_PORT 9877 /* TCP and UDP */
184 #define SERV_PORT_STR "9877" /* TCP and UDP */
185 #define UNIXSTR_PATH "/tmp/unix.str" /* Unix domain stream */
186 #define UNIXDG_PATH "/tmp/unix.dg" /* Unix domain datagram */
187 
188 /* Following shortens all the typecasts of pointer arguments: */
189 #define SA struct sockaddr
190 #define HAVE_STRUCT_SOCKADDR_STORAGE
191 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
192 
193 /*
194  * RFC 3493: protocol-independent placeholder for socket addresses
195  */
196 
197 #define __SS_MAXSIZE 128
198 #define __SS_ALIGNSIZE (sizeof(int64_t))
199 #ifdef HAVE_SOCKADDR_SA_LEN
200 #define __SS_PAD1SIZE (__SS_ALIGNSIZE - sizeof(u_char) - sizeof(sa_family_t))
201 #else
202 #define __SS_PAD1SIZE (__SS_ALIGNSIZE - sizeof(sa_family_t))
203 #endif
204 #define __SS_PAD2SIZE (__SS_MAXSIZE - 2*__SS_ALIGNSIZE)
205 struct sockaddr_storage {
206 
207 #ifdef HAVE_SOCKADDR_SA_LEN
208  u_char ss_len;
209 #endif
210  sa_family_t ss_family;
211  char __ss_pad1[__SS_PAD1SIZE];
212  int64_t __ss_align;
213  char __ss_pad2[__SS_PAD2SIZE];
214 };
215 #endif
216 
217 #define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
218  /* default file access permissions for new files */
219 #define DIR_MODE (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
220  /* default permissions for new directories */
221 
222 typedef void Sigfunc (int); /* for signal handlers */
223 
224 #ifdef _MSC_VER
225 // #include <simgear/misc/stdint.hxx>
226 typedef signed char int8_t;
227 typedef signed short int16_t;
228 typedef signed int int32_t;
229 typedef signed __int64 int64_t;
230 typedef unsigned char uint8_t;
231 typedef unsigned short uint16_t;
232 typedef unsigned int uint32_t;
233 typedef unsigned __int64 uint64_t;
234 
235 #if !defined(socklen_t)
236 #define socklen_t int
237 #endif
238  #define SWRITE(a,b,c) send(a,b,c,0)
239  #define SREAD(a,b,c) recv(a,b,c,0)
240  #define SCLOSE closesocket
241  #define SERROR(a) (a == SOCKET_ERROR)
242 #else // !_MSC_VER
243 #define min(a,b) ((a) < (b) ? (a) : (b))
244 #define max(a,b) ((a) > (b) ? (a) : (b))
245  #define SWRITE write
246  #define SREAD read
247  #define SCLOSE close
248  #define SERROR(a) (a < 0)
249 #endif // _MSC_VER y/n
250 
251 #ifndef HAVE_IF_NAMEINDEX_STRUCT
252 struct if_nameindex {
253  unsigned int if_index; /* 1, 2, ... */
254  char *if_name; /* null-terminated name: "le0", ... */
255 };
256 #endif
257 
258 #endif // #ifndef __common_h
259 /* eof - common.h */
260 
char * if_name
Definition: fg_common.hxx:208
void Sigfunc(int)
Definition: fgt_common.h:222
unsigned int if_index
Definition: fg_common.hxx:207