winutils.h revision 23bcfa32fddbe29a8c4c40d3bcfa4693a555c177
/* $Id$ */
/** @file
* NAT Network - winsock compatibility shim.
*/
/*
* Copyright (C) 2013-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef __WINUTILS_H_
# define __WINUTILS_H_
# ifdef RT_OS_WINDOWS
# include <WinSock2.h>
# include <ws2tcpip.h>
# include <mswsock.h>
# include <Windows.h>
/**
* of hton-family functions in LWIP and windock's headers.
*/
# ifndef PF_LOCAL
# endif
# ifdef DEBUG
AssertMsgFailed((__VA_ARGS__)); \
}while(0)
#else
DPRINTF0((__VA_ARGS__)); \
ExitProcess(code); \
}while(0)
#endif
# define __func__ __FUNCTION__
# define __attribute__(x) /* IGNORE */
# define SOCKERRNO() (WSAGetLastError())
/**
* "Windows Sockets Error Codes" obtained with WSAGetLastError().
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx
*
* This block of error codes from <winsock2.h> conflicts with "POSIX
* supplement" error codes from <errno.h>, but we don't expect to ever
* encounter the latter in the proxy code, so redefine them to their
* unixy names.
*/
# define EWOULDBLOCK WSAEWOULDBLOCK
# define EINPROGRESS WSAEINPROGRESS
# define EALREADY WSAEALREADY
# define ENOTSOCK WSAENOTSOCK
# define EDESTADDRREQ WSAEDESTADDRREQ
# define EMSGSIZE WSAEMSGSIZE
# define EPROTOTYPE WSAEPROTOTYPE
# define ENOPROTOOPT WSAENOPROTOOPT
# define EPROTONOSUPPORT WSAEPROTONOSUPPORT
# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
# define EOPNOTSUPP WSAEOPNOTSUPP
# define EPFNOSUPPORT WSAEPFNOSUPPORT
# define EAFNOSUPPORT WSAEAFNOSUPPORT
# define EADDRINUSE WSAEADDRINUSE
# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
# define ENETDOWN WSAENETDOWN
# define ENETUNREACH WSAENETUNREACH
# define ENETRESET WSAENETRESET
# define ECONNABORTED WSAECONNABORTED
# define ECONNRESET WSAECONNRESET
# define ENOBUFS WSAENOBUFS
# define EISCONN WSAEISCONN
# define ENOTCONN WSAENOTCONN
# define ESHUTDOWN WSAESHUTDOWN
# define ETOOMANYREFS WSAETOOMANYREFS
# define ETIMEDOUT WSAETIMEDOUT
# define ECONNREFUSED WSAECONNREFUSED
# define ENAMETOOLONG WSAENAMETOOLONG
# define EHOSTDOWN WSAEHOSTDOWN
# define EHOSTUNREACH WSAEHOSTUNREACH
/**
* parameters to shutdown (2) with Winsock2
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms740481(v=vs.85).aspx
*/
# define SHUT_RD SD_RECEIVE
#if _WIN32_WINNT < 0x0600
/* otherwise defined the other way around in ws2def.h */
#define cmsghdr _WSACMSGHDR
#define CMSG_DATA WSA_CMSG_DATA
#define CMSG_LEN WSA_CMSG_LEN
#define CMSG_SPACE WSA_CMSG_SPACE
#define CMSG_FIRSTHDR WSA_CMSG_FIRSTHDR
#define CMSG_NXTHDR WSA_CMSG_NXTHDR
#endif /* _WIN32_WINNT < 0x0600 - provide unglified CMSG names */
# else /* !RT_OS_WINDOWS */
# include <errno.h>
# define SOCKET int
# define INVALID_SOCKET (-1)
# define SOCKET_ERROR (-1)
# define closesocket(s) close(s)
# endif
DECLINLINE(int)
{
# if !defined(RT_OS_WINDOWS)
return error == EWOULDBLOCK
# if EAGAIN != EWOULDBLOCK
# endif
# else
return error == WSAEWOULDBLOCK
|| error == WSAENOBUFS;
# endif
}
#endif