FreeRDP
Loading...
Searching...
No Matches
udpsocket.c
1
17
18/* Required for struct in6_pktinfo before system headers */
19#if defined(__linux__) && !defined(_GNU_SOURCE)
20#define _GNU_SOURCE // NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
21#endif
22#if defined(__APPLE__) && !defined(__APPLE_USE_RFC_3542)
23#define __APPLE_USE_RFC_3542 // NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
24#endif
25
26#include <errno.h>
27#include <string.h>
28
29#include <winpr/assert.h>
30#include <winpr/cast.h>
31#include <winpr/winsock.h>
32
33/* From mstcpip.h; fails to compile with NONAMELESSUNION */
34#if defined(_WIN32) && !defined(SIO_UDP_CONNRESET)
35#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR, 12)
36#endif
37#if defined(_WIN32) && !defined(SIO_UDP_NETRESET)
38#define SIO_UDP_NETRESET _WSAIOW(IOC_VENDOR, 15)
39#endif
40
41#if !defined(_WIN32)
42#include <fcntl.h>
43#include <netdb.h>
44#include <sys/socket.h>
45#include <sys/uio.h>
46#include <netinet/in.h>
47#endif
48
49/* Sockets bound to the unspecified address can determine the local address used for
50 * each datagram, allowing replies to be sent from the address the client contacted. */
51/* NetBSD has IP_PKTINFO, but its struct in_pktinfo lacks the ipi_spec_dst used for sending. */
52#if !defined(_WIN32) && defined(IP_PKTINFO) && !defined(__NetBSD__)
53#define UDPLISTENER_LOCAL_ADDRESS_IPV4
54#endif
55#if !defined(_WIN32) && defined(IPV6_RECVPKTINFO) && defined(IPV6_PKTINFO)
56#define UDPLISTENER_LOCAL_ADDRESS_IPV6
57#endif
58
59#if defined(_WIN32) && !defined(WSA_FLAG_NO_HANDLE_INHERIT)
60#define WSA_FLAG_NO_HANDLE_INHERIT 0x80
61#endif
62
63#include <freerdp/log.h>
64
65#include "udplistener_internal.h"
66
67#define TAG FREERDP_TAG("core.udplistener")
68
69WINPR_ATTR_NODISCARD
70BOOL udpsocket_address_equal(const struct sockaddr_storage* a, const struct sockaddr* b,
71 size_t blen)
72{
73 WINPR_ASSERT(a);
74 WINPR_ASSERT(b);
75 if ((blen < sizeof(b->sa_family)) || (a->ss_family != b->sa_family))
76 return FALSE;
77 if (a->ss_family == AF_INET)
78 {
79 const struct sockaddr_in* x = WINPR_PACKED_ALIGN_CAST(const struct sockaddr_in*, a);
80 const struct sockaddr_in* y = WINPR_PACKED_ALIGN_CAST(const struct sockaddr_in*, b);
81 return (blen >= sizeof(*y)) && (x->sin_port == y->sin_port) &&
82 (memcmp(&x->sin_addr, &y->sin_addr, sizeof(x->sin_addr)) == 0);
83 }
84 if (a->ss_family == AF_INET6)
85 {
86 const struct sockaddr_in6* x = WINPR_PACKED_ALIGN_CAST(const struct sockaddr_in6*, a);
87 const struct sockaddr_in6* y = WINPR_PACKED_ALIGN_CAST(const struct sockaddr_in6*, b);
88 /* Link-local addresses on different interfaces are distinct. */
89 return (blen >= sizeof(*y)) && (x->sin6_port == y->sin6_port) &&
90 (x->sin6_scope_id == y->sin6_scope_id) &&
91 (memcmp(&x->sin6_addr, &y->sin6_addr, sizeof(x->sin6_addr)) == 0);
92 }
93 return FALSE;
94}
95
96void udpsocket_unmap_address(const struct sockaddr* addr, size_t addrlen,
97 struct sockaddr_storage* out, size_t* outlen)
98{
99 WINPR_ASSERT(addr);
100 WINPR_ASSERT(addrlen <= sizeof(*out));
101
102 memcpy(out, addr, addrlen);
103 *outlen = addrlen;
104 if ((addr->sa_family != AF_INET6) || (addrlen < sizeof(struct sockaddr_in6)))
105 return;
106 const struct sockaddr_in6* v6 = WINPR_PACKED_ALIGN_CAST(const struct sockaddr_in6*, addr);
107 if (!IN6_IS_ADDR_V4MAPPED(&v6->sin6_addr))
108 return;
109
110 struct sockaddr_in v4 = WINPR_C_ARRAY_INIT;
111 v4.sin_family = AF_INET;
112 v4.sin_port = v6->sin6_port;
113 memcpy(&v4.sin_addr, &v6->sin6_addr.s6_addr[12], sizeof(v4.sin_addr));
114 memset(out, 0, sizeof(*out));
115 memcpy(out, &v4, sizeof(v4));
116 *outlen = sizeof(v4);
117}
118
119/* Prevent listener sockets from leaking into exec'd child processes; children that
120 * fork without exec'ing retain them (see udp.h). Use SOCK_CLOEXEC where available
121 * to ensure atomicity and prevent race conditions with other threads calling exec(). */
122void udpsocket_set_no_inherit(SOCKET sockfd)
123{
124#if defined(_WIN32)
125 /* May fail under a layered service provider; socket remains usable. */
126 if (!SetHandleInformation((HANDLE)sockfd, HANDLE_FLAG_INHERIT, 0))
127 WLog_WARN(TAG, "unable to prevent child processes from acquiring a socket");
128#else
129 const int flags = fcntl((int)sockfd, F_GETFD);
130 if ((flags < 0) || (fcntl((int)sockfd, F_SETFD, flags | FD_CLOEXEC) != 0))
131 WLog_WARN(TAG, "failed to set close-on-exec for the socket");
132#endif
133}
134
135/* Use the no-inherit flag during creation where supported to prevent race conditions
136 * with other threads starting processes. */
137SOCKET udpsocket_new(int family, int type, int protocol)
138{
139#if defined(_WIN32)
140 SOCKET sockfd = WSASocketW(family, type, protocol, nullptr, 0,
141 WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
142 /* Windows 7 without SP does not support this flag. */
143 if ((sockfd == INVALID_SOCKET) && (WSAGetLastError() == WSAEINVAL))
144 sockfd = WSASocketW(family, type, protocol, nullptr, 0, WSA_FLAG_OVERLAPPED);
145#else
146 SOCKET sockfd = _socket(family, type | UDPLISTENER_SOCK_CLOEXEC, protocol);
147#endif
148 if (sockfd != INVALID_SOCKET)
149 udpsocket_set_no_inherit(sockfd);
150 return sockfd;
151}
152
153SOCKET udpsocket_bind(const struct sockaddr* addr, size_t addrlen)
154{
155 WINPR_ASSERT(addr);
156
157 SOCKET sockfd = udpsocket_new(addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
158 if (sockfd == INVALID_SOCKET)
159 return INVALID_SOCKET;
160
161 const int on = 1;
162 if ((addr->sa_family == AF_INET6) &&
163 (_setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&on, sizeof(on)) != 0))
164 WLog_WARN(TAG, "failed to set IPV6_V6ONLY via setsockopt()");
165#if defined(_WIN32)
166 /* Prevent other processes under the same user from binding to the port and
167 * intercepting datagrams. */
168 if (_setsockopt(sockfd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (const char*)&on, sizeof(on)) != 0)
169 {
170 closesocket(sockfd);
171 return INVALID_SOCKET;
172 }
173#endif
174 /* Avoid SO_REUSEADDR to prevent multiple sockets from competing for datagrams, as
175 * there is no mechanism to route them across processes. Multi-process servers will
176 * fail here and fallback to TCP unless relaying is used (see udp.h). */
177 /* Smaller buffers may increase retransmissions; see RDPUDP_RECEIVE_BUFFER. */
178 const UINT32 rcvbuf = UDPLISTENER_RECEIVE_BUFFER;
179 if (_setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (const char*)&rcvbuf, sizeof(rcvbuf)) != 0)
180 WLog_WARN(TAG, "failed to set SO_RCVBUF via setsockopt()");
181
182 if (_bind(sockfd, addr, WINPR_ASSERTING_INT_CAST(int, addrlen)) != 0)
183 {
184 /* e.g. port already in use; clients will fallback to TCP. */
185 WLog_WARN(TAG, "failed to bind UDP socket for RDP-UDP, error %d", WSAGetLastError());
186 closesocket(sockfd);
187 return INVALID_SOCKET;
188 }
189 return sockfd;
190}
191
192void udpsocket_ignore_icmp_errors(SOCKET sockfd)
193{
194#if defined(_WIN32)
195 /* Prevent ICMP "port unreachable" messages from causing subsequent receives to fail. */
196 BOOL report = FALSE;
197 DWORD bytes = 0;
198 if (WSAIoctl(sockfd, SIO_UDP_CONNRESET, &report, sizeof(report), nullptr, 0, &bytes, nullptr,
199 nullptr) != 0)
200 WLog_DBG(TAG, "unable to disable SIO_UDP_CONNRESET");
201 /* Same for ICMP "time exceeded". */
202 if (WSAIoctl(sockfd, SIO_UDP_NETRESET, &report, sizeof(report), nullptr, 0, &bytes, nullptr,
203 nullptr) != 0)
204 WLog_DBG(TAG, "unable to disable SIO_UDP_NETRESET");
205#else
206 WINPR_UNUSED(sockfd);
207#endif
208}
209
210BOOL udpsocket_is_message_socket(SOCKET sockfd)
211{
212 int type = 0;
213 int typeLength = sizeof(type);
214 return (_getsockopt(sockfd, SOL_SOCKET, SO_TYPE, (char*)&type, &typeLength) == 0) &&
215 ((type == SOCK_SEQPACKET) || (type == SOCK_DGRAM));
216}
217
218WINPR_ATTR_NODISCARD
219static BOOL udpsocket_is_any_address(const struct sockaddr_storage* addr)
220{
221 WINPR_ASSERT(addr);
222 if (addr->ss_family == AF_INET)
223 {
224 const struct sockaddr_in* in = (const struct sockaddr_in*)addr;
225 return in->sin_addr.s_addr == htonl(INADDR_ANY);
226 }
227 if (addr->ss_family == AF_INET6)
228 {
229 const struct sockaddr_in6* in6 = (const struct sockaddr_in6*)addr;
230 return IN6_IS_ADDR_UNSPECIFIED(&in6->sin6_addr);
231 }
232 return FALSE;
233}
234
235void udpsocket_enable_local_address(udpListenerSocket* sock)
236{
237 WINPR_ASSERT(sock);
238
239 if (!udpsocket_is_any_address(&sock->addr))
240 return;
241
242 int rc = -1;
243#if defined(UDPLISTENER_LOCAL_ADDRESS_IPV4) || defined(UDPLISTENER_LOCAL_ADDRESS_IPV6)
244 const int on = 1;
245#endif
246#if defined(UDPLISTENER_LOCAL_ADDRESS_IPV4)
247 if (sock->addr.ss_family == AF_INET)
248 rc = _setsockopt(sock->sockfd, IPPROTO_IP, IP_PKTINFO, (const char*)&on, sizeof(on));
249#endif
250#if defined(UDPLISTENER_LOCAL_ADDRESS_IPV6)
251 if (sock->addr.ss_family == AF_INET6)
252 rc =
253 _setsockopt(sock->sockfd, IPPROTO_IPV6, IPV6_RECVPKTINFO, (const char*)&on, sizeof(on));
254#endif
255 sock->localAddress = (rc == 0);
256 if (!sock->localAddress)
257 WLog_WARN(TAG,
258 "a socket bound to any address cannot determine the destination of a datagram. "
259 "With more than one address, a reply can go out from an incorrect address");
260}
261
262int udpsocket_receive(const udpListenerSocket* sock, BYTE* data, size_t size,
263 struct sockaddr_storage* addr, int* addrlen, udpLocalAddress* local)
264{
265 WINPR_ASSERT(sock);
266 WINPR_ASSERT(data);
267 WINPR_ASSERT(addr);
268 WINPR_ASSERT(addrlen);
269 WINPR_ASSERT(local);
270
271 memset(local, 0, sizeof(*local));
272#if defined(UDPLISTENER_LOCAL_ADDRESS_IPV4) || defined(UDPLISTENER_LOCAL_ADDRESS_IPV6)
273 if (sock->localAddress)
274 {
275 union
276 {
277 struct cmsghdr header;
278 BYTE data[256];
279 } control;
280 memset(&control, 0, sizeof(control));
281 struct iovec iov = { .iov_base = data, .iov_len = size };
282 struct msghdr msg = WINPR_C_ARRAY_INIT;
283 msg.msg_name = addr;
284 msg.msg_namelen = WINPR_ASSERTING_INT_CAST(socklen_t, *addrlen);
285 msg.msg_iov = &iov;
286 msg.msg_iovlen = 1;
287 msg.msg_control = control.data;
288 msg.msg_controllen = sizeof(control.data);
289 const ssize_t got = recvmsg(WINPR_ASSERTING_INT_CAST(int, sock->sockfd), &msg, 0);
290 if (got < 0)
291 return -1;
292 *addrlen = WINPR_ASSERTING_INT_CAST(int, msg.msg_namelen);
293
294 for (struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
295 {
296#if defined(UDPLISTENER_LOCAL_ADDRESS_IPV4)
297 if ((cmsg->cmsg_level == IPPROTO_IP) && (cmsg->cmsg_type == IP_PKTINFO) &&
298 (cmsg->cmsg_len >= CMSG_LEN(sizeof(struct in_pktinfo))))
299 {
300 struct in_pktinfo info = WINPR_C_ARRAY_INIT;
301 memcpy(&info, CMSG_DATA(cmsg), sizeof(info));
302 local->family = AF_INET;
303 local->ipv4 = info.ipi_addr;
304 local->interfaceIndex = WINPR_ASSERTING_INT_CAST(UINT32, info.ipi_ifindex);
305 local->valid = TRUE;
306 }
307#endif
308#if defined(UDPLISTENER_LOCAL_ADDRESS_IPV6)
309 if ((cmsg->cmsg_level == IPPROTO_IPV6) && (cmsg->cmsg_type == IPV6_PKTINFO) &&
310 (cmsg->cmsg_len >= CMSG_LEN(sizeof(struct in6_pktinfo))))
311 {
312 struct in6_pktinfo info = WINPR_C_ARRAY_INIT;
313 memcpy(&info, CMSG_DATA(cmsg), sizeof(info));
314 local->family = AF_INET6;
315 local->ipv6 = info.ipi6_addr;
316 local->interfaceIndex = WINPR_ASSERTING_INT_CAST(UINT32, info.ipi6_ifindex);
317 local->valid = TRUE;
318 }
319#endif
320 }
321 return WINPR_ASSERTING_INT_CAST(int, got);
322 }
323#endif
324 return _recvfrom(sock->sockfd, (char*)data, WINPR_ASSERTING_INT_CAST(int, size), 0,
325 (struct sockaddr*)addr, addrlen);
326}
327
328BOOL udpsocket_send_from(SOCKET sockfd, const struct sockaddr_storage* to, size_t tolen,
329 const udpLocalAddress* local, const BYTE* data, size_t length)
330{
331 WINPR_ASSERT(to);
332 WINPR_ASSERT(local);
333 WINPR_ASSERT(data);
334
335#if defined(UDPLISTENER_LOCAL_ADDRESS_IPV4) || defined(UDPLISTENER_LOCAL_ADDRESS_IPV6)
336 union
337 {
338 struct cmsghdr header;
339 BYTE data[256];
340 } control;
341 memset(&control, 0, sizeof(control));
342 struct iovec iov = { .iov_base = WINPR_CAST_CONST_PTR_AWAY(data, void*), .iov_len = length };
343 struct msghdr msg = WINPR_C_ARRAY_INIT;
344 msg.msg_name = WINPR_CAST_CONST_PTR_AWAY(to, void*);
345 msg.msg_namelen = WINPR_ASSERTING_INT_CAST(socklen_t, tolen);
346 msg.msg_iov = &iov;
347 msg.msg_iovlen = 1;
348 msg.msg_control = control.data;
349 msg.msg_controllen = sizeof(control.data);
350 struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
351 if (!cmsg)
352 {
353 errno = EINVAL; /* Caller lets the system pick the address */
354 return FALSE;
355 }
356
357 BOOL known = FALSE;
358#if defined(UDPLISTENER_LOCAL_ADDRESS_IPV4)
359 if (local->family == AF_INET)
360 {
361 /* The route picks the interface */
362 struct in_pktinfo info = WINPR_C_ARRAY_INIT;
363 info.ipi_spec_dst = local->ipv4;
364 cmsg->cmsg_level = IPPROTO_IP;
365 cmsg->cmsg_type = IP_PKTINFO;
366 cmsg->cmsg_len = CMSG_LEN(sizeof(info));
367 memcpy(CMSG_DATA(cmsg), &info, sizeof(info));
368 msg.msg_controllen = CMSG_SPACE(sizeof(info));
369 known = TRUE;
370 }
371#endif
372#if defined(UDPLISTENER_LOCAL_ADDRESS_IPV6)
373 if (local->family == AF_INET6)
374 {
375 /* Link-local addresses are interface-specific. For others, the route picks the interface,
376 * as interfaces may disappear and return with a new index. */
377 struct in6_pktinfo info = WINPR_C_ARRAY_INIT;
378 info.ipi6_addr = local->ipv6;
379 if (IN6_IS_ADDR_LINKLOCAL(&local->ipv6))
380 info.ipi6_ifindex = local->interfaceIndex;
381 cmsg->cmsg_level = IPPROTO_IPV6;
382 cmsg->cmsg_type = IPV6_PKTINFO;
383 cmsg->cmsg_len = CMSG_LEN(sizeof(info));
384 memcpy(CMSG_DATA(cmsg), &info, sizeof(info));
385 msg.msg_controllen = CMSG_SPACE(sizeof(info));
386 known = TRUE;
387 }
388#endif
389 if (!known)
390 {
391 errno = EINVAL; /* Caller lets the system pick the address */
392 return FALSE;
393 }
394 return sendmsg(WINPR_ASSERTING_INT_CAST(int, sockfd), &msg, 0) >= 0;
395#else
396 WINPR_UNUSED(sockfd);
397 WINPR_UNUSED(tolen);
398 WINPR_UNUSED(length);
399 return FALSE;
400#endif
401}
402
403BOOL udpsocket_source_address_unavailable(int* error)
404{
405 WINPR_ASSERT(error);
406#if !defined(_WIN32)
407 /* Interface for the address is gone */
408 const int systemError = errno;
409 const BOOL gone = (systemError == ENODEV) || (systemError == ENXIO);
410#else
411 const BOOL gone = FALSE;
412#endif
413 *error = WSAGetLastError();
414 return gone || (*error == WSAEADDRNOTAVAIL) || (*error == WSAEINVAL);
415}
416
417BOOL udpsocket_peer_closed(void)
418{
419 /* SOCK_DGRAM pairs don't report peer closure; only sends fail */
420#if defined(_WIN32)
421 const int error = WSAGetLastError();
422 return (error == WSAECONNRESET) || (error == WSAECONNREFUSED) || (error == WSAENOTCONN);
423#else
424 const int error = errno;
425 return (error == ECONNREFUSED) || (error == ENOTCONN) || (error == EPIPE) ||
426 (error == ECONNRESET);
427#endif
428}
429
430BOOL udpsocket_message_pair(SOCKET pair[2])
431{
432 WINPR_ASSERT(pair);
433
434 pair[0] = INVALID_SOCKET;
435 pair[1] = INVALID_SOCKET;
436#if defined(_WIN32)
437 /* Winsock lacks socketpair(); use two loopback sockets that other processes
438 * cannot share */
439 struct sockaddr_in addr[2] = WINPR_C_ARRAY_INIT;
440 for (size_t x = 0; x < 2; x++)
441 {
442 int length = sizeof(addr[x]);
443 addr[x].sin_family = AF_INET;
444 addr[x].sin_addr.s_addr = htonl(INADDR_LOOPBACK);
445 pair[x] = udpsocket_new(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
446 /* Prevent other processes from binding the same port to intercept traffic */
447 const BOOL exclusive = TRUE;
448 if ((pair[x] == INVALID_SOCKET) ||
449 (_setsockopt(pair[x], SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (const char*)&exclusive,
450 sizeof(exclusive)) != 0) ||
451 (_bind(pair[x], (const struct sockaddr*)&addr[x], sizeof(addr[x])) != 0) ||
452 (_getsockname(pair[x], (struct sockaddr*)&addr[x], &length) != 0))
453 goto fail;
454 }
455 for (size_t x = 0; x < 2; x++)
456 {
457 if (_connect(pair[x], (const struct sockaddr*)&addr[1 - x], sizeof(addr[1 - x])) != 0)
458 goto fail;
459 }
460 /* Drain any datagrams sent by other processes before connect() */
461 for (size_t x = 0; x < 2; x++)
462 {
463 u_long nonBlocking = 1;
464 if (_ioctlsocket(pair[x], FIONBIO, &nonBlocking) != 0)
465 goto fail;
466 char drop[64] = WINPR_C_ARRAY_INIT;
467 while ((_recv(pair[x], drop, sizeof(drop), 0) >= 0) || (WSAGetLastError() == WSAEMSGSIZE))
468 {
469 }
470 nonBlocking = 0;
471 if (_ioctlsocket(pair[x], FIONBIO, &nonBlocking) != 0)
472 goto fail;
473 }
474#else
475 /* Some systems (e.g. macOS) lack AF_UNIX SOCK_SEQPACKET. SOCK_DGRAM also preserves
476 * boundaries; it doesn't report peer closure, but both ends send an empty
477 * message before closing. */
478 int sv[2] = { -1, -1 };
479 if ((socketpair(AF_UNIX, SOCK_SEQPACKET | UDPLISTENER_SOCK_CLOEXEC, 0, sv) != 0) &&
480 (socketpair(AF_UNIX, SOCK_DGRAM | UDPLISTENER_SOCK_CLOEXEC, 0, sv) != 0))
481 return FALSE;
482 pair[0] = (SOCKET)sv[0];
483 pair[1] = (SOCKET)sv[1];
484 udpsocket_set_no_inherit(pair[0]);
485 udpsocket_set_no_inherit(pair[1]);
486#endif
487
488 return TRUE;
489
490#if defined(_WIN32)
491fail:
492 for (size_t x = 0; x < 2; x++)
493 {
494 if (pair[x] != INVALID_SOCKET)
495 closesocket(pair[x]);
496 pair[x] = INVALID_SOCKET;
497 }
498 return FALSE;
499#endif
500}
501
502WINPR_ATTR_NODISCARD
503BOOL freerdp_udp_socket_pair(int fds[2])
504{
505 WINPR_ASSERT(fds);
506
507 SOCKET pair[2] = { INVALID_SOCKET, INVALID_SOCKET };
508 if (!udpsocket_message_pair(pair))
509 return FALSE;
510
511 /* All client data passes through here; small buffers only increase resends */
512 const UINT32 size = UDPLISTENER_RECEIVE_BUFFER;
513 for (size_t x = 0; x < 2; x++)
514 {
515 if ((_setsockopt(pair[x], SOL_SOCKET, SO_SNDBUF, (const char*)&size, sizeof(size)) != 0) ||
516 (_setsockopt(pair[x], SOL_SOCKET, SO_RCVBUF, (const char*)&size, sizeof(size)) != 0))
517 WLog_DBG(TAG, "failed to set the buffer sizes of a socket pair");
518 fds[x] = (int)pair[x];
519 }
520 return TRUE;
521}
522
523void udpsocket_poll_set(udpPollFd* fd, SOCKET sockfd)
524{
525 WINPR_ASSERT(fd);
526#if defined(_WIN32)
527 fd->fd = sockfd;
528#else
529 fd->fd = WINPR_ASSERTING_INT_CAST(int, sockfd);
530#endif
531 fd->events = POLLIN;
532 fd->revents = 0;
533}
534
535int udpsocket_poll(udpPollFd* fds, size_t count)
536{
537#if defined(_WIN32)
538 return WSAPoll(fds, WINPR_ASSERTING_INT_CAST(ULONG, count), -1);
539#else
540 return poll(fds, WINPR_ASSERTING_INT_CAST(nfds_t, count), -1);
541#endif
542}