1 /* 2 * iphdr.h -- TCP/IP interface 3 * 4 * iphdr.h is a part of binkd project 5 * 6 * Copyright (C) 1996 Dima Maloff, 5047/13 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. See COPYING. 12 */ 13 14 /* 15 * $Id: iphdr.h,v 2.24.2.1 2014/08/20 06:12:37 gul Exp $ 16 * 17 * $Log: iphdr.h,v $ 18 * Revision 2.24.2.1 2014/08/20 06:12:37 gul 19 * Fixed 100% cpu load if called with poll flag, 20 * backport many fixes related to compilation on win32 and os/2. 21 * 22 * Revision 2.24 2012/01/25 21:02:43 green 23 * Some changes to enable compilation on OS/2 with GCC/kLIBC 24 * 25 * Revision 2.23 2012/01/08 17:34:57 green 26 * Avoid using MAXHOSTNAMELEN 27 * 28 * Revision 2.22 2012/01/08 16:23:52 green 29 * Fixed compilation in Cygwin/MinGW 30 * 31 * Revision 2.21 2012/01/08 13:21:19 green 32 * Ensure sufficiently long MAXHOSTNAMELEN 33 * 34 * Revision 2.20 2012/01/07 23:38:45 green 35 * Improved getnameinfo handling, retry without name resolution 36 * 37 * Revision 2.19 2012/01/06 07:23:47 gul 38 * Fix resolv.h check under FreeBSD; cosmetics 39 * 40 * Revision 2.18 2012/01/03 17:25:31 green 41 * Implemented IPv6 support 42 * - replace (almost) all getXbyY function calls with getaddrinfo/getnameinfo (RFC2553) calls 43 * - Add compatibility layer for target systems not supporting RFC2553 calls in rfc2553.[ch] 44 * - Add support for multiple listen sockets -- one for IPv4 and one for IPv6 (use V6ONLY) 45 * - For WIN32 platform add configuration parameter IPV6 (mutually exclusive with BINKD9X) 46 * - On WIN32 platform use Winsock2 API if IPV6 support is requested 47 * - config: node IP address literal + port supported: [<ipv6 address>]:<port> 48 * 49 * Revision 2.17 2004/07/12 08:21:20 stas 50 * Fix the file name case. Bugreport from Andrey Slusar 2:467/126 51 * 52 * Revision 2.16 2003/10/06 17:16:47 stas 53 * (Cosmetics) Rename tcperr() to w32err() for win32/win9x versions 54 * 55 * Revision 2.15 2003/08/26 16:06:26 stream 56 * Reload configuration on-the fly. 57 * 58 * Warning! Lot of code can be broken (Perl for sure). 59 * Compilation checked only under OS/2-Watcom and NT-MSVC (without Perl) 60 * 61 * Revision 2.14 2003/08/24 18:54:30 gul 62 * Bugfix in timeout check on win32 63 * 64 * Revision 2.13 2003/08/24 00:45:44 hbrew 65 * win9x-select-workaround fix, thanks to Pavel Gulchouck 66 * 67 * Revision 2.12 2003/07/18 10:30:33 stas 68 * New functions: IsNT(), Is9x(); small code cleanup 69 * 70 * Revision 2.11 2003/06/11 09:00:43 stas 71 * Don't try to install/uninstall/control service on incompatible OS. Thanks to Alexander Reznikov 72 * 73 * Revision 2.10 2003/06/04 10:36:58 stas 74 * Thread-safety tcperr() implementation on Win32 75 * 76 * Revision 2.9 2003/03/30 10:14:40 gul 77 * Use HAVE_SOCKLEN_T macro 78 * 79 * Revision 2.8 2003/03/26 13:53:28 gul 80 * Fix OS/2 compilation 81 * 82 * Revision 2.7 2003/03/11 09:21:30 gul 83 * Fixed OS/2 Watcom compilation 84 * 85 * Revision 2.6 2003/03/11 00:04:25 gul 86 * Use patches for compile under MSDOS by MSC 6.0 with IBMTCPIP 87 * 88 * Revision 2.5 2003/03/10 18:16:10 gul 89 * Define socklen_t for win32 90 * 91 * Revision 2.4 2003/03/10 12:16:53 gul 92 * Use HAVE_DOS_H macro 93 * 94 * Revision 2.3 2003/03/01 20:16:27 gul 95 * OS/2 IBM C support 96 * 97 * Revision 2.2 2003/03/01 18:37:08 gul 98 * Use HAVE_SYS_PARAM_H macro 99 * 100 * Revision 2.1 2003/02/28 20:39:08 gul 101 * Code cleanup: 102 * change "()" to "(void)" in function declarations; 103 * change C++-style comments to C-style 104 * 105 * Revision 2.0 2001/01/10 12:12:38 gul 106 * Binkd is under CVS again 107 * 108 * Revision 1.4 1997/10/23 04:02:31 mff 109 * many, many changes (forget to ci a version or two) 110 * 111 * Revision 1.2 1996/12/07 11:42:18 mff 112 * soclose() for NT was defined as close(). Fixed. 113 * 114 * 115 */ 116 #ifndef _iphdrs_h 117 #define _iphdrs_h 118 119 #include <sys/types.h> 120 121 #ifdef HAVE_SYS_PARAM_H 122 #include <sys/param.h> 123 #endif 124 125 #include "sys.h" /* Get system i/o headers */ 126 127 #ifdef IBMTCPIP 128 #include <errno.h> 129 #undef ENAMETOOLONG 130 #undef ENOTEMPTY 131 132 #define BSD_SELECT 133 #define __off_t 134 #define __size_t 135 #include <types.h> 136 #include <utils.h> 137 #include <unistd.h> 138 #include <sys/select.h> 139 #endif 140 141 #if !defined(WIN32) 142 #if defined(IBMTCPIPDOS) 143 #include <sys/tcptypes.h> 144 #endif 145 146 #ifdef HAVE_NETINET_IN_H 147 #include <netinet/in.h> 148 #endif 149 #ifdef HAVE_NETDB_H 150 #include <netdb.h> /* One of these two should have 151 * MAXHOSTNAMELEN */ 152 #endif 153 #endif 154 155 #ifdef HAVE_ARPA_INET_H 156 #include <arpa/inet.h> 157 #endif 158 159 #if !defined(WIN32) 160 #include <sys/socket.h> 161 #endif 162 163 /* Some systems have MAXHOSTNAMELEN = 64 */ 164 #ifdef NI_MAXHOST 165 #define BINKD_FQDNLEN NI_MAXHOST /* max length for getnameinfo */ 166 #else 167 #define BINKD_FQDNLEN 255 /* max FQDN size */ 168 #endif 169 170 #ifdef NI_MAXSERV 171 #define MAXSERVNAME NI_MAXSERV /* max length for getnameinfo */ 172 #else 173 #define MAXSERVNAME 80 /* max id len in /etc/services */ 174 #endif 175 176 #ifndef HAVE_SOCKLEN_T 177 typedef int socklen_t; 178 #endif 179 180 #if defined(IBMTCPIP) 181 const char *tcperr (void); 182 183 #define ReleaseErrorList() 184 #define TCPERR() tcperr() 185 #define TCPERRNO (sock_errno()) 186 #include <nerrno.h> 187 #define TCPERR_WOULDBLOCK EWOULDBLOCK 188 #define TCPERR_AGAIN EAGAIN 189 #define sock_deinit() 190 #ifndef MAXSOCKETS 191 #define MAXSOCKETS 2048 192 #endif 193 #elif defined(IBMTCPIPDOS) 194 const char *tcperr (void); 195 196 #define ReleaseErrorList() 197 #define TCPERR() tcperr() 198 #define TCPERRNO (tcperrno) 199 #include <sys/errno.h> 200 #undef ENAMETOOLONG 201 #undef ENOTEMPTY 202 #define TCPERR_WOULDBLOCK EWOULDBLOCK 203 #define TCPERR_AGAIN EAGAIN 204 #define sock_deinit() 205 #elif defined(WIN32) 206 const char *w32err (int); 207 void ReleaseErrorList(void); 208 209 #include <errno.h> 210 #define TCPERR() w32err(h_errno) 211 #define TCPERRNO (h_errno) 212 #define TCPERR_WOULDBLOCK WSAEWOULDBLOCK 213 #define TCPERR_AGAIN WSAEWOULDBLOCK 214 #include "nt/WSock.h" 215 #define sock_init() WinsockIni() 216 #define sock_deinit() WinsockClean() 217 #define soclose(h) closesocket(h) 218 /* w9x_workaround_sleep: 1000000 = 1 sec, 10000 = 10 ms */ 219 #define w9x_workaround_sleep 10000 220 #else 221 #include <errno.h> 222 #define ReleaseErrorList() 223 #define TCPERR() strerror(errno) 224 #define TCPERRNO errno 225 #define TCPERR_WOULDBLOCK EWOULDBLOCK 226 #define TCPERR_AGAIN EAGAIN 227 #define sock_init() 0 228 #define sock_deinit() 229 #define soclose(h) close(h) 230 #endif 231 232 #if !defined(WIN32) 233 typedef int SOCKET; 234 235 #define INVALID_SOCKET (-1) 236 #define SOCKET_ERROR (-1) 237 #endif 238 239 #ifndef INADDR_NONE 240 #define INADDR_NONE -1 241 #endif 242 243 /* OS/2 doesn't support IPv6, we are trying to detect availability of 244 * some structures based on this define 245 */ 246 #ifdef OS2 247 #undef AF_INET6 248 #endif 249 250 #endif 251