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