VirtualBox

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

Last change on this file since 78034 was 76576, checked in by vboxsync, 6 years ago

NetworkServices: scm header guard alignment.

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

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