You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

111 lines
2.7 KiB

  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include "compat.h"
  4. #include <windows.h>
  5. unsigned int
  6. sleep (unsigned int seconds)
  7. {
  8. Sleep (seconds * 1000);
  9. return 0;
  10. }
  11. static struct
  12. {
  13. int num;
  14. char *msg;
  15. } win32_error[] =
  16. {
  17. /* Errors that we might vaguely expect to see */
  18. {
  19. WSAEINTR, "Winsock: Interrupted system call"},
  20. {
  21. WSAEBADF, "Winsock: Bad file number"},
  22. {
  23. WSAEFAULT, "Winsock: Bad address"},
  24. {
  25. WSAEINVAL, "Winsock: Invalid argument"},
  26. {
  27. WSAEMFILE, "Winsock: Too many open files"},
  28. {
  29. WSAEWOULDBLOCK, "Winsock: Operation would block"},
  30. {
  31. WSAEINPROGRESS, "Winsock: Operation now in progress"},
  32. {
  33. WSAEALREADY, "Winsock: Operation already in progress"},
  34. {
  35. WSAENOTSOCK, "Winsock: Socket operation on nonsocket"},
  36. {
  37. WSAEADDRINUSE, "Winsock: Address already in use"},
  38. {
  39. WSAEADDRNOTAVAIL, "Winsock: Cannot assign requested address"},
  40. {
  41. WSAENETDOWN, "Winsock: Network is down"},
  42. {
  43. WSAENETUNREACH, "Winsock: Network is unreachable"},
  44. {
  45. WSAENETRESET, "Winsock: Network dropped connection on reset"},
  46. {
  47. WSAECONNABORTED, "Winsock: Software caused connection abort"},
  48. {
  49. WSAECONNRESET, "Winsock: Connection reset by peer"},
  50. {
  51. WSAETIMEDOUT, "Winsock: Connection timed out"},
  52. {
  53. WSAECONNREFUSED, "Winsock: Connection refused"},
  54. {
  55. WSAEHOSTDOWN, "Winsock: Host is down"},
  56. {
  57. WSAEHOSTUNREACH, "Winsock: No route to host"},
  58. {
  59. WSAVERNOTSUPPORTED, "Winsock: Unsupported Winsock version"},
  60. {
  61. ETIMEDOUT, "Connection timed out"},
  62. {
  63. ENOTCONN, "Not connected"},
  64. {
  65. -1, NULL},};
  66. char *
  67. compat_strerror (int errnum)
  68. {
  69. int i;
  70. static char buf[128];
  71. for (i = 0; win32_error[i].num != -1; i++)
  72. if (errnum == win32_error[i].num)
  73. return win32_error[i].msg;
  74. if (errnum >= 10000)
  75. {
  76. sprintf (buf, "Winsock: unknown error %d\n", errnum);
  77. return buf;
  78. }
  79. return strerror (errnum);
  80. }
  81. #ifdef __WIN32__
  82. /*const char *compat_inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
  83. {
  84. if (af == AF_INET)
  85. {
  86. struct sockaddr_in in;
  87. memset(&in, 0, sizeof(in));
  88. in.sin_family = AF_INET;
  89. memcpy(&in.sin_addr, src, sizeof(struct in_addr));
  90. getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST);
  91. return dst;
  92. }
  93. else if (af == AF_INET6)
  94. {
  95. struct sockaddr_in6 in;
  96. memset(&in, 0, sizeof(in));
  97. in.sin6_family = AF_INET6;
  98. memcpy(&in.sin6_addr, src, sizeof(struct in_addr6));
  99. getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST);
  100. return dst;
  101. }
  102. return NULL;
  103. }
  104. */
  105. #endif