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.
 
 
 

85 lines
2.6 KiB

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