libutp_inet_ntop.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef LIBUTP_INET_NTOP_H
  2. #define LIBUTP_INET_NTOP_H
  3. /*
  4. * Copyright (c) 2010-2013 BitTorrent, Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. // About us linking the system inet_pton and inet_ntop symbols:
  25. // 1) These symbols are usually defined on POSIX systems
  26. // 2) They are not defined on Windows versions earlier than Vista
  27. // Defined in:
  28. // ut_utils/src/sockaddr.cpp
  29. // libutp/win32_inet_ntop.obj
  30. //
  31. // When we drop support for XP we can just #include <ws2tcpip.h>, and use the system functions
  32. // For now, we will always use our functions on windows, on all builds
  33. // The reason is: we would like the debug build to behave as much as the release build as possible
  34. // It is much better to catch a problem in the debug build, than to link the system version
  35. // in debug, and our version int he wild.
  36. #if defined(_WIN32_WINNT)
  37. #if _WIN32_WINNT >= 0x600 // Win32, post-XP
  38. #include <ws2tcpip.h> // for inet_ntop, inet_pton
  39. #define INET_NTOP inet_ntop
  40. #define INET_PTON inet_pton
  41. #else
  42. #define INET_NTOP libutp::inet_ntop // Win32, pre-XP: Use ours
  43. #define INET_PTON libutp::inet_pton
  44. #endif
  45. #else // not WIN32
  46. #include <arpa/inet.h> // for inet_ntop, inet_pton
  47. #define INET_NTOP inet_ntop
  48. #define INET_PTON inet_pton
  49. #endif
  50. //######################################################################
  51. //######################################################################
  52. namespace libutp {
  53. //######################################################################
  54. const char *inet_ntop(int af, const void *src, char *dest, size_t length);
  55. //######################################################################
  56. int inet_pton(int af, const char* src, void* dest);
  57. } //namespace libutp
  58. #endif // LIBUTP_INET_NTOP_H