int WSAAPI WSANtohs ( IN SOCKET s, IN u_short netshort, OUT u_short FAR * lphostshort ) /*++ Routine Description: Arguments: Returns: Zero on success else SOCKET_ERROR. The error code is stored with SetErrorCode(). --*/ { PDPROCESS Process; PDTHREAD Thread; PDSOCKET Socket; INT ErrorCode; INT ReturnCode; PPROTO_CATALOG_ITEM CatalogEntry; LPWSAPROTOCOL_INFOW ProtocolInfo; ReturnCode = PROLOG( &Process, &Thread, &ErrorCode); if (ERROR_SUCCESS != ReturnCode) { SetLastError(ErrorCode); return(SOCKET_ERROR); } //if if( lphostshort == NULL ) { SetLastError( WSAEFAULT ); return(SOCKET_ERROR); } ErrorCode = DSOCKET::GetCountedDSocketFromSocket( s, // SocketHandle & Socket); // DSocket if(ERROR_SUCCESS == ErrorCode){ CatalogEntry = Socket->GetCatalogItem(); // This is kind of a special case. We are done with the DSOCKET // object reference and we don't call through to the provider at // all. Socket->DropDSocketReference(); ProtocolInfo = CatalogEntry->GetProtocolInfo(); if (LITTLEENDIAN == ProtocolInfo->iNetworkByteOrder) { *lphostshort = netshort; } //if else { *lphostshort = SWAP_SHORT( netshort ); } //else } //if if (ErrorCode != ERROR_SUCCESS) { SetLastError(ErrorCode); ReturnCode = SOCKET_ERROR; } return(ReturnCode); }
int WSAAPI WSAHtonl ( IN SOCKET s, IN u_long hostlong, OUT u_long FAR * lpnetlong ) /*++ Routine Description: Convert a u_long from a specified host byte order to network byte order. Arguments: s - A descriptor identifying a socket. hostlong - A 32-bit number in host byte order. lpnetlong - A pointer to a 32-bit number in network byte order. Returns: If no error occurs, WSAHtonl() returns 0. Otherwise, a value of SOCKET_ERROR is returned. --*/ { PDSOCKET Socket; INT ErrorCode; PPROTO_CATALOG_ITEM CatalogEntry; LPWSAPROTOCOL_INFOW ProtocolInfo; ErrorCode = TURBO_PROLOG(); if (ErrorCode==ERROR_SUCCESS) { if( lpnetlong == NULL ) { SetLastError( WSAEFAULT ); return(SOCKET_ERROR); } Socket = DSOCKET::GetCountedDSocketFromSocket(s); if(Socket != NULL){ CatalogEntry = Socket->GetCatalogItem(); ProtocolInfo = CatalogEntry->GetProtocolInfo(); __try { if (LITTLEENDIAN == ProtocolInfo->iNetworkByteOrder) { *lpnetlong = hostlong; } //if else { *lpnetlong = SWAP_LONG( hostlong ); } //else ErrorCode = ERROR_SUCCESS; } __except (WS2_EXCEPTION_FILTER()) { ErrorCode = WSAEFAULT; } Socket->DropDSocketReference(); if (ErrorCode==ERROR_SUCCESS) return ErrorCode; } //if else
int WSAAPI WSANtohl ( IN SOCKET s, IN u_long netlong, OUT u_long FAR * lphostlong ) /*++ Routine Description: Convert a u_long from network byte order to host byte order. Arguments: s - A descriptor identifying a socket. netlong - A 32-bit number in network byte order. lphostlong - A pointer to a 32-bit number in host byte order. Returns: If no error occurs, WSANtohs() returns 0. Otherwise, a value of SOCKET_ERROR is returned. --*/ { PDPROCESS Process; PDTHREAD Thread; PDSOCKET Socket; INT ErrorCode; INT ReturnCode; PPROTO_CATALOG_ITEM CatalogEntry; LPWSAPROTOCOL_INFOW ProtocolInfo; ReturnCode = PROLOG( &Process, &Thread, &ErrorCode); if (ERROR_SUCCESS != ReturnCode) { SetLastError(ErrorCode); return(SOCKET_ERROR); } //if if( lphostlong == NULL ) { SetLastError( WSAEFAULT ); return(SOCKET_ERROR); } ErrorCode = DSOCKET::GetCountedDSocketFromSocket( s, // SocketHandle & Socket); // DSocket if(ERROR_SUCCESS == ErrorCode){ CatalogEntry = Socket->GetCatalogItem(); // This is kind of a special case. We are done with the DSOCKET // object reference and we don't call through to the provider at // all. Socket->DropDSocketReference(); ProtocolInfo = CatalogEntry->GetProtocolInfo(); if (LITTLEENDIAN == ProtocolInfo->iNetworkByteOrder) { *lphostlong = netlong; } //if else { *lphostlong = SWAP_LONG( netlong ); } //else } //if if (ErrorCode != ERROR_SUCCESS) { SetLastError(ErrorCode); ReturnCode = SOCKET_ERROR; } return(ReturnCode); }