xref: /reactos/dll/win32/ws2_32/src/ioctl.c (revision 4561998a)
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS WinSock 2 API
4  * FILE:        dll/win32/ws2_32_new/src/ioctl.c
5  * PURPOSE:     Socket I/O Control Code support.
6  * PROGRAMMER:  Alex Ionescu (alex@relsoft.net)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include <ws2_32.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS *****************************************************************/
17 
18 /*
19  * @implemented
20  */
21 INT
22 WSAAPI
23 ioctlsocket(IN SOCKET s,
24             IN LONG cmd,
25             IN OUT ULONG FAR* argp)
26 {
27     DWORD Dummy;
28 
29     /* Let WSA do it */
30     return WSAIoctl(s,
31                     cmd,
32                     argp,
33                     sizeof(ULONG),
34                     argp,
35                     sizeof(ULONG),
36                     &Dummy,
37                     NULL,
38                     NULL);
39 }
40 
41 /*
42  * @implemented
43  */
44 INT
45 WSAAPI
46 WSAIoctl(IN SOCKET s,
47          IN DWORD dwIoControlCode,
48          IN LPVOID lpvInBuffer,
49          IN DWORD cbInBuffer,
50          OUT LPVOID lpvOutBuffer,
51          IN DWORD cbOutBuffer,
52          OUT LPDWORD lpcbBytesReturned,
53          IN LPWSAOVERLAPPED lpOverlapped,
54          IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
55 {
56     PWSSOCKET Socket;
57     INT Status;
58     INT ErrorCode;
59     LPWSATHREADID ThreadId;
60     DPRINT("WSAIoctl: %lx, %lx\n", s, dwIoControlCode);
61 
62     /* Check for WSAStartup */
63     if ((ErrorCode = WsQuickPrologTid(&ThreadId)) == ERROR_SUCCESS)
64     {
65         /* Get the Socket Context */
66         if ((Socket = WsSockGetSocket(s)))
67         {
68             /* Make the call */
69             Status = Socket->Provider->Service.lpWSPIoctl(s,
70                                                   dwIoControlCode,
71                                                   lpvInBuffer,
72                                                   cbInBuffer,
73                                                   lpvOutBuffer,
74                                                   cbOutBuffer,
75                                                   lpcbBytesReturned,
76                                                   lpOverlapped,
77                                                   lpCompletionRoutine,
78                                                   ThreadId,
79                                                   &ErrorCode);
80 
81             /* Deference the Socket Context */
82             WsSockDereference(Socket);
83 
84             /* Return Provider Value */
85             if (Status == ERROR_SUCCESS) return Status;
86         }
87         else
88         {
89             /* No Socket Context Found */
90             ErrorCode = WSAENOTSOCK;
91         }
92     }
93 
94     /* Return with an Error */
95     SetLastError(ErrorCode);
96     return SOCKET_ERROR;
97 }
98