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.

76 lines
1.8 KiB

10 years ago
10 years ago
10 years ago
  1. /*
  2. * win32.c - Win32 port helpers
  3. *
  4. * Copyright (C) 2014, Linus Yang <linusyang@gmail.com>
  5. *
  6. * This file is part of the shadowsocks-libev.
  7. *
  8. * shadowsocks-libev is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * shadowsocks-libev is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with shadowsocks-libev; see the file COPYING. If not, see
  20. * <http://www.gnu.org/licenses/>.
  21. */
  22. #ifndef _WIN32_H
  23. #define _WIN32_H
  24. #ifdef _WIN32_WINNT
  25. #undef _WIN32_WINNT
  26. #endif
  27. #define _WIN32_WINNT 0x0501
  28. #include <winsock2.h>
  29. #include <ws2tcpip.h>
  30. #ifdef EWOULDBLOCK
  31. #undef EWOULDBLOCK
  32. #endif
  33. #ifdef errno
  34. #undef errno
  35. #endif
  36. #ifdef ERROR
  37. #undef ERROR
  38. #endif
  39. #ifndef AI_ALL
  40. #define AI_ALL 0x00000100
  41. #endif
  42. #ifndef AI_ADDRCONFIG
  43. #define AI_ADDRCONFIG 0x00000400
  44. #endif
  45. #ifndef AI_V4MAPPED
  46. #define AI_V4MAPPED 0x00000800
  47. #endif
  48. #ifndef IPV6_V6ONLY
  49. #define IPV6_V6ONLY 27 // Treat wildcard bind as AF_INET6-only.
  50. #endif
  51. #define EWOULDBLOCK WSAEWOULDBLOCK
  52. #define errno WSAGetLastError()
  53. #define close(fd) closesocket(fd)
  54. #define ERROR(s) ss_error(s)
  55. #define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (char *)(d), e)
  56. void winsock_init(void);
  57. void winsock_cleanup(void);
  58. void ss_error(const char *s);
  59. size_t strnlen(const char *s, size_t maxlen);
  60. int setnonblocking(int fd);
  61. const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
  62. #endif