1dnl @synopsis AX_FUNC_WHICH_GETHOSTBYNAME_R
2dnl
3dnl Determines which historical variant of the gethostbyname_r() call
4dnl (taking three, five, or six arguments) is available on the system
5dnl and defines one of the following macros accordingly:
6dnl
7dnl   HAVE_FUNC_GETHOSTBYNAME_R_6
8dnl   HAVE_FUNC_GETHOSTBYNAME_R_5
9dnl   HAVE_FUNC_GETHOSTBYNAME_R_3
10dnl
11dnl If used in conjunction with gethostname.c, the API demonstrated in
12dnl test.c can be used regardless of which gethostbyname_r() is
13dnl available. These example files can be found at
14dnl http://www.csn.ul.ie/~caolan/publink/gethostbyname_r
15dnl
16dnl based on David Arnold's autoconf suggestion in the threads faq
17dnl
18dnl Originally named "AC_caolan_FUNC_WHICH_GETHOSTBYNAME_R". Rewritten
19dnl for Autoconf 2.5x by Daniel Richard G.
20dnl
21dnl @category InstalledPackages
22dnl @author Caolan McNamara <caolan@skynet.ie>
23dnl @author Daniel Richard G. <skunk@iskunk.org>
24dnl @version 2005-01-21
25dnl @license GPLWithACException
26
27AC_DEFUN([AX_FUNC_WHICH_GETHOSTBYNAME_R], [
28
29    AC_LANG_PUSH(C)
30    AC_MSG_CHECKING([how many arguments gethostbyname_r() takes])
31
32    AC_CACHE_VAL(ac_cv_func_which_gethostbyname_r, [
33
34################################################################
35
36ac_cv_func_which_gethostbyname_r=unknown
37
38#
39# ONE ARGUMENT (sanity check)
40#
41
42# This should fail, as there is no variant of gethostbyname_r() that takes
43# a single argument. If it actually compiles, then we can assume that
44# netdb.h is not declaring the function, and the compiler is thereby
45# assuming an implicit prototype. In which case, we're out of luck.
46#
47AC_COMPILE_IFELSE(
48    AC_LANG_PROGRAM(
49	[[#include <netdb.h>]],
50	[[
51	    char *name = "www.gnu.org";
52	    (void)gethostbyname_r(name) /* ; */
53	]]),
54    ac_cv_func_which_gethostbyname_r=no)
55
56#
57# SIX ARGUMENTS
58# (e.g. Linux)
59#
60
61if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
62
63AC_COMPILE_IFELSE(
64    AC_LANG_PROGRAM(
65	[[#include <netdb.h>]],
66	[[
67	    char *name = "www.gnu.org";
68	    struct hostent ret, *retp;
69	    char buf@<:@1024@:>@;
70	    int buflen = 1024;
71	    int my_h_errno;
72	    (void)gethostbyname_r(name, &ret, buf, buflen, &retp, &my_h_errno) /* ; */
73	]]),
74    ac_cv_func_which_gethostbyname_r=six)
75
76fi
77
78#
79# FIVE ARGUMENTS
80# (e.g. Solaris)
81#
82
83if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
84
85AC_COMPILE_IFELSE(
86    AC_LANG_PROGRAM(
87	[[#include <netdb.h>]],
88	[[
89	    char *name = "www.gnu.org";
90	    struct hostent ret;
91	    char buf@<:@1024@:>@;
92	    int buflen = 1024;
93	    int my_h_errno;
94	    (void)gethostbyname_r(name, &ret, buf, buflen, &my_h_errno) /* ; */
95	]]),
96    ac_cv_func_which_gethostbyname_r=five)
97
98fi
99
100#
101# THREE ARGUMENTS
102# (e.g. AIX, HP-UX, Tru64)
103#
104
105if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
106
107AC_COMPILE_IFELSE(
108    AC_LANG_PROGRAM(
109	[[#include <netdb.h>]],
110	[[
111	    char *name = "www.gnu.org";
112	    struct hostent ret;
113	    struct hostent_data data;
114	    (void)gethostbyname_r(name, &ret, &data) /* ; */
115	]]),
116    ac_cv_func_which_gethostbyname_r=three)
117
118fi
119
120################################################################
121
122]) dnl end AC_CACHE_VAL
123
124case "$ac_cv_func_which_gethostbyname_r" in
125    three)
126    AC_MSG_RESULT([three])
127    AC_DEFINE(HAVE_FUNC_GETHOSTBYNAME_R_3)
128    ;;
129
130    five)
131    AC_MSG_RESULT([five])
132    AC_DEFINE(HAVE_FUNC_GETHOSTBYNAME_R_5)
133    ;;
134
135    six)
136    AC_MSG_RESULT([six])
137    AC_DEFINE(HAVE_FUNC_GETHOSTBYNAME_R_6)
138    ;;
139
140    no)
141    AC_MSG_RESULT([cannot find function declaration in netdb.h])
142    ;;
143
144    unknown)
145    AC_MSG_RESULT([can't tell])
146    ;;
147
148    *)
149    AC_MSG_ERROR([internal error])
150    ;;
151esac
152
153AC_LANG_POP(C)
154
155]) dnl end AC_DEFUN
156