1 | #ifndef __WINUTILS_H_
|
---|
2 | # define __WINUTILS_H_
|
---|
3 |
|
---|
4 | # ifdef RT_OS_WINDOWS
|
---|
5 | # include <iprt/cdefs.h>
|
---|
6 | # include <WinSock2.h>
|
---|
7 | # include <ws2tcpip.h>
|
---|
8 | # include <Windows.h>
|
---|
9 | # include <iprt/err.h>
|
---|
10 | # include <iprt/net.h>
|
---|
11 | # include <iprt/log.h>
|
---|
12 | /**
|
---|
13 | * Inclusion of lwip/def.h was added here to avoid conflict of definitions
|
---|
14 | * of hton-family functions in LWIP and windock's headers.
|
---|
15 | */
|
---|
16 | # include <lwip/def.h>
|
---|
17 |
|
---|
18 | # ifndef PF_LOCAL
|
---|
19 | # define PF_LOCAL AF_INET
|
---|
20 | # endif
|
---|
21 |
|
---|
22 | # define warn(...) DPRINTF2((__VA_ARGS__))
|
---|
23 | # define warnx warn
|
---|
24 | # ifdef DEBUG
|
---|
25 | # define err(code,...) do { \
|
---|
26 | AssertMsgFailed((__VA_ARGS__)); \
|
---|
27 | }while(0)
|
---|
28 | #else
|
---|
29 | # define err(code,...) do { \
|
---|
30 | DPRINTF0((__VA_ARGS__)); \
|
---|
31 | ExitProcess(code); \
|
---|
32 | }while(0)
|
---|
33 | #endif
|
---|
34 | # define errx err
|
---|
35 | # define __func__ __FUNCTION__
|
---|
36 | # define __attribute__(x) /* IGNORE */
|
---|
37 | # define inet_ntop(dom, pvaddr, pstrbuf, cbstrbuf) InetNtop((dom),(pvaddr),(pstrbuf),(cbstrbuf))
|
---|
38 |
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * tftpd emulation we're using POSIX operations which needs "DOS errno". see proxy_tftpd.c
|
---|
42 | */
|
---|
43 | # ifndef _USE_WINSTD_ERRNO
|
---|
44 | /**
|
---|
45 | * http://msdn.microsoft.com/en-us/library/windows/desktop/ms737828(v=vs.85).aspx
|
---|
46 | * "Error Codes - errno, h_errno and WSAGetLastError" says "Error codes set by Windows Sockets are
|
---|
47 | * not made available through the errno variable."
|
---|
48 | */
|
---|
49 | # include <errno.h>
|
---|
50 | # ifdef errno
|
---|
51 | # undef errno
|
---|
52 | # endif
|
---|
53 | # define errno (WSAGetLastError())
|
---|
54 | # endif
|
---|
55 | /* Missing errno codes */
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx#WSAEHOSTDOWN
|
---|
59 | * Corresponds to WSAEHOSTDOWN (10064) WSAGetLastError()
|
---|
60 | */
|
---|
61 | # define EHOSTDOWN WSAEHOSTDOWN
|
---|
62 | /**
|
---|
63 | * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx#WSAEHOSTUNREACH
|
---|
64 | */
|
---|
65 | # define EHOSTUNREAH WSAEHOSTUNREACH
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * parameters to shutdown (2) with Winsock2
|
---|
69 | * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740481(v=vs.85).aspx
|
---|
70 | */
|
---|
71 | # define SHUT_RD SD_RECEIVE
|
---|
72 | # define SHUT_WR SD_SEND
|
---|
73 | # define SHUT_RDWR SD_BOTH
|
---|
74 |
|
---|
75 | typedef int socklen_t;
|
---|
76 |
|
---|
77 | typedef ULONG nfds_t;
|
---|
78 |
|
---|
79 | typedef WSABUF IOVEC;
|
---|
80 |
|
---|
81 | # define IOVEC_GET_BASE(iov) ((iov).buf)
|
---|
82 | # define IOVEC_SET_BASE(iov, b) ((iov).buf = (b))
|
---|
83 |
|
---|
84 | # define IOVEC_GET_LEN(iov) ((iov).len)
|
---|
85 | # define IOVEC_SET_LEN(iov, l) ((iov).len = (ULONG)(l))
|
---|
86 |
|
---|
87 | RT_C_DECLS_BEGIN
|
---|
88 | int RTWinSocketPair(int domain, int type, int protocol, SOCKET socket_vector[2]);
|
---|
89 | RT_C_DECLS_END
|
---|
90 |
|
---|
91 | # else /* !RT_OS_WINDOWS */
|
---|
92 | # define ioctlsocket ioctl
|
---|
93 | # define closesocket close
|
---|
94 | # define SOCKET int
|
---|
95 | # define INVALID_SOCKET (-1)
|
---|
96 | # define SOCKET_ERROR (-1)
|
---|
97 |
|
---|
98 | typedef struct iovec IOVEC;
|
---|
99 |
|
---|
100 | # define IOVEC_GET_BASE(iov) ((iov).iov_base)
|
---|
101 | # define IOVEC_SET_BASE(iov, b) ((iov).iov_base = (b))
|
---|
102 |
|
---|
103 | # define IOVEC_GET_LEN(iov) ((iov).iov_len)
|
---|
104 | # define IOVEC_SET_LEN(iov, l) ((iov).iov_len = (l))
|
---|
105 | # endif
|
---|
106 | #endif
|
---|