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;
193 WINPR_PRAGMA_DIAG_PUSH
194 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
196 #define _IFF_UP 0x00000001
197 #define _IFF_BROADCAST 0x00000002
198 #define _IFF_LOOPBACK 0x00000004
199 #define _IFF_POINTTOPOINT 0x00000008
200 #define _IFF_MULTICAST 0x00000010
202 WINPR_PRAGMA_DIAG_POP
213 #define MAX_PROTOCOL_CHAIN 7
214 #define WSAPROTOCOL_LEN 255
219 DWORD ChainEntries[MAX_PROTOCOL_CHAIN];
224 DWORD dwServiceFlags1;
225 DWORD dwServiceFlags2;
226 DWORD dwServiceFlags3;
227 DWORD dwServiceFlags4;
228 DWORD dwProviderFlags;
230 DWORD dwCatalogEntryId;
238 int iProtocolMaxOffset;
239 int iNetworkByteOrder;
242 DWORD dwProviderReserved;
243 CHAR szProtocol[WSAPROTOCOL_LEN + 1];
248 DWORD dwServiceFlags1;
249 DWORD dwServiceFlags2;
250 DWORD dwServiceFlags3;
251 DWORD dwServiceFlags4;
252 DWORD dwProviderFlags;
254 DWORD dwCatalogEntryId;
262 int iProtocolMaxOffset;
263 int iNetworkByteOrder;
266 DWORD dwProviderReserved;
267 WCHAR szProtocol[WSAPROTOCOL_LEN + 1];
270 typedef void(CALLBACK* LPWSAOVERLAPPED_COMPLETION_ROUTINE)(DWORD dwError, DWORD cbTransferred,
274 typedef UINT32 GROUP;
275 #define SG_UNCONSTRAINED_GROUP 0x01
276 #define SG_CONSTRAINED_GROUP 0x02
278 #define SIO_GET_INTERFACE_LIST _IOR('t', 127, ULONG)
279 #define SIO_GET_INTERFACE_LIST_EX _IOR('t', 126, ULONG)
280 #define SIO_SET_MULTICAST_FILTER _IOW('t', 125, ULONG)
281 #define SIO_GET_MULTICAST_FILTER _IOW('t', 124 | IOC_IN, ULONG)
282 #define SIOCSIPMSFILTER SIO_SET_MULTICAST_FILTER
283 #define SIOCGIPMSFILTER SIO_GET_MULTICAST_FILTER
286 #define WSAPROTOCOL_INFO WSAPROTOCOL_INFOW
287 #define LPWSAPROTOCOL_INFO LPWSAPROTOCOL_INFOW
289 #define WSAPROTOCOL_INFO WSAPROTOCOL_INFOA
290 #define LPWSAPROTOCOL_INFO LPWSAPROTOCOL_INFOA
298 WINPR_API
int WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
299 WINPR_API
int WSACleanup(
void);
301 WINPR_API
void WSASetLastError(
int iError);
302 WINPR_API
int WSAGetLastError(
void);
304 WINPR_API BOOL WSACloseEvent(HANDLE hEvent);
306 WINPR_ATTR_MALLOC(WSACloseEvent, 1)
307 WINPR_API HANDLE WSACreateEvent(
void);
308 WINPR_API BOOL WSASetEvent(HANDLE hEvent);
309 WINPR_API BOOL WSAResetEvent(HANDLE hEvent);
311 WINPR_API
int WSAEventSelect(SOCKET s, WSAEVENT hEventObject, LONG lNetworkEvents);
313 WINPR_API DWORD WSAWaitForMultipleEvents(DWORD cEvents, const HANDLE* lphEvents, BOOL fWaitAll,
314 DWORD dwTimeout, BOOL fAlertable);
316 WINPR_API SOCKET WSASocketA(
int af,
int type,
int protocol,
LPWSAPROTOCOL_INFOA lpProtocolInfo,
317 GROUP g, DWORD dwFlags);
318 WINPR_API SOCKET WSASocketW(
int af,
int type,
int protocol,
LPWSAPROTOCOL_INFOW lpProtocolInfo,
319 GROUP g, DWORD dwFlags);
321 WINPR_API
int WSAIoctl(SOCKET s, DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
322 LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned,
324 LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
326 WINPR_API SOCKET _accept(SOCKET s, struct sockaddr* addr,
int* addrlen);
327 WINPR_API
int _bind(SOCKET s, const struct sockaddr* addr,
int namelen);
328 WINPR_API
int closesocket(SOCKET s);
329 WINPR_API
int _connect(SOCKET s, const struct sockaddr* name,
int namelen);
330 WINPR_API
int _ioctlsocket(SOCKET s,
long cmd, u_long* argp);
331 WINPR_API
int _getpeername(SOCKET s, struct sockaddr* name,
int* namelen);
332 WINPR_API
int _getsockname(SOCKET s, struct sockaddr* name,
int* namelen);
333 WINPR_API
int _getsockopt(SOCKET s,
int level,
int optname,
char* optval,
int* optlen);
334 WINPR_API u_long _htonl(u_long hostlong);
335 WINPR_API u_short _htons(u_short hostshort);
336 WINPR_API
unsigned long _inet_addr(const
char* cp);
337 WINPR_API
char* _inet_ntoa(struct in_addr in);
338 WINPR_API
int _listen(SOCKET s,
int backlog);
339 WINPR_API u_long _ntohl(u_long netlong);
340 WINPR_API u_short _ntohs(u_short netshort);
341 WINPR_API
int _recv(SOCKET s,
char* buf,
int len,
int flags);
342 WINPR_API
int _recvfrom(SOCKET s,
char* buf,
int len,
int flags, struct sockaddr* from,
344 WINPR_API
int _select(
int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds,
345 const struct timeval* timeout);
346 WINPR_API
int _send(SOCKET s, const
char* buf,
int len,
int flags);
347 WINPR_API
int _sendto(SOCKET s, const
char* buf,
int len,
int flags, const struct sockaddr* to,
349 WINPR_API
int _setsockopt(SOCKET s,
int level,
int optname, const
char* optval,
int optlen);
350 WINPR_API
int _shutdown(SOCKET s,
int how);
351 WINPR_API SOCKET _socket(
int af,
int type,
int protocol);
352 WINPR_API struct hostent* _gethostbyaddr(const
char* addr,
int len,
int type);
353 WINPR_API struct hostent* _gethostbyname(const
char* name);
354 WINPR_API
int _gethostname(
char* name,
int namelen);
355 WINPR_API struct servent* _getservbyport(
int port,
357 WINPR_API struct servent* _getservbyname(const
char* name,
359 WINPR_API struct protoent* _getprotobynumber(
int number);
360 WINPR_API struct protoent* _getprotobyname(const
char* name);
367 #define WSASocket WSASocketW
369 #define WSASocket WSASocketA
374 WINPR_PRAGMA_DIAG_POP