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