14 #ifndef NETWORK_CORE_OS_ABSTRACTION_H
15 #define NETWORK_CORE_OS_ABSTRACTION_H
26 #define GET_LAST_ERROR() WSAGetLastError()
28 #define EWOULDBLOCK WSAEWOULDBLOCK
30 typedef unsigned long in_addr_t;
33 #if defined(__MINGW32__) && !defined(AI_ADDRCONFIG)
34 # define AI_ADDRCONFIG 0x00000400
37 #if !(defined(__MINGW32__) || defined(__CYGWIN__))
39 typedef SSIZE_T ssize_t;
40 typedef int socklen_t;
41 # define IPPROTO_IPV6 41
46 #if defined(UNIX) && !defined(__OS2__)
47 # if defined(OPENBSD) || defined(__NetBSD__)
48 # define AI_ADDRCONFIG 0
51 # define INVALID_SOCKET -1
52 # define ioctlsocket ioctl
53 # define closesocket close
54 # define GET_LAST_ERROR() (errno)
60 # include <sys/ioctl.h>
61 # include <sys/socket.h>
62 # include <netinet/in.h>
63 # include <netinet/tcp.h>
64 # include <arpa/inet.h>
67 # if !defined(__sgi__) && !defined(SUNOS) && !defined(__INNOTEK_LIBC__) \
68 && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX)
73 # define HAVE_GETIFADDRS
75 # if !defined(INADDR_NONE)
76 # define INADDR_NONE 0xffffffff
79 # if defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 1)
80 typedef uint32_t in_addr_t;
84 # include <sys/time.h>
87 # if defined(__EMSCRIPTEN__)
90 # define AI_ADDRCONFIG 0
94 # define FD_SETSIZE 64
101 # define INVALID_SOCKET -1
102 # define ioctlsocket ioctl
103 # define closesocket close
104 # define GET_LAST_ERROR() (sock_errno())
109 # include <sys/ioctl.h>
110 # include <sys/socket.h>
111 # include <netinet/in.h>
112 # include <netinet/tcp.h>
113 # include <arpa/inet.h>
116 # include <sys/time.h>
119 # define INADDR_NONE 0xffffffff
120 # include "../../3rdparty/os2/getaddrinfo.h"
121 # include "../../3rdparty/os2/getnameinfo.h"
123 #define IPV6_V6ONLY 27
130 uint8_t __u6_addr8[16];
131 uint16_t __u6_addr16[8];
132 uint32_t __u6_addr32[4];
136 #define s6_addr __u6_addr.__u6_addr8
138 struct sockaddr_in6 {
140 sa_family_t sin6_family;
142 uint32_t sin6_flowinfo;
143 struct in6_addr sin6_addr;
144 uint32_t sin6_scope_id;
147 typedef int socklen_t;
148 #if !defined(__INNOTEK_LIBC__)
149 typedef unsigned long in_addr_t;
154 #ifdef __EMSCRIPTEN__
166 static inline socklen_t FixAddrLenForEmscripten(
struct sockaddr_storage &address)
168 switch (address.ss_family) {
169 case AF_INET6:
return sizeof(
struct sockaddr_in6);
170 case AF_INET:
return sizeof(
struct sockaddr_in);
171 default: NOT_REACHED();
183 #ifdef __EMSCRIPTEN__
187 u_long nonblocking = 1;
191 return ioctlsocket(d, FIONBIO, &nonblocking) == 0;
202 #ifdef __EMSCRIPTEN__
208 return setsockopt(d, IPPROTO_TCP, TCP_NODELAY, (
const char*)&b,
sizeof(b)) == 0;
213 static_assert(
sizeof(in_addr) == 4);
214 static_assert(
sizeof(in6_addr) == 16);