PWSSOCKET WSAAPI WsSockFindIfsSocket(IN SOCKET Handle) { INT ErrorCode; DWORD Flags; PWSSOCKET Socket = NULL; PWSPROCESS Process = NULL; PTCATALOG Catalog = NULL; /* Validate the socket and get handle info */ if ((Handle != INVALID_SOCKET) && (GetHandleInformation((HANDLE)Handle, &Flags))) { /* Get the process */ if ((Process = WsGetProcess())) { /* Get the catalog */ Catalog = WsProcGetTCatalog(Process); /* Get the IFS Provider */ ErrorCode = WsTcFindIfsProviderForSocket(Catalog, Handle); /* Check for success */ if (ErrorCode == ERROR_SUCCESS) { /* Get the Socket now */ Socket = WsSockGetSocketNoExport(Handle); /* Mark it as an API Socket */ if (Socket) Socket->ApiSocket = TRUE; } } } /* Return the socket */ return Socket; }
/* * @implemented */ INT WSAAPI WSAStringToAddressW(IN LPWSTR AddressString, IN INT AddressFamily, IN LPWSAPROTOCOL_INFOW lpProtocolInfo, OUT LPSOCKADDR lpAddress, IN OUT LPINT lpAddressLength) { PWSPROCESS Process; PWSTHREAD Thread; INT ErrorCode, Status; DWORD CatalogEntryId; PTCATALOG Catalog; PTCATALOG_ENTRY CatalogEntry; DPRINT("WSAStringToAddressW: %S\n", AddressString); /* Enter prolog */ if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS) { /* Leave now */ SetLastError(ErrorCode); return SOCKET_ERROR; } /* Get the catalog */ Catalog = WsProcGetTCatalog(Process); /* Check if we got custom protocol info */ if (lpProtocolInfo) { /* Get the entry ID */ CatalogEntryId = lpProtocolInfo->dwCatalogEntryId; /* Get the entry associated with it */ ErrorCode = WsTcGetEntryFromCatalogEntryId(Catalog, CatalogEntryId, &CatalogEntry); } else { /* Get it from the address family */ ErrorCode = WsTcGetEntryFromAf(Catalog, AddressFamily, &CatalogEntry); } /* Check for success */ if (ErrorCode == ERROR_SUCCESS) { /* Call the provider */ Status = CatalogEntry->Provider->Service.lpWSPStringToAddress(AddressString, AddressFamily, &CatalogEntry-> ProtocolInfo, lpAddress, lpAddressLength, &ErrorCode); /* Dereference the entry */ WsTcEntryDereference(CatalogEntry); /* Check for success and return */ if (Status == ERROR_SUCCESS) return ERROR_SUCCESS; } /* Set the error and return */ SetLastError(ErrorCode); return SOCKET_ERROR; }
/* * @implemented */ INT WSAAPI WSAStringToAddressA(IN LPSTR AddressString, IN INT AddressFamily, IN LPWSAPROTOCOL_INFOA lpProtocolInfo, OUT LPSOCKADDR lpAddress, IN OUT LPINT lpAddressLength) { PWSPROCESS Process; PWSTHREAD Thread; INT ErrorCode, Status; DWORD CatalogEntryId; PTCATALOG Catalog; PTCATALOG_ENTRY CatalogEntry; LPWSTR UnicodeString; DWORD Length = (DWORD)strlen(AddressString) + 1; DPRINT("WSAStringToAddressA: %s\n", AddressString); /* Enter prolog */ if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS) { /* Leave now */ SetLastError(ErrorCode); return SOCKET_ERROR; } /* Allocate the unicode string */ UnicodeString = HeapAlloc(WsSockHeap, 0, Length * 2); if (!UnicodeString) { /* No memory; fail */ SetLastError(WSAENOBUFS); return SOCKET_ERROR; } /* Convert the string */ MultiByteToWideChar(CP_ACP, 0, AddressString, -1, UnicodeString, Length); /* Get the catalog */ Catalog = WsProcGetTCatalog(Process); /* Check if we got custom protocol info */ if (lpProtocolInfo) { /* Get the entry ID */ CatalogEntryId = lpProtocolInfo->dwCatalogEntryId; /* Get the entry associated with it */ ErrorCode = WsTcGetEntryFromCatalogEntryId(Catalog, CatalogEntryId, &CatalogEntry); } else { /* Get it from the address family */ ErrorCode = WsTcGetEntryFromAf(Catalog, AddressFamily, &CatalogEntry); } /* Check for success */ if (ErrorCode == ERROR_SUCCESS) { /* Call the provider */ Status = CatalogEntry->Provider->Service.lpWSPStringToAddress(UnicodeString, AddressFamily, &CatalogEntry-> ProtocolInfo, lpAddress, lpAddressLength, &ErrorCode); /* Dereference the entry */ WsTcEntryDereference(CatalogEntry); /* Free the unicode string */ HeapFree(WsSockHeap, 0, UnicodeString); /* Check for success and return */ if (Status == ERROR_SUCCESS) return ERROR_SUCCESS; } else { /* Free the unicode string */ HeapFree(WsSockHeap, 0, UnicodeString); } /* Set the error and return */ SetLastError(ErrorCode); return SOCKET_ERROR; }
/* * @implemented */ SOCKET WSAAPI WSASocketW(IN INT af, IN INT type, IN INT protocol, IN LPWSAPROTOCOL_INFOW lpProtocolInfo, IN GROUP g, IN DWORD dwFlags) { PWSPROCESS Process; PWSTHREAD Thread; INT ErrorCode; PTCATALOG Catalog; DWORD CatalogId; PTCATALOG_ENTRY CatalogEntry; LPWSAPROTOCOL_INFOW ProtocolInfo; DWORD OpenType; SOCKET Status = INVALID_SOCKET; DPRINT("WSASocketW: %lx, %lx, %lx, %p\n", af, type, protocol, lpProtocolInfo); /* Enter prolog */ if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS) { /* Fail now */ SetLastError(ErrorCode); return INVALID_SOCKET; } /* Get the catalog */ Catalog = WsProcGetTCatalog(Process); /* Find a Provider for the Catalog ID */ if (lpProtocolInfo) { /* Get the catalog ID */ CatalogId = lpProtocolInfo->dwCatalogEntryId; /* Get the Catalog Entry */ ErrorCode = WsTcGetEntryFromCatalogEntryId(Catalog, CatalogId, &CatalogEntry); } else { /* No ID */ CatalogId = 0; DoLookup: /* Get the Catalog Data from the Socket Info */ ErrorCode = WsTcGetEntryFromTriplet(Catalog, af, type, protocol, CatalogId, &CatalogEntry); } /* Check for Success */ if (ErrorCode == ERROR_SUCCESS) { /* Use the default Protocol Info if none given */ ProtocolInfo = lpProtocolInfo ? lpProtocolInfo : &CatalogEntry->ProtocolInfo; /* Save the open type and set new one */ OpenType = Thread->OpenType; Thread->OpenType = (dwFlags & WSA_FLAG_OVERLAPPED) ? 0 : SO_SYNCHRONOUS_NONALERT; /* Call the Provider to create the Socket */ Status = CatalogEntry->Provider->Service.lpWSPSocket(af, type, protocol, ProtocolInfo, g, dwFlags, &ErrorCode); /* Restore open type */ Thread->OpenType = OpenType; /* Get the catalog ID now, and dereference */ CatalogId = ProtocolInfo->dwCatalogEntryId; WsTcEntryDereference(CatalogEntry); /* Did we fail with WSAEINPROGRESS and had no specific provider? */ if ((Status == INVALID_SOCKET) && (ErrorCode == WSAEINPROGRESS) && !(lpProtocolInfo)) { /* In that case, restart the lookup from this ID */ goto DoLookup; } /* Check if we got a valid socket */ if (Status != INVALID_SOCKET) { /* Add an API reference and return */ WsSockAddApiReference(Status); return Status; } } /* Return with an Error */ SetLastError(ErrorCode); return INVALID_SOCKET; }
/* * @implemented */ SOCKET WSPAPI WPUModifyIFSHandle(IN DWORD dwCatalogEntryId, IN SOCKET ProposedHandle, OUT LPINT lpErrno) { SOCKET Handle = INVALID_SOCKET; DWORD ErrorCode = ERROR_SUCCESS; PWSPROCESS Process; PTCATALOG Catalog; PTCATALOG_ENTRY Entry; PWSSOCKET Socket; DPRINT("WPUModifyIFSHandle: %lx, %lx\n", dwCatalogEntryId, ProposedHandle); /* Get the current process */ if ((Process = WsGetProcess())) { /* Get the Transport Catalog */ if ((Catalog = WsProcGetTCatalog(Process))) { /* Get the entry for this ID */ ErrorCode = WsTcGetEntryFromCatalogEntryId(Catalog, dwCatalogEntryId, &Entry); /* Check for success */ if (ErrorCode == ERROR_SUCCESS) { /* Create a socket object */ if ((Socket = WsSockAllocate())) { /* Initialize it */ WsSockInitialize(Socket, Entry); /* Associate it */ ErrorCode = WsSockAssociateHandle(Socket, ProposedHandle, TRUE); /* Check for success */ if (ErrorCode == ERROR_SUCCESS) { /* Return */ Handle = ProposedHandle; *lpErrno = ERROR_SUCCESS; } else { /* Fail */ WsSockDereference(Socket); *lpErrno = ErrorCode; } /* Dereference the extra count */ WsSockDereference(Socket); } else { /* No memory to allocate a socket */ *lpErrno = WSAENOBUFS; } /* Dereference the catalog entry */ WsTcEntryDereference(Entry); } else { /* Entry not found */ *lpErrno = ErrorCode; } } else { /* Catalog not found */ *lpErrno = WSANOTINITIALISED; } } else { /* Process not ready */ *lpErrno = WSANOTINITIALISED; } /* Return */ return Handle; }