VirtualBox

source: vbox/trunk/src/VBox/NetworkServices/NAT/winutils.h@ 51585

Last change on this file since 51585 was 51585, checked in by vboxsync, 11 years ago

NAT/Net: Fix previous - provide #include's necessary for
proxy_error_is_transient() on the unix side of things too.

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
1#ifndef __WINUTILS_H_
2# define __WINUTILS_H_
3
4# include <iprt/cdefs.h>
5
6# ifdef RT_OS_WINDOWS
7# include <WinSock2.h>
8# include <ws2tcpip.h>
9# include <mswsock.h>
10# include <Windows.h>
11# include <iprt/err.h>
12# include <iprt/net.h>
13# include <iprt/log.h>
14/**
15 * Inclusion of lwip/def.h was added here to avoid conflict of definitions
16 * of hton-family functions in LWIP and windock's headers.
17 */
18# include <lwip/def.h>
19
20# ifndef PF_LOCAL
21# define PF_LOCAL AF_INET
22# endif
23
24# define warn(...) DPRINTF2((__VA_ARGS__))
25# define warnx warn
26# ifdef DEBUG
27# define err(code,...) do { \
28 AssertMsgFailed((__VA_ARGS__)); \
29 }while(0)
30#else
31# define err(code,...) do { \
32 DPRINTF0((__VA_ARGS__)); \
33 ExitProcess(code); \
34 }while(0)
35#endif
36# define errx err
37# define __func__ __FUNCTION__
38# define __attribute__(x) /* IGNORE */
39
40# define SOCKERRNO() (WSAGetLastError())
41
42/**
43 * "Windows Sockets Error Codes" obtained with WSAGetLastError().
44 * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx
45 *
46 * This block of error codes from <winsock2.h> conflicts with "POSIX
47 * supplement" error codes from <errno.h>, but we don't expect to ever
48 * encounter the latter in the proxy code, so redefine them to their
49 * unixy names.
50 */
51# undef EWOULDBLOCK
52# define EWOULDBLOCK WSAEWOULDBLOCK
53# undef EINPROGRESS
54# define EINPROGRESS WSAEINPROGRESS
55# undef EALREADY
56# define EALREADY WSAEALREADY
57# undef ENOTSOCK
58# define ENOTSOCK WSAENOTSOCK
59# undef EDESTADDRREQ
60# define EDESTADDRREQ WSAEDESTADDRREQ
61# undef EMSGSIZE
62# define EMSGSIZE WSAEMSGSIZE
63# undef EPROTOTYPE
64# define EPROTOTYPE WSAEPROTOTYPE
65# undef ENOPROTOOPT
66# define ENOPROTOOPT WSAENOPROTOOPT
67# undef EPROTONOSUPPORT
68# define EPROTONOSUPPORT WSAEPROTONOSUPPORT
69# undef ESOCKTNOSUPPORT
70# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
71# undef EOPNOTSUPP
72# define EOPNOTSUPP WSAEOPNOTSUPP
73# undef EPFNOSUPPORT
74# define EPFNOSUPPORT WSAEPFNOSUPPORT
75# undef EAFNOSUPPORT
76# define EAFNOSUPPORT WSAEAFNOSUPPORT
77# undef EADDRINUSE
78# define EADDRINUSE WSAEADDRINUSE
79# undef EADDRNOTAVAIL
80# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
81# undef ENETDOWN
82# define ENETDOWN WSAENETDOWN
83# undef ENETUNREACH
84# define ENETUNREACH WSAENETUNREACH
85# undef ENETRESET
86# define ENETRESET WSAENETRESET
87# undef ECONNABORTED
88# define ECONNABORTED WSAECONNABORTED
89# undef ECONNRESET
90# define ECONNRESET WSAECONNRESET
91# undef ENOBUFS
92# define ENOBUFS WSAENOBUFS
93# undef EISCONN
94# define EISCONN WSAEISCONN
95# undef ENOTCONN
96# define ENOTCONN WSAENOTCONN
97# undef ESHUTDOWN
98# define ESHUTDOWN WSAESHUTDOWN
99# undef ETOOMANYREFS
100# define ETOOMANYREFS WSAETOOMANYREFS
101# undef ETIMEDOUT
102# define ETIMEDOUT WSAETIMEDOUT
103# undef ECONNREFUSED
104# define ECONNREFUSED WSAECONNREFUSED
105# undef ELOOP
106# define ELOOP WSAELOOP
107# undef ENAMETOOLONG
108# define ENAMETOOLONG WSAENAMETOOLONG
109# undef EHOSTDOWN
110# define EHOSTDOWN WSAEHOSTDOWN
111# undef EHOSTUNREACH
112# define EHOSTUNREACH WSAEHOSTUNREACH
113
114/**
115 * parameters to shutdown (2) with Winsock2
116 * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740481(v=vs.85).aspx
117 */
118# define SHUT_RD SD_RECEIVE
119# define SHUT_WR SD_SEND
120# define SHUT_RDWR SD_BOTH
121
122typedef ULONG nfds_t;
123
124typedef WSABUF IOVEC;
125
126# define IOVEC_GET_BASE(iov) ((iov).buf)
127# define IOVEC_SET_BASE(iov, b) ((iov).buf = (b))
128
129# define IOVEC_GET_LEN(iov) ((iov).len)
130# define IOVEC_SET_LEN(iov, l) ((iov).len = (ULONG)(l))
131
132#if _WIN32_WINNT < 0x0600
133/* otherwise defined the other way around in ws2def.h */
134#define cmsghdr _WSACMSGHDR
135
136#undef CMSG_DATA /* wincrypt.h can byte my shiny metal #undef */
137#define CMSG_DATA WSA_CMSG_DATA
138#define CMSG_LEN WSA_CMSG_LEN
139#define CMSG_SPACE WSA_CMSG_SPACE
140
141#define CMSG_FIRSTHDR WSA_CMSG_FIRSTHDR
142#define CMSG_NXTHDR WSA_CMSG_NXTHDR
143#endif /* _WIN32_WINNT < 0x0600 - provide unglified CMSG names */
144
145RT_C_DECLS_BEGIN
146int RTWinSocketPair(int domain, int type, int protocol, SOCKET socket_vector[2]);
147RT_C_DECLS_END
148
149# else /* !RT_OS_WINDOWS */
150
151# include <errno.h>
152
153# define SOCKET int
154# define INVALID_SOCKET (-1)
155# define SOCKET_ERROR (-1)
156
157# define SOCKERRNO() (errno)
158
159# define closesocket(s) close(s)
160# define ioctlsocket(s, req, arg) ioctl((s), (req), (arg))
161
162typedef struct iovec IOVEC;
163
164# define IOVEC_GET_BASE(iov) ((iov).iov_base)
165# define IOVEC_SET_BASE(iov, b) ((iov).iov_base = (b))
166
167# define IOVEC_GET_LEN(iov) ((iov).iov_len)
168# define IOVEC_SET_LEN(iov, l) ((iov).iov_len = (l))
169# endif
170
171DECLINLINE(int)
172proxy_error_is_transient(int error)
173{
174# if !defined(RT_OS_WINDOWS)
175 return error == EWOULDBLOCK
176# if EAGAIN != EWOULDBLOCK
177 || error == EAGAIN
178# endif
179 || error == EINTR
180 || error == ENOBUFS
181 || error == ENOMEM;
182# else
183 return error == WSAEWOULDBLOCK
184 || error == WSAEINTR /* NB: we don't redefine EINTR above */
185 || error == WSAENOBUFS;
186# endif
187}
188
189#endif
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette