winutils.h revision daef40d247c31e2073c0ed0ec55fac77a4b89ac3
1707N/A#ifndef __WINUTILS_H_
1707N/A# define __WINUTILS_H_
1707N/A
1707N/A# ifdef RT_OS_WINDOWS
1707N/A# include <iprt/cdefs.h>
1707N/A# include <WinSock2.h>
1707N/A# include <ws2tcpip.h>
1707N/A# include <mswsock.h>
1707N/A# include <Windows.h>
1707N/A# include <iprt/err.h>
1707N/A# include <iprt/net.h>
1707N/A# include <iprt/log.h>
1707N/A/**
1707N/A * Inclusion of lwip/def.h was added here to avoid conflict of definitions
1707N/A * of hton-family functions in LWIP and windock's headers.
1707N/A */
1707N/A# include <lwip/def.h>
1707N/A
1707N/A# ifndef PF_LOCAL
1707N/A# define PF_LOCAL AF_INET
1707N/A# endif
1707N/A
1707N/A# define warn(...) DPRINTF2((__VA_ARGS__))
1707N/A# define warnx warn
1707N/A# ifdef DEBUG
3233N/A# define err(code,...) do { \
1707N/A AssertMsgFailed((__VA_ARGS__)); \
1707N/A }while(0)
1920N/A#else
1707N/A# define err(code,...) do { \
3824N/A DPRINTF0((__VA_ARGS__)); \
3824N/A ExitProcess(code); \
3824N/A }while(0)
3824N/A#endif
3824N/A# define errx err
3824N/A# define __func__ __FUNCTION__
3842N/A# define __attribute__(x) /* IGNORE */
3842N/A
3824N/A/**
3842N/A * tftpd emulation we're using POSIX operations which needs "DOS errno". see proxy_tftpd.c
1707N/A */
2976N/A# ifndef _USE_WINSTD_ERRNO
2650N/A/**
2976N/A * http://msdn.microsoft.com/en-us/library/windows/desktop/ms737828(v=vs.85).aspx
2976N/A * "Error Codes - errno, h_errno and WSAGetLastError" says "Error codes set by Windows Sockets are
3824N/A * not made available through the errno variable."
2976N/A */
1707N/A# include <errno.h>
2549N/A# ifdef errno
2549N/A# undef errno
2549N/A# endif
2549N/A# define errno (WSAGetLastError())
3824N/A# endif
2549N/A/* Missing errno codes */
2549N/A
2549N/A/**
2549N/A * "Windows Sockets Error Codes" obtained with WSAGetLastError().
2976N/A * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx
1777N/A */
1777N/A# undef EMSGSIZE
1777N/A# define EMSGSIZE WSAEMSGSIZE
1707N/A# undef ENETDOWN
1707N/A# define ENETDOWN WSAENETDOWN
1777N/A# undef ENETUNREACH
1777N/A# define ENETUNREACH WSAENETUNREACH
1777N/A# undef EHOSTDOWN
1777N/A# define EHOSTDOWN WSAEHOSTDOWN
1707N/A# undef EHOSTUNREACH
# 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
# define SHUT_WR SD_SEND
# define SHUT_RDWR SD_BOTH
typedef ULONG nfds_t;
typedef WSABUF IOVEC;
# define IOVEC_GET_BASE(iov) ((iov).buf)
# define IOVEC_SET_BASE(iov, b) ((iov).buf = (b))
# define IOVEC_GET_LEN(iov) ((iov).len)
# define IOVEC_SET_LEN(iov, l) ((iov).len = (ULONG)(l))
#if _WIN32_WINNT < 0x0600
/* otherwise defined the other way around in ws2def.h */
#define cmsghdr _WSACMSGHDR
#undef CMSG_DATA /* wincrypt.h can byte my shiny metal #undef */
#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 */
RT_C_DECLS_BEGIN
int RTWinSocketPair(int domain, int type, int protocol, SOCKET socket_vector[2]);
RT_C_DECLS_END
# else /* !RT_OS_WINDOWS */
# define ioctlsocket ioctl
# define closesocket close
# define SOCKET int
# define INVALID_SOCKET (-1)
# define SOCKET_ERROR (-1)
typedef struct iovec IOVEC;
# define IOVEC_GET_BASE(iov) ((iov).iov_base)
# define IOVEC_SET_BASE(iov, b) ((iov).iov_base = (b))
# define IOVEC_GET_LEN(iov) ((iov).iov_len)
# define IOVEC_SET_LEN(iov, l) ((iov).iov_len = (l))
# endif
#endif