Why ioctlsocket function call fails?

Николай Изюмов 0 Reputation points
2023-08-02T04:50:44.69+00:00
I create and debug a program in Visual Studio 2022 under Windows 11 64 bit version 21H2
First I initialize my socket with parameters
C++Highlight Code
1
 MySocket Socket1 = MySocket(AF_INET, SOCK_RAW, 5000, IPPROTO_IP, adr);
In the call to this constructor, a socket is created

C++Highlight Code
1
mysocket = socket(familydress, typesocket, typeprotocol);
Subsequently, I try to put it into promiscuous mode using the ioctlsocket(mysocket,SIO_RCVALL,&1) function
And the function fails with error 10022
When this function is called with the FIONBIO command, it succeeds with code 0. That is, the socket is switched to non-blocking mode without any problems. But it does not allow it to switch itself to promiscuous mode. What prevents the socket from being put into promiscuous mode, how can I achieve this?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,523 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,231 Reputation points Microsoft Vendor
    2023-08-02T05:35:18.4133333+00:00

    Use WSAIoctl.

    According to SIO_RCVALL Control Code,

    The socket handle passed to the WSAIoctl or WSPIoctl function must be one of the following:

    • An IPv4 socket that was created with the address family set to AF_INET, the socket type set to SOCK_RAW, and the protocol set to IPPROTO_IP.
    • An IPv6 socket that was created with the address family set to AF_INET6, the socket type set to SOCK_RAW, and the protocol set to IPPROTO_IPV6.

    The socket also must be bound to an explicit local IPv4 or IPv6 interface, which means that you cannot bind to INADDR_ANY or in6addr_any.

    See the rcvall example.