20 #ifndef WINPR_WINSOCK_H
21 #define WINPR_WINSOCK_H
23 #include <winpr/platform.h>
24 #include <winpr/winpr.h>
25 #include <winpr/wtypes.h>
26 #include <winpr/windows.h>
28 WINPR_PRAGMA_DIAG_PUSH
29 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
33 #define _accept accept
35 #define _connect connect
36 #define _ioctlsocket ioctlsocket
37 #define _getpeername getpeername
38 #define _getsockname getsockname
39 #define _getsockopt getsockopt
42 #define _inet_addr inet_addr
43 #define _inet_ntoa inet_ntoa
44 #define _listen listen
48 #define _recvfrom recvfrom
49 #define _select select
51 #define _sendto sendto
52 #define _setsockopt setsockopt
53 #define _shutdown shutdown
54 #define _socket socket
55 #define _gethostbyaddr gethostbyaddr
56 #define _gethostbyname gethostbyname
57 #define _gethostname gethostname
58 #define _getservbyport getservbyport
59 #define _getservbyname getservbyname
60 #define _getprotobynumber getprotobynumber
61 #define _getprotobyname getprotobyname
63 #define _IFF_UP IFF_UP
64 #define _IFF_BROADCAST IFF_BROADCAST
65 #define _IFF_LOOPBACK IFF_LOOPBACK
66 #define _IFF_POINTTOPOINT IFF_POINTTOPOINT
67 #define _IFF_MULTICAST IFF_MULTICAST
69 #if (_WIN32_WINNT < 0x0600)
71 WINPR_API PCSTR winpr_inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf,
size_t StringBufSize);
72 WINPR_API INT winpr_inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf);
74 #define inet_ntop winpr_inet_ntop
75 #define inet_pton winpr_inet_pton
84 #include <sys/ioctl.h>
85 #include <sys/socket.h>
86 #include <arpa/inet.h>
87 #include <netinet/in.h>
88 #include <netinet/tcp.h>
92 #include <winpr/error.h>
93 #include <winpr/platform.h>
95 #define WSAEVENT HANDLE
96 #define LPWSAEVENT LPHANDLE
97 #define WSAOVERLAPPED OVERLAPPED
100 typedef UINT_PTR SOCKET;
101 typedef struct sockaddr_storage SOCKADDR_STORAGE;
103 #ifndef INVALID_SOCKET
104 #define INVALID_SOCKET (SOCKET)(~0)
107 #define WSADESCRIPTION_LEN 256
108 #define WSASYS_STATUS_LEN 128
110 #define FD_READ_BIT 0
111 #define FD_READ (1 << FD_READ_BIT)
113 #define FD_WRITE_BIT 1
114 #define FD_WRITE (1 << FD_WRITE_BIT)
117 #define FD_OOB (1 << FD_OOB_BIT)
119 #define FD_ACCEPT_BIT 3
120 #define FD_ACCEPT (1 << FD_ACCEPT_BIT)
122 #define FD_CONNECT_BIT 4
123 #define FD_CONNECT (1 << FD_CONNECT_BIT)
125 #define FD_CLOSE_BIT 5
126 #define FD_CLOSE (1 << FD_CLOSE_BIT)
129 #define FD_QOS (1 << FD_QOS_BIT)
131 #define FD_GROUP_QOS_BIT 7
132 #define FD_GROUP_QOS (1 << FD_GROUP_QOS_BIT)
134 #define FD_ROUTING_INTERFACE_CHANGE_BIT 8
135 #define FD_ROUTING_INTERFACE_CHANGE (1 << FD_ROUTING_INTERFACE_CHANGE_BIT)
137 #define FD_ADDRESS_LIST_CHANGE_BIT 9
138 #define FD_ADDRESS_LIST_CHANGE (1 << FD_ADDRESS_LIST_CHANGE_BIT)
140 #define FD_MAX_EVENTS 10
141 #define FD_ALL_EVENTS ((1 << FD_MAX_EVENTS) - 1)
147 #define SOCKET_ERROR (-1)
149 typedef struct WSAData
154 unsigned short iMaxSockets;
155 unsigned short iMaxUdpDg;
157 char szDescription[WSADESCRIPTION_LEN + 1];
158 char szSystemStatus[WSASYS_STATUS_LEN + 1];
160 char szDescription[WSADESCRIPTION_LEN + 1];
161 char szSystemStatus[WSASYS_STATUS_LEN + 1];
162 unsigned short iMaxSockets;
163 unsigned short iMaxUdpDg;
169 #define MAKEWORD(a, b) \
170 ((WORD)(((BYTE)((DWORD_PTR)(a)&0xFF)) | (((WORD)((BYTE)((DWORD_PTR)(b)&0xFF))) << 8)))
173 typedef struct in6_addr IN6_ADDR;
174 typedef struct in6_addr* PIN6_ADDR;
175 typedef struct in6_addr* LPIN6_ADDR;
187 struct sockaddr Address;
188 struct sockaddr_in AddressIn;
192 WINPR_PRAGMA_DIAG_PUSH
193 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
195 #define _IFF_UP 0x00000001
196 #define _IFF_BROADCAST 0x00000002
197 #define _IFF_LOOPBACK 0x00000004
198 #define _IFF_POINTTOPOINT 0x00000008
199 #define _IFF_MULTICAST 0x00000010
201 WINPR_PRAGMA_DIAG_POP
212 #define MAX_PROTOCOL_CHAIN 7
213 #define WSAPROTOCOL_LEN 255
218 DWORD ChainEntries[MAX_PROTOCOL_CHAIN];
223 DWORD dwServiceFlags1;
224 DWORD dwServiceFlags2;
225 DWORD dwServiceFlags3;
226 DWORD dwServiceFlags4;
227 DWORD dwProviderFlags;
229 DWORD dwCatalogEntryId;
237 int iProtocolMaxOffset;
238 int iNetworkByteOrder;
241 DWORD dwProviderReserved;
242 CHAR szProtocol[WSAPROTOCOL_LEN + 1];
247 DWORD dwServiceFlags1;
248 DWORD dwServiceFlags2;
249 DWORD dwServiceFlags3;
250 DWORD dwServiceFlags4;
251 DWORD dwProviderFlags;
253 DWORD dwCatalogEntryId;
261 int iProtocolMaxOffset;
262 int iNetworkByteOrder;
265 DWORD dwProviderReserved;
266 WCHAR szProtocol[WSAPROTOCOL_LEN + 1];
269 typedef void(CALLBACK* LPWSAOVERLAPPED_COMPLETION_ROUTINE)(DWORD dwError, DWORD cbTransferred,
273 typedef UINT32 GROUP;
274 #define SG_UNCONSTRAINED_GROUP 0x01
275 #define SG_CONSTRAINED_GROUP 0x02
277 #define SIO_GET_INTERFACE_LIST _IOR('t', 127, ULONG)
278 #define SIO_GET_INTERFACE_LIST_EX _IOR('t', 126, ULONG)
279 #define SIO_SET_MULTICAST_FILTER _IOW('t', 125, ULONG)
280 #define SIO_GET_MULTICAST_FILTER _IOW('t', 124 | IOC_IN, ULONG)
281 #define SIOCSIPMSFILTER SIO_SET_MULTICAST_FILTER
282 #define SIOCGIPMSFILTER SIO_GET_MULTICAST_FILTER
285 #define WSAPROTOCOL_INFO WSAPROTOCOL_INFOW
286 #define LPWSAPROTOCOL_INFO LPWSAPROTOCOL_INFOW
288 #define WSAPROTOCOL_INFO WSAPROTOCOL_INFOA
289 #define LPWSAPROTOCOL_INFO LPWSAPROTOCOL_INFOA
297 WINPR_API
int WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
298 WINPR_API
int WSACleanup(
void);
300 WINPR_API
void WSASetLastError(
int iError);
301 WINPR_API
int WSAGetLastError(
void);
303 WINPR_API BOOL WSACloseEvent(HANDLE hEvent);
305 WINPR_ATTR_MALLOC(WSACloseEvent, 1)
306 WINPR_API HANDLE WSACreateEvent(
void);
307 WINPR_API BOOL WSASetEvent(HANDLE hEvent);
308 WINPR_API BOOL WSAResetEvent(HANDLE hEvent);
310 WINPR_API
int WSAEventSelect(SOCKET s, WSAEVENT hEventObject, LONG lNetworkEvents);
312 WINPR_API DWORD WSAWaitForMultipleEvents(DWORD cEvents, const HANDLE* lphEvents, BOOL fWaitAll,
313 DWORD dwTimeout, BOOL fAlertable);
315 WINPR_API SOCKET WSASocketA(
int af,
int type,
int protocol,
LPWSAPROTOCOL_INFOA lpProtocolInfo,
316 GROUP g, DWORD dwFlags);
317 WINPR_API SOCKET WSASocketW(
int af,
int type,
int protocol,
LPWSAPROTOCOL_INFOW lpProtocolInfo,
318 GROUP g, DWORD dwFlags);
320 WINPR_API
int WSAIoctl(SOCKET s, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
321 LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned,
323 LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
325 WINPR_API SOCKET _accept(SOCKET s, struct sockaddr* addr,
int* addrlen);
326 WINPR_API
int _bind(SOCKET s, const struct sockaddr* addr,
int namelen);
327 WINPR_API
int closesocket(SOCKET s);
328 WINPR_API
int _connect(SOCKET s, const struct sockaddr* name,
int namelen);
329 WINPR_API
int _ioctlsocket(SOCKET s,
long cmd, u_long* argp);
330 WINPR_API
int _getpeername(SOCKET s, struct sockaddr* name,
int* namelen);
331 WINPR_API
int _getsockname(SOCKET s, struct sockaddr* name,
int* namelen);
332 WINPR_API
int _getsockopt(SOCKET s,
int level,
int optname,
char* optval,
int* optlen);
333 WINPR_API u_long _htonl(u_long hostlong);
334 WINPR_API u_short _htons(u_short hostshort);
335 WINPR_API
unsigned long _inet_addr(const
char* cp);
336 WINPR_API
char* _inet_ntoa(struct in_addr in);
337 WINPR_API
int _listen(SOCKET s,
int backlog);
338 WINPR_API u_long _ntohl(u_long netlong);
339 WINPR_API u_short _ntohs(u_short netshort);
340 WINPR_API
int _recv(SOCKET s,
char* buf,
int len,
int flags);
341 WINPR_API
int _recvfrom(SOCKET s,
char* buf,
int len,
int flags, struct sockaddr* from,
343 WINPR_API
int _select(
int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds,
344 const struct timeval* timeout);
345 WINPR_API
int _send(SOCKET s, const
char* buf,
int len,
int flags);
346 WINPR_API
int _sendto(SOCKET s, const
char* buf,
int len,
int flags, const struct sockaddr* to,
348 WINPR_API
int _setsockopt(SOCKET s,
int level,
int optname, const
char* optval,
int optlen);
349 WINPR_API
int _shutdown(SOCKET s,
int how);
350 WINPR_API SOCKET _socket(
int af,
int type,
int protocol);
351 WINPR_API struct hostent* _gethostbyaddr(const
char* addr,
int len,
int type);
352 WINPR_API struct hostent* _gethostbyname(const
char* name);
353 WINPR_API
int _gethostname(
char* name,
int namelen);
354 WINPR_API struct servent* _getservbyport(
int port, const
char* proto);
355 WINPR_API struct servent* _getservbyname(const
char* name, const
char* proto);
356 WINPR_API struct protoent* _getprotobynumber(
int number);
357 WINPR_API struct protoent* _getprotobyname(const
char* name);
364 #define WSASocket WSASocketW
366 #define WSASocket WSASocketA
371 WINPR_PRAGMA_DIAG_POP