fgms 0.11.8
The
FlightGear MultiPlayer Server
project
fg_common.hxx
Go to the documentation of this file.
1 #ifndef __common_hxx
2 #define __common_hxx
3 
4 #ifdef HAVE_CONFIG_H
5  #include "config.h"
6 #endif
7 
8 #ifndef _MSC_VER
9  #ifndef __FreeBSD__
10  #include "error.h"
11  #endif
12  #include <sys/time.h>
13  #include <sys/types.h>
14  #include <sys/socket.h>
15  #include <sys/stat.h>
16  #include <sys/uio.h>
17  #include <sys/un.h>
18  #include <sys/wait.h>
19  #include <time.h>
20  #include <netinet/in.h>
21  #include <arpa/inet.h>
22  #include <errno.h>
23  #include <fcntl.h>
24  #include <netdb.h>
25  #include <signal.h>
26  #include <stdio.h>
27  #include <stdlib.h>
28  #include <stdarg.h>
29  #include <syslog.h>
30  #include <string.h>
31  #include <unistd.h>
32  #include <sys/ipc.h>
33  #include <sys/msg.h>
34 #endif // !_MSC_VER
35 
36 #ifdef HAVE_SYS_SELECT_H
37  #include <sys/select.h>
38 #endif
39 
40 #ifdef HAVE_SYS_SYSCTL_H
41  #include <sys/sysctl.h>
42 #endif
43 
44 #ifdef HAVE_POLL_H
45  #include <poll.h>
46 #endif
47 
48 #ifdef HAVE_SYS_EVENT_H
49  #include <sys/event.h>
50 #endif
51 
52 #ifdef HAVE_STRINGS_H
53  #include <strings.h>
54 #endif
55 
56 #ifdef HAVE_SYS_IOCTL_H
57  #include <sys/ioctl.h>
58 #endif
59 
60 #ifdef HAVE_SYS_FILIO_H
61  #include <sys/filio.h>
62 #endif
63 
64 #ifdef HAVE_SYS_SOCKIO_H
65  #include <sys/sockio.h>
66 #endif
67 
68 #ifdef HAVE_PTHREAD_H
69  #include <pthread.h>
70 #endif
71 
72 #ifdef HAVE_NET_IF_DL_H
73  #include <net/if_dl.h>
74 #endif
75 
76 #ifdef HAVE_NETINET_SCTP_H
77  #include <netinet/sctp.h>
78 #endif
79 
80 #ifndef MSG_NOSIGNAL
81  #define MSG_NOSIGNAL 0
82 #endif
83 
84 /* OSF/1 actually disables recv() and send() in <sys/socket.h> */
85 #ifdef __osf__
86  #undef recv
87  #undef send
88  #define recv(a,b,c,d) recvfrom(a,b,c,d,0,0)
89  #define send(a,b,c,d) sendto(a,b,c,d,0,0)
90 #endif
91 
92 #ifndef INADDR_NONE
93  #define INADDR_NONE 0xffffffff /* should have been in <netinet/in.h> */
94 #endif
95 
96 #ifndef SHUT_RD /* these three POSIX names are new */
97  #define SHUT_RD 0 /* shutdown for reading */
98  #define SHUT_WR 1 /* shutdown for writing */
99  #define SHUT_RDWR 2 /* shutdown for reading and writing */
100 #endif
101 
102 #if 0
103 
104 #ifndef INET_ADDRSTRLEN
105  #define INET_ADDRSTRLEN 16 /* "ddd.ddd.ddd.ddd\0"
106  1234567890123456 */
107 #endif
108 
109 /* Define following even if IPv6 not supported, so we can always allocate
110  an adequately sized buffer without #ifdefs in the code. */
111 #ifndef INET6_ADDRSTRLEN
112 #define INET6_ADDRSTRLEN 46 /* max size of IPv6 address string:
113  "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx" or
114  "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:ddd.ddd.ddd.ddd\0"
115  1234567890123456789012345678901234567890123456 */
116 #endif
117 
118 #endif
119 
120 /* Define bzero() as a macro if it's not in standard C library. */
121 #ifndef HAVE_BZERO
122  #define bzero(ptr,n) memset (ptr, 0, n)
123 #endif
124 
125 /* Older resolvers do not have gethostbyname2() */
126 #ifndef HAVE_GETHOSTBYNAME2
127  #define gethostbyname2(host,family) gethostbyname((host))
128 #endif
129 
130 /* The structure returned by recvfrom_flags() */
131 struct unp_in_pktinfo {
132  struct in_addr ipi_addr; /* dst IPv4 address */
133  int ipi_ifindex; /* received interface index */
134 };
135 
136 /* We need the newer CMSG_LEN() and CMSG_SPACE() macros, but few
137  implementations support them today. These two macros really need
138  an ALIGN() macro, but each implementation does this differently. */
139 #ifndef CMSG_LEN
140  #define CMSG_LEN(size) (sizeof(struct cmsghdr) + (size))
141 #endif
142 #ifndef CMSG_SPACE
143  #define CMSG_SPACE(size) (sizeof(struct cmsghdr) + (size))
144 #endif
145 
146 /* POSIX requires the SUN_LEN() macro, but not all implementations define
147  it (yet). Note that this 4.4BSD macro works regardless whether there is
148  a length field or not. */
149 #ifndef SUN_LEN
150  # define SUN_LEN (su) \
151  (sizeof (*(su)) - sizeof ((su)->sun_path) + strlen((su)->sun_path))
152 #endif
153 
154 /* POSIX renames "Unix domain" as "local IPC."
155  Not all systems define AF_LOCAL and PF_LOCAL (yet). */
156 #ifndef AF_LOCAL
157  #define AF_LOCAL AF_UNIX
158 #endif
159 #ifndef PF_LOCAL
160  #define PF_LOCAL PF_UNIX
161 #endif
162 
163 /* POSIX requires that an #include of <poll.h> define INFTIM, but many
164  systems still define it in <sys/stropts.h>. We don't want to include
165  all the STREAMS stuff if it's not needed, so we just define INFTIM here.
166  This is the standard value, but there's no guarantee it is -1. */
167 #ifndef INFTIM
168  #define INFTIM (-1) /* infinite poll timeout */
169  #ifdef HAVE_POLL_H
170  #define INFTIM_UNPH /* tell unpxti.h we defined it */
171  #endif
172 #endif
173 
174 /* Following could be derived from SOMAXCONN in <sys/socket.h>, but many
175  kernels still #define it as 5, while actually supporting many more */
176 #define LISTENQ 1024 /* 2nd argument to listen () */
177 
178 /* Miscellaneous constants */
179 #define MAXLINE 4096 /* max text line length */
180 #define MSGMAXLINE 504 /*Maximun character in msg: 503. char in [504] = '\0'. Note that MSGMAXLINE should be 512n-8 bytes. The "reserved" 8 bytes is for 64 bit pointer.*/
181 #define BUFFSIZE 8192 /* buffer size for reads and writes */
182 
183 /* Define some port number that can be used for our examples */
184 #define SERV_PORT 9877 /* TCP and UDP */
185 #define SERV_PORT_STR "9877" /* TCP and UDP */
186 #define UNIXSTR_PATH "/tmp/unix.str" /* Unix domain stream */
187 #define UNIXDG_PATH "/tmp/unix.dg" /* Unix domain datagram */
188 
189 /* Following shortens all the typecasts of pointer arguments: */
190 #define SA struct sockaddr
191 
192 #define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
193  /* default file access permissions for new files */
194 #define DIR_MODE (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
195  /* default permissions for new directories */
196 
197 typedef void Sigfunc (int); /* for signal handlers */
198 
199 #if 0
200 #define min(a,b) ((a) < (b) ? (a) : (b))
201 #define max(a,b) ((a) > (b) ? (a) : (b))
202 #endif
203 
204 #if !defined(HAVE_IF_NAMEINDEX_STRUCT) && !defined(__CYGWIN__)
205  #define HAVE_IF_NAMEINDEX_STRUCT
206  struct if_nameindex {
207  unsigned int if_index; /* 1, 2, ... */
208  char *if_name; /* null-terminated name: "le0", ... */
209  };
210 #endif
211 
212 extern void write_msg_log(const char *msg, int len, char *src = 0); // write to 'tracker' log
213 
214 #endif // #ifndef __common_hxx
char * if_name
Definition: fg_common.hxx:208
void Sigfunc(int)
Definition: fg_common.hxx:197
struct in_addr ipi_addr
Definition: fg_common.hxx:132
void write_msg_log(const char *msg, int len, char *src=0)
unsigned int if_index
Definition: fg_common.hxx:207