2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
5 * PURPOSE: Socket Duplication
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
9 /* INCLUDES ******************************************************************/
15 /* DATA **********************************************************************/
17 /* FUNCTIONS *****************************************************************/
24 WSADuplicateSocketA(IN SOCKET s
,
26 OUT LPWSAPROTOCOL_INFOA lpProtocolInfo
)
28 WSAPROTOCOL_INFOW ProtocolInfoW
;
30 DPRINT("WSADuplicateSocketA: %lx, %lx, %p\n", s
, dwProcessId
, lpProtocolInfo
);
32 /* Call the Unicode Function */
33 ErrorCode
= WSADuplicateSocketW(s
, dwProcessId
, &ProtocolInfoW
);
35 /* Check for success */
36 if (ErrorCode
== ERROR_SUCCESS
)
38 /* Convert Protocol Info to Ansi */
41 /* Convert the information to ANSI */
42 ErrorCode
= MapUnicodeProtocolInfoToAnsi(&ProtocolInfoW
,
48 ErrorCode
= WSAEFAULT
;
51 /* Check if the conversion failed */
52 if (ErrorCode
!= ERROR_SUCCESS
)
54 /* Set the last error and normalize the error */
55 SetLastError(ErrorCode
);
56 ErrorCode
= SOCKET_ERROR
;
69 WSADuplicateSocketW(IN SOCKET s
,
71 OUT LPWSAPROTOCOL_INFOW lpProtocolInfo
)
76 DPRINT("WSADuplicateSocketW: %lx, %lx, %p\n", s
, dwProcessId
, lpProtocolInfo
);
78 /* Check for WSAStartup */
79 if ((ErrorCode
= WsQuickProlog()) == ERROR_SUCCESS
)
81 /* Get the Socket Context */
82 if ((Socket
= WsSockGetSocket(s
)))
85 Status
= Socket
->Provider
->Service
.lpWSPDuplicateSocket(s
,
89 /* Deference the Socket Context */
90 WsSockDereference(Socket
);
92 /* Return Provider Value */
93 if (Status
== ERROR_SUCCESS
) return Status
;
95 /* If everything seemed fine, then the WSP call failed itself */
96 if (ErrorCode
== NO_ERROR
) ErrorCode
= WSASYSCALLFAILURE
;
100 /* No Socket Context Found */
101 ErrorCode
= WSAENOTSOCK
;
105 /* Return with an Error */
106 SetLastError(ErrorCode
);