Rizin
unix-like reverse engineering framework and cli tools
winsock.c File Reference
#include <assert.h>
#include <stdlib.h>
#include "uv.h"
#include "internal.h"

Go to the source code of this file.

Functions

static BOOL uv_get_extension_function (SOCKET socket, GUID guid, void **target)
 
BOOL uv_get_acceptex_function (SOCKET socket, LPFN_ACCEPTEX *target)
 
BOOL uv_get_connectex_function (SOCKET socket, LPFN_CONNECTEX *target)
 
void uv_winsock_init (void)
 
int uv_ntstatus_to_winsock_error (NTSTATUS status)
 
int WSAAPI uv_wsarecv_workaround (SOCKET socket, WSABUF *buffers, DWORD buffer_count, DWORD *bytes, DWORD *flags, WSAOVERLAPPED *overlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine)
 
int WSAAPI uv_wsarecvfrom_workaround (SOCKET socket, WSABUF *buffers, DWORD buffer_count, DWORD *bytes, DWORD *flags, struct sockaddr *addr, int *addr_len, WSAOVERLAPPED *overlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine)
 
int WSAAPI uv_msafd_poll (SOCKET socket, AFD_POLL_INFO *info_in, AFD_POLL_INFO *info_out, OVERLAPPED *overlapped)
 
int uv__convert_to_localhost_if_unspecified (const struct sockaddr *addr, struct sockaddr_storage *storage)
 

Variables

int uv_tcp_non_ifs_lsp_ipv4
 
int uv_tcp_non_ifs_lsp_ipv6
 
struct sockaddr_in uv_addr_ip4_any_
 
struct sockaddr_in6 uv_addr_ip6_any_
 

Function Documentation

◆ uv__convert_to_localhost_if_unspecified()

int uv__convert_to_localhost_if_unspecified ( const struct sockaddr addr,
struct sockaddr_storage *  storage 
)

Definition at line 547 of file winsock.c.

548  {
549  struct sockaddr_in* dest4;
550  struct sockaddr_in6* dest6;
551 
552  if (addr == NULL)
553  return UV_EINVAL;
554 
555  switch (addr->sa_family) {
556  case AF_INET:
557  dest4 = (struct sockaddr_in*) storage;
558  memcpy(dest4, addr, sizeof(*dest4));
559  if (dest4->sin_addr.s_addr == 0)
560  dest4->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
561  return 0;
562  case AF_INET6:
563  dest6 = (struct sockaddr_in6*) storage;
564  memcpy(dest6, addr, sizeof(*dest6));
565  if (memcmp(&dest6->sin6_addr,
567  sizeof(uv_addr_ip6_any_.sin6_addr)) == 0) {
568  struct in6_addr init_sin6_addr = IN6ADDR_LOOPBACK_INIT;
569  dest6->sin6_addr = init_sin6_addr;
570  }
571  return 0;
572  default:
573  return UV_EINVAL;
574  }
575 }
#define NULL
Definition: cris-opc.c:27
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define AF_INET
Definition: sftypes.h:287
#define AF_INET6
Definition: sftypes.h:295
in_addr_t s_addr
Definition: sftypes.h:337
struct in6_addr sin6_addr
Definition: sftypes.h:375
struct in_addr sin_addr
Definition: sftypes.h:344
struct sockaddr_in6 uv_addr_ip6_any_
Definition: winsock.c:35
static int addr
Definition: z80asm.c:58

References addr, AF_INET, AF_INET6, memcpy(), NULL, in_addr::s_addr, sockaddr_in6::sin6_addr, sockaddr_in::sin_addr, and uv_addr_ip6_any_.

Referenced by uv__udp_try_send(), and uv_tcp_try_connect().

◆ uv_get_acceptex_function()

BOOL uv_get_acceptex_function ( SOCKET  socket,
LPFN_ACCEPTEX target 
)

Definition at line 65 of file winsock.c.

65  {
66  const GUID wsaid_acceptex = WSAID_ACCEPTEX;
67  return uv_get_extension_function(socket, wsaid_acceptex, (void**)target);
68 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd socket
Definition: sflib.h:79
#define WSAID_ACCEPTEX
Definition: win.h:109
static BOOL uv_get_extension_function(SOCKET socket, GUID guid, void **target)
Definition: winsock.c:41

References socket, uv_get_extension_function(), and WSAID_ACCEPTEX.

Referenced by uv_tcp_listen().

◆ uv_get_connectex_function()

BOOL uv_get_connectex_function ( SOCKET  socket,
LPFN_CONNECTEX target 
)

Definition at line 71 of file winsock.c.

71  {
72  const GUID wsaid_connectex = WSAID_CONNECTEX;
73  return uv_get_extension_function(socket, wsaid_connectex, (void**)target);
74 }
#define WSAID_CONNECTEX
Definition: win.h:113

References socket, uv_get_extension_function(), and WSAID_CONNECTEX.

Referenced by uv_tcp_try_connect().

◆ uv_get_extension_function()

static BOOL uv_get_extension_function ( SOCKET  socket,
GUID  guid,
void **  target 
)
static

Definition at line 41 of file winsock.c.

42  {
43  int result;
44  DWORD bytes;
45 
46  result = WSAIoctl(socket,
47  SIO_GET_EXTENSION_FUNCTION_POINTER,
48  &guid,
49  sizeof(guid),
50  (void*)target,
51  sizeof(*target),
52  &bytes,
53  NULL,
54  NULL);
55 
56  if (result == SOCKET_ERROR) {
57  *target = NULL;
58  return FALSE;
59  } else {
60  return TRUE;
61  }
62 }
static ut8 bytes[32]
Definition: asm_arc.c:23
#define TRUE
Definition: mybfd.h:103
#define FALSE
Definition: mybfd.h:102
DWORD

References bytes, DWORD, FALSE, NULL, socket, and TRUE.

Referenced by uv_get_acceptex_function(), and uv_get_connectex_function().

◆ uv_msafd_poll()

int WSAAPI uv_msafd_poll ( SOCKET  socket,
AFD_POLL_INFO info_in,
AFD_POLL_INFO info_out,
OVERLAPPED *  overlapped 
)

Definition at line 461 of file winsock.c.

462  {
463  IO_STATUS_BLOCK iosb;
464  IO_STATUS_BLOCK* iosb_ptr;
465  HANDLE event = NULL;
466  void* apc_context;
468  DWORD error;
469 
470  if (overlapped != NULL) {
471  /* Overlapped operation. */
472  iosb_ptr = (IO_STATUS_BLOCK*) &overlapped->Internal;
473  event = overlapped->hEvent;
474 
475  /* Do not report iocp completion if hEvent is tagged. */
476  if ((uintptr_t) event & 1) {
477  event = (HANDLE)((uintptr_t) event & ~(uintptr_t) 1);
478  apc_context = NULL;
479  } else {
480  apc_context = overlapped;
481  }
482 
483  } else {
484  /* Blocking operation. */
485  iosb_ptr = &iosb;
486  event = CreateEvent(NULL, FALSE, FALSE, NULL);
487  if (event == NULL) {
488  return SOCKET_ERROR;
489  }
490  apc_context = NULL;
491  }
492 
493  iosb_ptr->Status = STATUS_PENDING;
495  event,
496  NULL,
497  apc_context,
498  iosb_ptr,
500  info_in,
501  sizeof *info_in,
502  info_out,
503  sizeof *info_out);
504 
505  if (overlapped == NULL) {
506  /* If this is a blocking operation, wait for the event to become signaled,
507  * and then grab the real status from the io status block. */
508  if (status == STATUS_PENDING) {
509  DWORD r = WaitForSingleObject(event, INFINITE);
510 
511  if (r == WAIT_FAILED) {
512  DWORD saved_error = GetLastError();
513  CloseHandle(event);
514  WSASetLastError(saved_error);
515  return SOCKET_ERROR;
516  }
517 
518  status = iosb.Status;
519  }
520 
521  CloseHandle(event);
522  }
523 
524  switch (status) {
525  case STATUS_SUCCESS:
526  error = ERROR_SUCCESS;
527  break;
528 
529  case STATUS_PENDING:
530  error = WSA_IO_PENDING;
531  break;
532 
533  default:
535  break;
536  }
537 
538  WSASetLastError(error);
539 
540  if (error == ERROR_SUCCESS) {
541  return 0;
542  } else {
543  return SOCKET_ERROR;
544  }
545 }
#define r
Definition: crypto_rc6.c:12
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
_W64 unsigned int uintptr_t
NTSTATUS Status
Definition: winapi.h:4165
void error(const char *msg)
Definition: untgz.c:593
LONG NTSTATUS
Definition: win.h:198
sNtDeviceIoControlFile pNtDeviceIoControlFile
Definition: winapi.c:31
#define STATUS_PENDING
Definition: winapi.h:120
#define STATUS_SUCCESS
Definition: winapi.h:68
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
DWORD * HANDLE
int uv_ntstatus_to_winsock_error(NTSTATUS status)
Definition: winsock.c:137
#define IOCTL_AFD_POLL
Definition: winsock.h:154

References DWORD, error(), FALSE, HANDLE, if(), IOCTL_AFD_POLL, NULL, pNtDeviceIoControlFile, r, socket, status, _IO_STATUS_BLOCK::Status, STATUS_PENDING, STATUS_SUCCESS, and uv_ntstatus_to_winsock_error().

Referenced by uv__fast_poll_submit_poll_req(), and uv_poll_close().

◆ uv_ntstatus_to_winsock_error()

int uv_ntstatus_to_winsock_error ( NTSTATUS  status)

Definition at line 137 of file winsock.c.

137  {
138  switch (status) {
139  case STATUS_SUCCESS:
140  return ERROR_SUCCESS;
141 
142  case STATUS_PENDING:
143  return ERROR_IO_PENDING;
144 
147  return WSAENOTSOCK;
148 
153  case STATUS_NO_MEMORY:
157  return WSAENOBUFS;
158 
162  return WSAEADDRINUSE;
163 
164  case STATUS_LINK_TIMEOUT:
165  case STATUS_IO_TIMEOUT:
166  case STATUS_TIMEOUT:
167  return WSAETIMEDOUT;
168 
170  return WSAEDISCON;
171 
174  case STATUS_LINK_FAILED:
178  return WSAECONNRESET;
179 
183  return WSAECONNABORTED;
184 
188  return WSAENETUNREACH;
189 
191  return WSAEHOSTUNREACH;
192 
193  case STATUS_CANCELLED:
195  return WSAEINTR;
196 
199  return WSAEMSGSIZE;
200 
203  return WSAEFAULT;
204 
207  return WSAEWOULDBLOCK;
208 
210  case STATUS_NETWORK_BUSY:
212  case STATUS_NO_SUCH_FILE:
216  return WSAENETDOWN;
217 
219  return WSAENOTCONN;
220 
223  return WSAECONNREFUSED;
224 
226  return WSAESHUTDOWN;
227 
231  return WSAEADDRNOTAVAIL;
232 
235  return WSAEOPNOTSUPP;
236 
238  return WSAEACCES;
239 
240  default:
241  if ((status & (FACILITY_NTWIN32 << 16)) == (FACILITY_NTWIN32 << 16) &&
242  (status & (ERROR_SEVERITY_ERROR | ERROR_SEVERITY_WARNING))) {
243  /* It's a windows error that has been previously mapped to an ntstatus
244  * code. */
245  return (DWORD) (status & 0xffff);
246  } else {
247  /* The default fallback for unmappable ntstatus codes. */
248  return WSAEINVAL;
249  }
250  }
251 }
#define STATUS_TIMEOUT
Definition: winapi.h:116
#define STATUS_PIPE_DISCONNECTED
Definition: winapi.h:1376
#define STATUS_INVALID_ADDRESS
Definition: winapi.h:1956
#define STATUS_INVALID_HANDLE
Definition: winapi.h:708
#define STATUS_QUOTA_EXCEEDED
Definition: winapi.h:944
#define STATUS_NETWORK_UNREACHABLE
Definition: winapi.h:2576
#define STATUS_DEVICE_NOT_READY
Definition: winapi.h:1324
#define STATUS_PROTOCOL_UNREACHABLE
Definition: winapi.h:2584
#define STATUS_ADDRESS_ALREADY_EXISTS
Definition: winapi.h:2376
#define STATUS_GRACEFUL_DISCONNECT
Definition: winapi.h:2556
#define STATUS_INVALID_BUFFER_SIZE
Definition: winapi.h:2360
#define STATUS_TRANSACTION_ABORTED
Definition: winapi.h:2396
#define STATUS_ACCESS_DENIED
Definition: winapi.h:812
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: winapi.h:904
#define STATUS_HOST_UNREACHABLE
Definition: winapi.h:2580
#define STATUS_WORKING_SET_QUOTA
Definition: winapi.h:1316
#define STATUS_REMOTE_DISCONNECT
Definition: winapi.h:1936
#define STATUS_INVALID_CONNECTION
Definition: winapi.h:1952
#define STATUS_PORT_UNREACHABLE
Definition: winapi.h:2588
#define STATUS_NETWORK_BUSY
Definition: winapi.h:1436
#define STATUS_IO_TIMEOUT
Definition: winapi.h:1396
#define STATUS_INVALID_NETWORK_RESPONSE
Definition: winapi.h:1452
#define STATUS_CONNECTION_RESET
Definition: winapi.h:2388
#define STATUS_NO_SUCH_DEVICE
Definition: winapi.h:732
#define STATUS_REQUEST_ABORTED
Definition: winapi.h:2592
#define STATUS_NO_MEMORY
Definition: winapi.h:768
#define STATUS_CONNECTION_ABORTED
Definition: winapi.h:2596
#define STATUS_NOT_SUPPORTED
Definition: winapi.h:1420
#define STATUS_BAD_NETWORK_PATH
Definition: winapi.h:1432
#define STATUS_CONNECTION_REFUSED
Definition: winapi.h:2552
#define STATUS_INVALID_ADDRESS_COMPONENT
Definition: winapi.h:2364
#define STATUS_ACCESS_VIOLATION
Definition: winapi.h:696
#define STATUS_NOT_IMPLEMENTED
Definition: winapi.h:684
#define STATUS_CONNECTION_DISCONNECTED
Definition: winapi.h:2384
#define FACILITY_NTWIN32
Definition: winapi.h:48
#define STATUS_NO_SUCH_FILE
Definition: winapi.h:736
#define STATUS_LINK_TIMEOUT
Definition: winapi.h:1948
#define STATUS_CONFLICTING_ADDRESSES
Definition: winapi.h:772
#define STATUS_REMOTE_NOT_LISTENING
Definition: winapi.h:1424
#define STATUS_REMOTE_RESOURCES
Definition: winapi.h:1940
#define STATUS_LINK_FAILED
Definition: winapi.h:1944
#define STATUS_BUFFER_TOO_SMALL
Definition: winapi.h:816
#define STATUS_BUFFER_OVERFLOW
Definition: winapi.h:520
#define STATUS_UNEXPECTED_NETWORK_ERROR
Definition: winapi.h:1456
#define STATUS_HOPLIMIT_EXCEEDED
Definition: winapi.h:4024
#define STATUS_LOCAL_DISCONNECT
Definition: winapi.h:1932
#define STATUS_SHARING_VIOLATION
Definition: winapi.h:940
#define STATUS_INSUFFICIENT_RESOURCES
Definition: winapi.h:1288
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: winapi.h:884
#define STATUS_CANCELLED
Definition: winapi.h:1824
#define STATUS_REQUEST_NOT_ACCEPTED
Definition: winapi.h:1504
#define STATUS_PAGEFILE_QUOTA
Definition: winapi.h:704
#define STATUS_TOO_MANY_ADDRESSES
Definition: winapi.h:2372
#define STATUS_TOO_MANY_PAGING_FILES
Definition: winapi.h:1276
#define STATUS_COMMITMENT_LIMIT
Definition: winapi.h:1876
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: winapi.h:820

References DWORD, FACILITY_NTWIN32, status, STATUS_ACCESS_DENIED, STATUS_ACCESS_VIOLATION, STATUS_ADDRESS_ALREADY_EXISTS, STATUS_BAD_NETWORK_PATH, STATUS_BUFFER_OVERFLOW, STATUS_BUFFER_TOO_SMALL, STATUS_CANCELLED, STATUS_COMMITMENT_LIMIT, STATUS_CONFLICTING_ADDRESSES, STATUS_CONNECTION_ABORTED, STATUS_CONNECTION_DISCONNECTED, STATUS_CONNECTION_REFUSED, STATUS_CONNECTION_RESET, STATUS_DEVICE_NOT_READY, STATUS_GRACEFUL_DISCONNECT, STATUS_HOPLIMIT_EXCEEDED, STATUS_HOST_UNREACHABLE, STATUS_INSUFFICIENT_RESOURCES, STATUS_INVALID_ADDRESS, STATUS_INVALID_ADDRESS_COMPONENT, STATUS_INVALID_BUFFER_SIZE, STATUS_INVALID_CONNECTION, STATUS_INVALID_HANDLE, STATUS_INVALID_NETWORK_RESPONSE, STATUS_IO_TIMEOUT, STATUS_LINK_FAILED, STATUS_LINK_TIMEOUT, STATUS_LOCAL_DISCONNECT, STATUS_NETWORK_BUSY, STATUS_NETWORK_UNREACHABLE, STATUS_NO_MEMORY, STATUS_NO_SUCH_DEVICE, STATUS_NO_SUCH_FILE, STATUS_NOT_IMPLEMENTED, STATUS_NOT_SUPPORTED, STATUS_OBJECT_NAME_NOT_FOUND, STATUS_OBJECT_PATH_NOT_FOUND, STATUS_OBJECT_TYPE_MISMATCH, STATUS_PAGEFILE_QUOTA, STATUS_PENDING, STATUS_PIPE_DISCONNECTED, STATUS_PORT_UNREACHABLE, STATUS_PROTOCOL_UNREACHABLE, STATUS_QUOTA_EXCEEDED, STATUS_REMOTE_DISCONNECT, STATUS_REMOTE_NOT_LISTENING, STATUS_REMOTE_RESOURCES, STATUS_REQUEST_ABORTED, STATUS_REQUEST_NOT_ACCEPTED, STATUS_SHARING_VIOLATION, STATUS_SUCCESS, STATUS_TIMEOUT, STATUS_TOO_MANY_ADDRESSES, STATUS_TOO_MANY_PAGING_FILES, STATUS_TRANSACTION_ABORTED, STATUS_UNEXPECTED_NETWORK_ERROR, and STATUS_WORKING_SET_QUOTA.

Referenced by uv_msafd_poll(), uv_wsarecv_workaround(), and uv_wsarecvfrom_workaround().

◆ uv_winsock_init()

void uv_winsock_init ( void  )

Definition at line 78 of file winsock.c.

78  {
79  WSADATA wsa_data;
80  int errorno;
81  SOCKET dummy;
82  WSAPROTOCOL_INFOW protocol_info;
83  int opt_len;
84 
85  /* Set implicit binding address used by connectEx */
86  if (uv_ip4_addr("0.0.0.0", 0, &uv_addr_ip4_any_)) {
87  abort();
88  }
89 
90  if (uv_ip6_addr("::", 0, &uv_addr_ip6_any_)) {
91  abort();
92  }
93 
94  /* Skip initialization in safe mode without network support */
95  if (1 == GetSystemMetrics(SM_CLEANBOOT)) return;
96 
97  /* Initialize winsock */
98  errorno = WSAStartup(MAKEWORD(2, 2), &wsa_data);
99  if (errorno != 0) {
100  uv_fatal_error(errorno, "WSAStartup");
101  }
102 
103  /* Try to detect non-IFS LSPs */
105  dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
106  if (dummy != INVALID_SOCKET) {
107  opt_len = (int) sizeof protocol_info;
108  if (getsockopt(dummy,
109  SOL_SOCKET,
110  SO_PROTOCOL_INFOW,
111  (char*) &protocol_info,
112  &opt_len) == 0) {
113  if (protocol_info.dwServiceFlags1 & XP1_IFS_HANDLES)
115  }
116  closesocket(dummy);
117  }
118 
119  /* Try to detect IPV6 support and non-IFS LSPs */
121  dummy = socket(AF_INET6, SOCK_STREAM, IPPROTO_IP);
122  if (dummy != INVALID_SOCKET) {
123  opt_len = (int) sizeof protocol_info;
124  if (getsockopt(dummy,
125  SOL_SOCKET,
126  SO_PROTOCOL_INFOW,
127  (char*) &protocol_info,
128  &opt_len) == 0) {
129  if (protocol_info.dwServiceFlags1 & XP1_IFS_HANDLES)
131  }
132  closesocket(dummy);
133  }
134 }
void uv_fatal_error(const int errorno, const char *syscall)
Definition: error.c:35
static int
Definition: sfsocketcall.h:114
@ SOCK_STREAM
Definition: sftypes.h:224
#define SOL_SOCKET
Definition: sftypes.h:427
UV_EXTERN int uv_ip4_addr(const char *ip, int port, struct sockaddr_in *addr)
Definition: uv-common.c:221
UV_EXTERN int uv_ip6_addr(const char *ip, int port, struct sockaddr_in6 *addr)
Definition: uv-common.c:232
struct sockaddr_in uv_addr_ip4_any_
Definition: winsock.c:34
int uv_tcp_non_ifs_lsp_ipv4
Definition: winsock.c:30
int uv_tcp_non_ifs_lsp_ipv6
Definition: winsock.c:31

References AF_INET, AF_INET6, int, SOCK_STREAM, socket, SOL_SOCKET, uv_addr_ip4_any_, uv_addr_ip6_any_, uv_fatal_error(), uv_ip4_addr(), uv_ip6_addr(), uv_tcp_non_ifs_lsp_ipv4, and uv_tcp_non_ifs_lsp_ipv6.

Referenced by uv_init().

◆ uv_wsarecv_workaround()

int WSAAPI uv_wsarecv_workaround ( SOCKET  socket,
WSABUF *  buffers,
DWORD  buffer_count,
DWORD bytes,
DWORD flags,
WSAOVERLAPPED *  overlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE  completion_routine 
)

Definition at line 270 of file winsock.c.

272  {
274  void* apc_context;
275  IO_STATUS_BLOCK* iosb = (IO_STATUS_BLOCK*) &overlapped->Internal;
277  DWORD error;
278 
279  if (overlapped == NULL || completion_routine != NULL) {
280  WSASetLastError(WSAEINVAL);
281  return SOCKET_ERROR;
282  }
283 
284  info.BufferArray = buffers;
285  info.BufferCount = buffer_count;
286  info.AfdFlags = AFD_OVERLAPPED;
287  info.TdiFlags = TDI_RECEIVE_NORMAL;
288 
289  if (*flags & MSG_PEEK) {
290  info.TdiFlags |= TDI_RECEIVE_PEEK;
291  }
292 
293  if (*flags & MSG_PARTIAL) {
294  info.TdiFlags |= TDI_RECEIVE_PARTIAL;
295  }
296 
297  if (!((intptr_t) overlapped->hEvent & 1)) {
298  apc_context = (void*) overlapped;
299  } else {
300  apc_context = NULL;
301  }
302 
303  iosb->Status = STATUS_PENDING;
304  iosb->Pointer = 0;
305 
307  overlapped->hEvent,
308  NULL,
309  apc_context,
310  iosb,
312  &info,
313  sizeof(info),
314  NULL,
315  0);
316 
317  *flags = 0;
318  *bytes = (DWORD) iosb->Information;
319 
320  switch (status) {
321  case STATUS_SUCCESS:
322  error = ERROR_SUCCESS;
323  break;
324 
325  case STATUS_PENDING:
326  error = WSA_IO_PENDING;
327  break;
328 
330  error = WSAEMSGSIZE;
331  break;
332 
334  error = ERROR_SUCCESS;
335  *flags = MSG_OOB;
336  break;
337 
339  error = ERROR_SUCCESS;
340  *flags = MSG_PARTIAL | MSG_OOB;
341  break;
342 
344  error = ERROR_SUCCESS;
345  *flags = MSG_PARTIAL;
346  break;
347 
348  default:
350  break;
351  }
352 
353  WSASetLastError(error);
354 
355  if (error == ERROR_SUCCESS) {
356  return 0;
357  } else {
358  return SOCKET_ERROR;
359  }
360 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
_W64 signed int intptr_t
ULONG_PTR Information
Definition: winapi.h:4168
#define STATUS_RECEIVE_EXPEDITED
Definition: winapi.h:356
#define STATUS_RECEIVE_PARTIAL
Definition: winapi.h:352
#define STATUS_RECEIVE_PARTIAL_EXPEDITED
Definition: winapi.h:360
#define TDI_RECEIVE_PARTIAL
Definition: winsock.h:72
#define AFD_OVERLAPPED
Definition: winsock.h:93
#define TDI_RECEIVE_PEEK
Definition: winsock.h:75
#define TDI_RECEIVE_NORMAL
Definition: winsock.h:73
#define IOCTL_AFD_RECEIVE
Definition: winsock.h:148

References AFD_OVERLAPPED, bytes, DWORD, error(), flags, HANDLE, if(), info(), _IO_STATUS_BLOCK::Information, IOCTL_AFD_RECEIVE, NULL, pNtDeviceIoControlFile, _IO_STATUS_BLOCK::Pointer, socket, status, _IO_STATUS_BLOCK::Status, STATUS_BUFFER_OVERFLOW, STATUS_PENDING, STATUS_RECEIVE_EXPEDITED, STATUS_RECEIVE_PARTIAL, STATUS_RECEIVE_PARTIAL_EXPEDITED, STATUS_SUCCESS, TDI_RECEIVE_NORMAL, TDI_RECEIVE_PARTIAL, TDI_RECEIVE_PEEK, and uv_ntstatus_to_winsock_error().

Referenced by uv_udp_set_socket().

◆ uv_wsarecvfrom_workaround()

int WSAAPI uv_wsarecvfrom_workaround ( SOCKET  socket,
WSABUF *  buffers,
DWORD  buffer_count,
DWORD bytes,
DWORD flags,
struct sockaddr addr,
int addr_len,
WSAOVERLAPPED *  overlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE  completion_routine 
)

Definition at line 364 of file winsock.c.

367  {
369  void* apc_context;
370  IO_STATUS_BLOCK* iosb = (IO_STATUS_BLOCK*) &overlapped->Internal;
372  DWORD error;
373 
374  if (overlapped == NULL || addr == NULL || addr_len == NULL ||
375  completion_routine != NULL) {
376  WSASetLastError(WSAEINVAL);
377  return SOCKET_ERROR;
378  }
379 
380  info.BufferArray = buffers;
381  info.BufferCount = buffer_count;
382  info.AfdFlags = AFD_OVERLAPPED;
383  info.TdiFlags = TDI_RECEIVE_NORMAL;
384  info.Address = addr;
385  info.AddressLength = addr_len;
386 
387  if (*flags & MSG_PEEK) {
388  info.TdiFlags |= TDI_RECEIVE_PEEK;
389  }
390 
391  if (*flags & MSG_PARTIAL) {
392  info.TdiFlags |= TDI_RECEIVE_PARTIAL;
393  }
394 
395  if (!((intptr_t) overlapped->hEvent & 1)) {
396  apc_context = (void*) overlapped;
397  } else {
398  apc_context = NULL;
399  }
400 
401  iosb->Status = STATUS_PENDING;
402  iosb->Pointer = 0;
403 
405  overlapped->hEvent,
406  NULL,
407  apc_context,
408  iosb,
410  &info,
411  sizeof(info),
412  NULL,
413  0);
414 
415  *flags = 0;
416  *bytes = (DWORD) iosb->Information;
417 
418  switch (status) {
419  case STATUS_SUCCESS:
420  error = ERROR_SUCCESS;
421  break;
422 
423  case STATUS_PENDING:
424  error = WSA_IO_PENDING;
425  break;
426 
428  error = WSAEMSGSIZE;
429  break;
430 
432  error = ERROR_SUCCESS;
433  *flags = MSG_OOB;
434  break;
435 
437  error = ERROR_SUCCESS;
438  *flags = MSG_PARTIAL | MSG_OOB;
439  break;
440 
442  error = ERROR_SUCCESS;
443  *flags = MSG_PARTIAL;
444  break;
445 
446  default:
448  break;
449  }
450 
451  WSASetLastError(error);
452 
453  if (error == ERROR_SUCCESS) {
454  return 0;
455  } else {
456  return SOCKET_ERROR;
457  }
458 }
#define IOCTL_AFD_RECEIVE_DATAGRAM
Definition: winsock.h:151

References addr, AFD_OVERLAPPED, bytes, DWORD, error(), flags, HANDLE, if(), info(), _IO_STATUS_BLOCK::Information, IOCTL_AFD_RECEIVE_DATAGRAM, NULL, pNtDeviceIoControlFile, _IO_STATUS_BLOCK::Pointer, socket, status, _IO_STATUS_BLOCK::Status, STATUS_BUFFER_OVERFLOW, STATUS_PENDING, STATUS_RECEIVE_EXPEDITED, STATUS_RECEIVE_PARTIAL, STATUS_RECEIVE_PARTIAL_EXPEDITED, STATUS_SUCCESS, TDI_RECEIVE_NORMAL, TDI_RECEIVE_PARTIAL, TDI_RECEIVE_PEEK, and uv_ntstatus_to_winsock_error().

Referenced by uv_udp_set_socket().

Variable Documentation

◆ uv_addr_ip4_any_

◆ uv_addr_ip6_any_

◆ uv_tcp_non_ifs_lsp_ipv4

int uv_tcp_non_ifs_lsp_ipv4

Definition at line 30 of file winsock.c.

Referenced by uv_tcp_set_socket(), uv_tcp_try_cancel_io(), and uv_winsock_init().

◆ uv_tcp_non_ifs_lsp_ipv6

int uv_tcp_non_ifs_lsp_ipv6

Definition at line 31 of file winsock.c.

Referenced by uv_tcp_set_socket(), uv_tcp_try_cancel_io(), and uv_winsock_init().