ReactOS  0.4.14-dev-384-g5b37caa
dupsock.c
Go to the documentation of this file.
1 /*
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)
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
24  IN DWORD dwProcessId,
25  OUT LPWSAPROTOCOL_INFOA lpProtocolInfo)
26 {
27  WSAPROTOCOL_INFOW ProtocolInfoW;
28  INT ErrorCode;
29  DPRINT("WSADuplicateSocketA: %lx, %lx, %p\n", s, dwProcessId, lpProtocolInfo);
30 
31  /* Call the Unicode Function */
32  ErrorCode = WSADuplicateSocketW(s, dwProcessId, &ProtocolInfoW);
33 
34  /* Check for success */
35  if (ErrorCode == ERROR_SUCCESS)
36  {
37  /* Convert Protocol Info to Ansi */
38  if (lpProtocolInfo)
39  {
40  /* Convert the information to ANSI */
41  ErrorCode = MapUnicodeProtocolInfoToAnsi(&ProtocolInfoW,
42  lpProtocolInfo);
43  }
44  else
45  {
46  /* Fail */
48  }
49 
50  /* Check if the conversion failed */
51  if (ErrorCode != ERROR_SUCCESS)
52  {
53  /* Set the last error and normalize the error */
56  }
57  }
58 
59  /* Return */
60  return ErrorCode;
61 }
62 
63 /*
64  * @implemented
65  */
66 INT
67 WSAAPI
69  IN DWORD dwProcessId,
70  OUT LPWSAPROTOCOL_INFOW lpProtocolInfo)
71 {
72  PWSSOCKET Socket;
73  INT Status;
74  INT ErrorCode;
75  DPRINT("WSADuplicateSocketW: %lx, %lx, %p\n", s, dwProcessId, lpProtocolInfo);
76 
77  /* Check for WSAStartup */
79  {
80  /* Get the Socket Context */
81  if ((Socket = WsSockGetSocket(s)))
82  {
83  /* Make the call */
85  dwProcessId,
86  lpProtocolInfo,
87  &ErrorCode);
88  /* Deference the Socket Context */
89  WsSockDereference(Socket);
90 
91  /* Return Provider Value */
92  if (Status == ERROR_SUCCESS) return Status;
93 
94  /* If everything seemed fine, then the WSP call failed itself */
96  }
97  else
98  {
99  /* No Socket Context Found */
101  }
102  }
103 
104  /* Return with an Error */
106  return SOCKET_ERROR;
107 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
#define IN
Definition: typedefs.h:38
#define WSAEFAULT
Definition: winerror.h:1945
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
INT WSAAPI WSADuplicateSocketA(IN SOCKET s, IN DWORD dwProcessId, OUT LPWSAPROTOCOL_INFOA lpProtocolInfo)
Definition: dupsock.c:23
PWSSOCKET WSAAPI WsSockGetSocket(IN SOCKET Handle)
Definition: dsocket.c:140
LPWSPDUPLICATESOCKET lpWSPDuplicateSocket
Definition: ws2spi.h:469
#define NO_ERROR
Definition: dderror.h:5
int32_t INT
Definition: typedefs.h:56
WSPPROC_TABLE Service
Definition: ws2_32p.h:80
VOID WSAAPI WsSockDereference(IN PWSSOCKET Socket)
Definition: dsocket.c:205
void DPRINT(...)
Definition: polytest.cpp:61
PTPROVIDER Provider
Definition: ws2_32p.h:199
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
INT WSAAPI WSADuplicateSocketW(IN SOCKET s, IN DWORD dwProcessId, OUT LPWSAPROTOCOL_INFOW lpProtocolInfo)
Definition: dupsock.c:68
GLdouble s
Definition: gl.h:2039
Status
Definition: gdiplustypes.h:24
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
#define WSAAPI
Definition: winsock2.h:584
INT WSAAPI MapUnicodeProtocolInfoToAnsi(IN LPWSAPROTOCOL_INFOW UnicodeInfo, OUT LPWSAPROTOCOL_INFOA AnsiInfo)
Definition: wsautil.c:224
#define OUT
Definition: typedefs.h:39
UINT_PTR SOCKET
Definition: winsock.h:47
FORCEINLINE DWORD WsQuickProlog(VOID)
Definition: ws2_32p.h:892