Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendupsock.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS WinSock 2 API 00004 * FILE: dupsock.c 00005 * PURPOSE: Socket Duplication 00006 * PROGRAMMER: Alex Ionescu (alex@relsoft.net) 00007 */ 00008 00009 /* INCLUDES ******************************************************************/ 00010 #include "ws2_32.h" 00011 00012 //#define NDEBUG 00013 #include <debug.h> 00014 00015 /* DATA **********************************************************************/ 00016 00017 /* FUNCTIONS *****************************************************************/ 00018 00019 /* 00020 * @implemented 00021 */ 00022 INT 00023 WSAAPI 00024 WSADuplicateSocketA(IN SOCKET s, 00025 IN DWORD dwProcessId, 00026 OUT LPWSAPROTOCOL_INFOA lpProtocolInfo) 00027 { 00028 WSAPROTOCOL_INFOW ProtocolInfoW; 00029 INT ErrorCode; 00030 DPRINT("WSADuplicateSocketA: %lx, %lx, %p\n", s, dwProcessId, lpProtocolInfo); 00031 00032 /* Call the Unicode Function */ 00033 ErrorCode = WSADuplicateSocketW(s, dwProcessId, &ProtocolInfoW); 00034 00035 /* Check for success */ 00036 if (ErrorCode == ERROR_SUCCESS) 00037 { 00038 /* Convert Protocol Info to Ansi */ 00039 if (lpProtocolInfo) 00040 { 00041 /* Convert the information to ANSI */ 00042 ErrorCode = MapUnicodeProtocolInfoToAnsi(&ProtocolInfoW, 00043 lpProtocolInfo); 00044 } 00045 else 00046 { 00047 /* Fail */ 00048 ErrorCode = WSAEFAULT; 00049 } 00050 00051 /* Check if the conversion failed */ 00052 if (ErrorCode != ERROR_SUCCESS) 00053 { 00054 /* Set the last error and normalize the error */ 00055 SetLastError(ErrorCode); 00056 ErrorCode = SOCKET_ERROR; 00057 } 00058 } 00059 00060 /* Return */ 00061 return ErrorCode; 00062 } 00063 00064 /* 00065 * @implemented 00066 */ 00067 INT 00068 WSAAPI 00069 WSADuplicateSocketW(IN SOCKET s, 00070 IN DWORD dwProcessId, 00071 OUT LPWSAPROTOCOL_INFOW lpProtocolInfo) 00072 { 00073 PWSSOCKET Socket; 00074 INT Status; 00075 INT ErrorCode; 00076 DPRINT("WSADuplicateSocketW: %lx, %lx, %p\n", s, dwProcessId, lpProtocolInfo); 00077 00078 /* Check for WSAStartup */ 00079 if ((ErrorCode = WsQuickProlog()) == ERROR_SUCCESS) 00080 { 00081 /* Get the Socket Context */ 00082 if ((Socket = WsSockGetSocket(s))) 00083 { 00084 /* Make the call */ 00085 Status = Socket->Provider->Service.lpWSPDuplicateSocket(s, 00086 dwProcessId, 00087 lpProtocolInfo, 00088 &ErrorCode); 00089 /* Deference the Socket Context */ 00090 WsSockDereference(Socket); 00091 00092 /* Return Provider Value */ 00093 if (Status == ERROR_SUCCESS) return Status; 00094 00095 /* If everything seemed fine, then the WSP call failed itself */ 00096 if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE; 00097 } 00098 else 00099 { 00100 /* No Socket Context Found */ 00101 ErrorCode = WSAENOTSOCK; 00102 } 00103 } 00104 00105 /* Return with an Error */ 00106 SetLastError(ErrorCode); 00107 return SOCKET_ERROR; 00108 } Generated on Sun May 27 2012 04:27:09 for ReactOS by
1.7.6.1
|