Blame m4/inet_pton.m4

Packit 8f70b4
# inet_pton.m4 serial 18
Packit 8f70b4
dnl Copyright (C) 2006, 2008-2018 Free Software Foundation, Inc.
Packit 8f70b4
dnl This file is free software; the Free Software Foundation
Packit 8f70b4
dnl gives unlimited permission to copy and/or distribute it,
Packit 8f70b4
dnl with or without modifications, as long as this notice is preserved.
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_FUNC_INET_PTON],
Packit 8f70b4
[
Packit 8f70b4
  AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
Packit 8f70b4
Packit 8f70b4
  dnl Persuade Solaris <arpa/inet.h> to declare inet_pton.
Packit 8f70b4
  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
Packit 8f70b4
Packit 8f70b4
  AC_REQUIRE([AC_C_RESTRICT])
Packit 8f70b4
Packit 8f70b4
  dnl Most platforms that provide inet_pton define it in libc.
Packit 8f70b4
  dnl Solaris 8..10 provide inet_pton in libnsl instead.
Packit 8f70b4
  dnl Solaris 2.6..7 provide inet_pton in libresolv instead.
Packit 8f70b4
  dnl Haiku provides it in -lnetwork.
Packit 8f70b4
  dnl Native Windows provides it in -lws2_32 instead, with a declaration in
Packit 8f70b4
  dnl <ws2tcpip.h>, and it uses stdcall calling convention, not cdecl
Packit 8f70b4
  dnl (hence we cannot use AC_CHECK_FUNCS, AC_SEARCH_LIBS to find it).
Packit 8f70b4
  HAVE_INET_PTON=1
Packit 8f70b4
  INET_PTON_LIB=
Packit 8f70b4
  gl_PREREQ_SYS_H_WINSOCK2
Packit 8f70b4
  if test $HAVE_WINSOCK2_H = 1; then
Packit 8f70b4
    AC_CHECK_DECLS([inet_pton],,, [[#include <ws2tcpip.h>]])
Packit 8f70b4
    if test $ac_cv_have_decl_inet_pton = yes; then
Packit 8f70b4
      dnl It needs to be overridden, because the stdcall calling convention
Packit 8f70b4
      dnl is not compliant with POSIX.
Packit 8f70b4
      REPLACE_INET_PTON=1
Packit 8f70b4
      INET_PTON_LIB="-lws2_32"
Packit 8f70b4
    else
Packit 8f70b4
      HAVE_DECL_INET_PTON=0
Packit 8f70b4
      HAVE_INET_PTON=0
Packit 8f70b4
    fi
Packit 8f70b4
  else
Packit 8f70b4
    gl_save_LIBS=$LIBS
Packit 8f70b4
    AC_SEARCH_LIBS([inet_pton], [nsl resolv network], [],
Packit 8f70b4
      [AC_CHECK_FUNCS([inet_pton])
Packit 8f70b4
       if test $ac_cv_func_inet_pton = no; then
Packit 8f70b4
         HAVE_INET_PTON=0
Packit 8f70b4
       fi
Packit 8f70b4
      ])
Packit 8f70b4
    LIBS=$gl_save_LIBS
Packit 8f70b4
Packit 8f70b4
    if test "$ac_cv_search_inet_pton" != "no" \
Packit 8f70b4
       && test "$ac_cv_search_inet_pton" != "none required"; then
Packit 8f70b4
      INET_PTON_LIB="$ac_cv_search_inet_pton"
Packit 8f70b4
    fi
Packit 8f70b4
Packit 8f70b4
    AC_CHECK_HEADERS_ONCE([netdb.h])
Packit 8f70b4
    AC_CHECK_DECLS([inet_pton],,,
Packit 8f70b4
      [[#include <arpa/inet.h>
Packit 8f70b4
        #if HAVE_NETDB_H
Packit 8f70b4
        # include <netdb.h>
Packit 8f70b4
        #endif
Packit 8f70b4
      ]])
Packit 8f70b4
    if test $ac_cv_have_decl_inet_pton = no; then
Packit 8f70b4
      HAVE_DECL_INET_PTON=0
Packit 8f70b4
    fi
Packit 8f70b4
  fi
Packit 8f70b4
  AC_SUBST([INET_PTON_LIB])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# Prerequisites of lib/inet_pton.c.
Packit 8f70b4
AC_DEFUN([gl_PREREQ_INET_PTON], [
Packit 8f70b4
  AC_REQUIRE([gl_SOCKET_FAMILIES])
Packit 8f70b4
])