2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
4 * FILE: dll/win32/ws2_32_new/src/dupsock.c
5 * PURPOSE: Socket Duplication
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
9 /* INCLUDES ******************************************************************/
16 /* FUNCTIONS *****************************************************************/
23 WSADuplicateSocketA(IN SOCKET s
,
25 OUT LPWSAPROTOCOL_INFOA lpProtocolInfo
)
27 WSAPROTOCOL_INFOW ProtocolInfoW
;
29 DPRINT("WSADuplicateSocketA: %lx, %lx, %p\n", s
, dwProcessId
, lpProtocolInfo
);
31 /* Call the Unicode Function */
32 ErrorCode
= WSADuplicateSocketW(s
, dwProcessId
, &ProtocolInfoW
);
34 /* Check for success */
35 if (ErrorCode
== ERROR_SUCCESS
)
37 /* Convert Protocol Info to Ansi */
40 /* Convert the information to ANSI */
41 ErrorCode
= MapUnicodeProtocolInfoToAnsi(&ProtocolInfoW
,
47 ErrorCode
= WSAEFAULT
;
50 /* Check if the conversion failed */
51 if (ErrorCode
!= ERROR_SUCCESS
)
53 /* Set the last error and normalize the error */
54 SetLastError(ErrorCode
);
55 ErrorCode
= SOCKET_ERROR
;
68 WSADuplicateSocketW(IN SOCKET s
,
70 OUT LPWSAPROTOCOL_INFOW lpProtocolInfo
)
75 DPRINT("WSADuplicateSocketW: %lx, %lx, %p\n", s
, dwProcessId
, lpProtocolInfo
);
77 /* Check for WSAStartup */
78 if ((ErrorCode
= WsQuickProlog()) == ERROR_SUCCESS
)
80 /* Get the Socket Context */
81 if ((Socket
= WsSockGetSocket(s
)))
84 Status
= Socket
->Provider
->Service
.lpWSPDuplicateSocket(s
,
88 /* Deference the Socket Context */
89 WsSockDereference(Socket
);
91 /* Return Provider Value */
92 if (Status
== ERROR_SUCCESS
) return Status
;
94 /* If everything seemed fine, then the WSP call failed itself */
95 if (ErrorCode
== NO_ERROR
) ErrorCode
= WSASYSCALLFAILURE
;
99 /* No Socket Context Found */
100 ErrorCode
= WSAENOTSOCK
;
104 /* Return with an Error */
105 SetLastError(ErrorCode
);