0xAA55 发表于 2014-5-20 18:41:31

【MSDN】WSAGetLastError(h_errno)Winsock相关错误代码查询

搬运自MSDN Library - October 2001。
找到这页信息的方法是在MSDN打开后的界面找到“索引(N)”选项卡,然后输入关键词“Winsock API ”(注意去掉引号),找到“Error Codes in the API
”,双击打开即可。
如下图所示。

这样就能找到了。当然我会把MSDN上的这些内容搬运到这里的。如果懒得自己打开MSDN看的话请回帖查看我搬运的内容。**** Hidden Message *****

0xAA55 发表于 2014-6-2 21:01:42

以下是将h_errno翻译成字符串的函数。配合printf、sprintf、fprintf可以很好地打印错误信息。char*h_error_String()
{
    switch(h_errno)
    {
    case WSAEACCES:
      return"WSAEACCES";
    case WSAEADDRINUSE:
      return"WSAEADDRINUSE";
    case WSAEADDRNOTAVAIL:
      return"WSAEADDRNOTAVAIL";
    case WSAEAFNOSUPPORT:
      return"WSAEAFNOSUPPORT";
    case WSAEALREADY:
      return"WSAEALREADY";
    case WSAECONNABORTED:
      return"WSAECONNABORTED";
    case WSAECONNREFUSED:
      return"WSAECONNREFUSED";
    case WSAECONNRESET:
      return"WSAECONNRESET";
    case WSAEDESTADDRREQ:
      return"WSAEDESTADDRREQ";
    case WSAEFAULT:
      return"WSAEFAULT";
    case WSAEHOSTDOWN:
      return"WSAEHOSTDOWN";
    case WSAEHOSTUNREACH:
      return"WSAEHOSTUNREACH";
    case WSAEINPROGRESS:
      return"WSAEINPROGRESS";
    case WSAEINTR:
      return"WSAEINTR";
    case WSAEINVAL:
      return"WSAEINVAL";
    case WSAEISCONN:
      return"WSAEISCONN";
    case WSAEMFILE:
      return"WSAEMFILE";
    case WSAEMSGSIZE:
      return"WSAEMSGSIZE";
    case WSAENETDOWN:
      return"WSAENETDOWN";
    case WSAENETRESET:
      return"WSAENETRESET";
    case WSAENETUNREACH:
      return"WSAENETUNREACH";
    case WSAENOBUFS:
      return"WSAENOBUFS";
    case WSAENOPROTOOPT:
      return"WSAENOPROTOOPT";
    case WSAENOTCONN:
      return"WSAENOTCONN";
    case WSAENOTSOCK:
      return"WSAENOTSOCK";
    case WSAEOPNOTSUPP:
      return"WSAEOPNOTSUPP";
    case WSAEPFNOSUPPORT:
      return"WSAEPFNOSUPPORT";
    case WSAEPROCLIM:
      return"WSAEPROCLIM";
    case WSAEPROTONOSUPPORT:
      return"WSAEPROTONOSUPPORT";
    case WSAEPROTOTYPE:
      return"WSAEPROTOTYPE";
    case WSAESHUTDOWN:
      return"WSAESHUTDOWN";
    case WSAESOCKTNOSUPPORT:
      return"WSAESOCKTNOSUPPORT";
    case WSAETIMEDOUT:
      return"WSAETIMEDOUT";
    case WSATYPE_NOT_FOUND:
      return"WSATYPE_NOT_FOUND";
    case WSAEWOULDBLOCK:
      return"WSAEWOULDBLOCK";
    case WSAHOST_NOT_FOUND:
      return"WSAHOST_NOT_FOUND";
    case WSA_INVALID_HANDLE:
      return"WSA_INVALID_HANDLE";
    case WSA_INVALID_PARAMETER:
      return"WSA_INVALID_PARAMETER";
    case WSAEINVALIDPROCTABLE:
      return"WSAEINVALIDPROCTABLE";
    case WSAEINVALIDPROVIDER:
      return"WSAEINVALIDPROVIDER";
    case WSA_IO_INCOMPLETE:
      return"WSA_IO_INCOMPLETE";
    case WSA_IO_PENDING:
      return"WSA_IO_PENDING";
    case WSA_NOT_ENOUGH_MEMORY:
      return"WSA_NOT_ENOUGH_MEMORY";
    case WSANOTINITIALISED:
      return"WSANOTINITIALISED";
    case WSANO_DATA:
      return"WSANO_DATA";
    case WSANO_RECOVERY:
      return"WSANO_RECOVERY";
    case WSAEPROVIDERFAILEDINIT:
      return"WSAEPROVIDERFAILEDINIT";
    case WSASYSCALLFAILURE:
      return"WSASYSCALLFAILURE";
    case WSASYSNOTREADY:
      return"WSASYSNOTREADY";
    case WSATRY_AGAIN:
      return"WSATRY_AGAIN";
    case WSAVERNOTSUPPORTED:
      return"WSAVERNOTSUPPORTED";
    case WSAEDISCON:
      return"WSAEDISCON";
    case WSA_OPERATION_ABORTED:
      return"WSA_OPERATION_ABORTED";
    default:
      return"";
    }
}

cloud0121 发表于 2024-6-11 15:44:23

感谢感谢
页: [1]
查看完整版本: 【MSDN】WSAGetLastError(h_errno)Winsock相关错误代码查询