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.
 
 
 

84 lines
2.6 KiB

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