Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ws2_32/socket.c | 107 ++++++++++++++++++++++++++++++++----------- 1 file changed, 80 insertions(+), 27 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 74e86e9d845..ed7218f9fb7 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -972,35 +972,88 @@ static NTSTATUS sock_error_to_ntstatus( DWORD err ) } }
-static DWORD NtStatusToWSAError( DWORD status ) +static DWORD NtStatusToWSAError( NTSTATUS status ) { - switch ( status ) + static const struct { - case STATUS_SUCCESS: return 0; - case STATUS_PENDING: return WSA_IO_PENDING; - case STATUS_INVALID_HANDLE: - case STATUS_OBJECT_TYPE_MISMATCH: return WSAENOTSOCK; - case STATUS_INVALID_PARAMETER: return WSAEINVAL; - case STATUS_PIPE_DISCONNECTED: return WSAESHUTDOWN; - case STATUS_NETWORK_BUSY: return WSAEALREADY; - case STATUS_NETWORK_UNREACHABLE: return WSAENETUNREACH; - case STATUS_CONNECTION_REFUSED: return WSAECONNREFUSED; - case STATUS_INVALID_CONNECTION: return WSAENOTCONN; - case STATUS_CONNECTION_RESET: return WSAECONNRESET; - case STATUS_CONNECTION_ABORTED: return WSAECONNABORTED; - case STATUS_CANCELLED: return WSA_OPERATION_ABORTED; - case STATUS_SHARING_VIOLATION: return WSAEADDRINUSE; - case STATUS_IO_TIMEOUT: - case STATUS_TIMEOUT: return WSAETIMEDOUT; - case STATUS_ACCESS_VIOLATION: return WSAEFAULT; - case STATUS_ACCESS_DENIED: return WSAEACCES; - case STATUS_TOO_MANY_OPENED_FILES: return WSAEMFILE; - case STATUS_DEVICE_NOT_READY: return WSAEWOULDBLOCK; - case STATUS_BUFFER_OVERFLOW: return WSAEMSGSIZE; - case STATUS_NOT_SUPPORTED: return WSAEOPNOTSUPP; - case STATUS_HOST_UNREACHABLE: return WSAEHOSTUNREACH; - default: return RtlNtStatusToDosError( status ); + NTSTATUS status; + DWORD error; } + errors[] = + { + {STATUS_PENDING, ERROR_IO_PENDING}, + + {STATUS_BUFFER_OVERFLOW, WSAEMSGSIZE}, + + {STATUS_NOT_IMPLEMENTED, WSAEOPNOTSUPP}, + {STATUS_ACCESS_VIOLATION, WSAEFAULT}, + {STATUS_PAGEFILE_QUOTA, WSAENOBUFS}, + {STATUS_INVALID_HANDLE, WSAENOTSOCK}, + {STATUS_NO_SUCH_DEVICE, WSAENETDOWN}, + {STATUS_NO_SUCH_FILE, WSAENETDOWN}, + {STATUS_NO_MEMORY, WSAENOBUFS}, + {STATUS_CONFLICTING_ADDRESSES, WSAENOBUFS}, + {STATUS_ACCESS_DENIED, WSAEACCES}, + {STATUS_BUFFER_TOO_SMALL, WSAEFAULT}, + {STATUS_OBJECT_TYPE_MISMATCH, WSAENOTSOCK}, + {STATUS_OBJECT_NAME_NOT_FOUND, WSAENETDOWN}, + {STATUS_OBJECT_PATH_NOT_FOUND, WSAENETDOWN}, + {STATUS_SHARING_VIOLATION, WSAEADDRINUSE}, + {STATUS_QUOTA_EXCEEDED, WSAENOBUFS}, + {STATUS_TOO_MANY_PAGING_FILES, WSAENOBUFS}, + {STATUS_INSUFFICIENT_RESOURCES, WSAENOBUFS}, + {STATUS_WORKING_SET_QUOTA, WSAENOBUFS}, + {STATUS_DEVICE_NOT_READY, WSAEWOULDBLOCK}, + {STATUS_PIPE_DISCONNECTED, WSAESHUTDOWN}, + {STATUS_IO_TIMEOUT, WSAETIMEDOUT}, + {STATUS_NOT_SUPPORTED, WSAEOPNOTSUPP}, + {STATUS_REMOTE_NOT_LISTENING, WSAECONNREFUSED}, + {STATUS_BAD_NETWORK_PATH, WSAENETUNREACH}, + {STATUS_NETWORK_BUSY, WSAENETDOWN}, + {STATUS_INVALID_NETWORK_RESPONSE, WSAENETDOWN}, + {STATUS_UNEXPECTED_NETWORK_ERROR, WSAENETDOWN}, + {STATUS_REQUEST_NOT_ACCEPTED, WSAEWOULDBLOCK}, + {STATUS_CANCELLED, ERROR_OPERATION_ABORTED}, + {STATUS_COMMITMENT_LIMIT, WSAENOBUFS}, + {STATUS_LOCAL_DISCONNECT, WSAECONNABORTED}, + {STATUS_REMOTE_DISCONNECT, WSAECONNRESET}, + {STATUS_REMOTE_RESOURCES, WSAENOBUFS}, + {STATUS_LINK_FAILED, WSAECONNRESET}, + {STATUS_LINK_TIMEOUT, WSAETIMEDOUT}, + {STATUS_INVALID_CONNECTION, WSAENOTCONN}, + {STATUS_INVALID_ADDRESS, WSAEADDRNOTAVAIL}, + {STATUS_INVALID_BUFFER_SIZE, WSAEMSGSIZE}, + {STATUS_INVALID_ADDRESS_COMPONENT, WSAEADDRNOTAVAIL}, + {STATUS_TOO_MANY_ADDRESSES, WSAENOBUFS}, + {STATUS_ADDRESS_ALREADY_EXISTS, WSAEADDRINUSE}, + {STATUS_CONNECTION_DISCONNECTED, WSAECONNRESET}, + {STATUS_CONNECTION_RESET, WSAECONNRESET}, + {STATUS_TRANSACTION_ABORTED, WSAECONNABORTED}, + {STATUS_CONNECTION_REFUSED, WSAECONNREFUSED}, + {STATUS_GRACEFUL_DISCONNECT, WSAEDISCON}, + {STATUS_CONNECTION_ACTIVE, WSAEISCONN}, + {STATUS_NETWORK_UNREACHABLE, WSAENETUNREACH}, + {STATUS_HOST_UNREACHABLE, WSAEHOSTUNREACH}, + {STATUS_PROTOCOL_UNREACHABLE, WSAENETUNREACH}, + {STATUS_PORT_UNREACHABLE, WSAECONNRESET}, + {STATUS_REQUEST_ABORTED, WSAEINTR}, + {STATUS_CONNECTION_ABORTED, WSAECONNABORTED}, + {STATUS_DATATYPE_MISALIGNMENT_ERROR,WSAEFAULT}, + {STATUS_HOST_DOWN, WSAEHOSTDOWN}, + {0x80070000 | ERROR_IO_INCOMPLETE, ERROR_IO_INCOMPLETE}, + {0xc0010000 | ERROR_IO_INCOMPLETE, ERROR_IO_INCOMPLETE}, + {0xc0070000 | ERROR_IO_INCOMPLETE, ERROR_IO_INCOMPLETE}, + }; + + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(errors); ++i) + { + if (errors[i].status == status) + return errors[i].error; + } + + return NT_SUCCESS(status) ? RtlNtStatusToDosErrorNoTeb(status) : WSAEINVAL; }
/* set last error code from NT status without mapping WSA errors */ @@ -5871,7 +5924,7 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol, IOCTL_AFD_CREATE, &create_params, sizeof(create_params), NULL, 0))) { WARN("Failed to initialize socket, status %#x.\n", status); - err = NtStatusToWSAError(status); + err = RtlNtStatusToDosError( status ); if (err == WSAEACCES) /* raw socket denied */ { if (type == SOCK_RAW)