inet_pton.m4 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # inet_pton.m4 serial 19
  2. dnl Copyright (C) 2006, 2008-2023 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. AC_DEFUN([gl_FUNC_INET_PTON],
  7. [
  8. AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
  9. dnl Persuade Solaris <arpa/inet.h> to declare inet_pton.
  10. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  11. AC_REQUIRE([AC_C_RESTRICT])
  12. dnl Most platforms that provide inet_pton define it in libc.
  13. dnl Solaris 8..10 provide inet_pton in libnsl instead.
  14. dnl Solaris 2.6..7 provide inet_pton in libresolv instead.
  15. dnl Haiku provides it in -lnetwork.
  16. dnl Native Windows provides it in -lws2_32 instead, with a declaration in
  17. dnl <ws2tcpip.h>, and it uses stdcall calling convention, not cdecl
  18. dnl (hence we cannot use AC_CHECK_FUNCS, AC_SEARCH_LIBS to find it).
  19. HAVE_INET_PTON=1
  20. INET_PTON_LIB=
  21. gl_PREREQ_SYS_H_WINSOCK2
  22. if test $HAVE_WINSOCK2_H = 1; then
  23. dnl It needs to be overridden, because the stdcall calling convention
  24. dnl is not compliant with POSIX. Set REPLACE_INET_PTON in order to avoid
  25. dnl a name conflict at the linker level, even though the header file
  26. dnl <ws2tcpip.h> declares inet_pton only if _WIN32_WINNT >= 0x0600.
  27. REPLACE_INET_PTON=1
  28. AC_CHECK_DECLS([inet_pton],,, [[#include <ws2tcpip.h>]])
  29. if test $ac_cv_have_decl_inet_pton = yes; then
  30. INET_PTON_LIB="-lws2_32"
  31. else
  32. HAVE_DECL_INET_PTON=0
  33. fi
  34. else
  35. gl_save_LIBS=$LIBS
  36. AC_SEARCH_LIBS([inet_pton], [nsl resolv network], [],
  37. [AC_CHECK_FUNCS([inet_pton])
  38. if test $ac_cv_func_inet_pton = no; then
  39. HAVE_INET_PTON=0
  40. fi
  41. ])
  42. LIBS=$gl_save_LIBS
  43. if test "$ac_cv_search_inet_pton" != "no" \
  44. && test "$ac_cv_search_inet_pton" != "none required"; then
  45. INET_PTON_LIB="$ac_cv_search_inet_pton"
  46. fi
  47. AC_CHECK_HEADERS_ONCE([netdb.h])
  48. AC_CHECK_DECLS([inet_pton],,,
  49. [[#include <arpa/inet.h>
  50. #if HAVE_NETDB_H
  51. # include <netdb.h>
  52. #endif
  53. ]])
  54. if test $ac_cv_have_decl_inet_pton = no; then
  55. HAVE_DECL_INET_PTON=0
  56. fi
  57. fi
  58. AC_SUBST([INET_PTON_LIB])
  59. ])
  60. # Prerequisites of lib/inet_pton.c.
  61. AC_DEFUN([gl_PREREQ_INET_PTON], [
  62. AC_REQUIRE([gl_SOCKET_FAMILIES])
  63. ])