build: use -fstack-protector if available
[sfrench/samba-autobuild/.git] / lib / replace / libreplace_network.m4
1 AC_DEFUN_ONCE(AC_LIBREPLACE_NETWORK_CHECKS,
2 [
3 echo "LIBREPLACE_NETWORK_CHECKS: START"
4
5 AC_DEFINE(LIBREPLACE_NETWORK_CHECKS, 1, [LIBREPLACE_NETWORK_CHECKS were used])
6 LIBREPLACE_NETWORK_OBJS=""
7 LIBREPLACE_NETWORK_LIBS=""
8
9 AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
10 AC_CHECK_HEADERS(netinet/in_systm.h)
11 AC_CHECK_HEADERS([netinet/ip.h], [], [],[
12         #include <sys/types.h>
13         #ifdef HAVE_NETINET_IN_H
14         #include <netinet/in.h>
15         #endif
16         #ifdef HAVE_NETINET_IN_SYSTM_H
17         #include <netinet/in_systm.h>
18         #endif
19 ])
20 AC_CHECK_HEADERS(netinet/tcp.h netinet/in_ip.h)
21 AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
22 AC_CHECK_HEADERS(sys/uio.h)
23
24 dnl we need to check that net/if.h really can be used, to cope with hpux
25 dnl where including it always fails
26 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
27         AC_COMPILE_IFELSE([AC_LANG_SOURCE([
28                 AC_INCLUDES_DEFAULT
29                 #if HAVE_SYS_SOCKET_H
30                 # include <sys/socket.h>
31                 #endif
32                 #include <net/if.h>
33                 int main(void) {return 0;}])],
34                 [libreplace_cv_USABLE_NET_IF_H=yes],
35                 [libreplace_cv_USABLE_NET_IF_H=no]
36         )
37 ])
38 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
39         AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
40 fi
41
42 AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
43 AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
44 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
45 AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
46 AC_HAVE_TYPE([struct sockaddr_storage], [
47 #include <sys/socket.h>
48 #include <sys/types.h>
49 #include <netinet/in.h>
50 ])
51 AC_HAVE_TYPE([struct sockaddr_in6], [
52 #include <sys/socket.h>
53 #include <sys/types.h>
54 #include <netinet/in.h>
55 ])
56
57 if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
58 AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
59                 AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
60                 [
61 #include <sys/socket.h>
62 #include <sys/types.h>
63 #include <netinet/in.h>
64                 ])
65
66 if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
67 AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
68                 AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
69                 [
70 #include <sys/socket.h>
71 #include <sys/types.h>
72 #include <netinet/in.h>
73                 ])
74 fi
75 fi
76
77 AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
78         AC_TRY_COMPILE(
79                 [
80 #include <sys/types.h>
81 #include <sys/socket.h>
82 #include <netinet/in.h>
83                 ],[
84 struct sockaddr_in sock; sock.sin_len = sizeof(sock);
85                 ],[
86                 libreplace_cv_HAVE_SOCK_SIN_LEN=yes
87                 ],[
88                 libreplace_cv_HAVE_SOCK_SIN_LEN=no
89                 ])
90 ])
91 if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then
92         AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
93 fi
94
95 ############################################
96 # check for unix domain sockets
97 AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
98         AC_TRY_COMPILE([
99 #include <sys/types.h>
100 #include <stdlib.h>
101 #include <stddef.h>
102 #include <sys/socket.h>
103 #include <sys/un.h>
104                 ],[
105 struct sockaddr_un sunaddr;
106 sunaddr.sun_family = AF_UNIX;
107                 ],[
108                 libreplace_cv_HAVE_UNIXSOCKET=yes
109                 ],[
110                 libreplace_cv_HAVE_UNIXSOCKET=no
111                 ])
112 ])
113 if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
114         AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support])
115 fi
116
117 dnl The following test is roughly taken from the cvs sources.
118 dnl
119 dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
120 dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
121 dnl libsocket.so which has a bad implementation of gethostbyname (it
122 dnl only looks in /etc/hosts), so we only look for -lsocket if we need
123 dnl it.
124 AC_CHECK_FUNCS(connect)
125 if test x"$ac_cv_func_connect" = x"no"; then
126         AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect)
127         AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect)
128         AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect)
129         AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect)
130         dnl We can't just call AC_CHECK_FUNCS(connect) here,
131         dnl because the value has been cached.
132         if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
133                 test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
134                 test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
135                 test x"$ac_cv_lib_ext_inet_connect" = x"yes"
136         then
137                 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
138         fi
139 fi
140
141 AC_CHECK_FUNCS(gethostbyname)
142 if test x"$ac_cv_func_gethostbyname" = x"no"; then
143         AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname)
144         AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname)
145         AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname)
146         dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
147         dnl because the value has been cached.
148         if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
149                 test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
150                 test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
151         then
152                 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
153                           [Whether the system has gethostbyname()])
154         fi
155 fi
156
157 dnl HP-UX has if_nametoindex in -lipv6
158 AC_CHECK_FUNCS(if_nametoindex)
159 if test x"$ac_cv_func_if_nametoindex" = x"no"; then
160         AC_CHECK_LIB_EXT(ipv6, LIBREPLACE_NETWORK_LIBS, if_nametoindex)
161         dnl We can't just call AC_CHECK_FUNCS(if_nametoindex) here,
162         dnl because the value has been cached.
163         if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes"
164         then
165                 AC_DEFINE(HAVE_IF_NAMETOINDEX, 1,
166                           [Whether the system has if_nametoindex()])
167         fi
168 fi
169
170 # The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
171 old_LIBS=$LIBS
172 LIBS="${LIBREPLACE_NETWORK_LIBS}"
173 libreplace_SAVE_CPPFLAGS="$CPPFLAGS"
174 CPPFLAGS="$CPPFLAGS -I$libreplacedir"
175
176 AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/socketpair.o"])
177
178 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
179 AC_TRY_RUN([
180 #include <stdio.h>
181 #include <unistd.h>
182 #include <sys/types.h>
183 #include <netinet/in.h>
184 #ifdef HAVE_ARPA_INET_H
185 #include <arpa/inet.h>
186 #endif
187 main() { struct in_addr ip; ip.s_addr = 0x12345678;
188 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
189     strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
190 exit(1);}],
191            libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
192
193 AC_CHECK_FUNCS(inet_ntoa,[],[libreplace_cv_REPLACE_INET_NTOA=yes])
194 if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
195     AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
196     LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntoa.o"
197 fi
198
199 AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_aton.o"])
200
201 AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntop.o"])
202
203 AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_pton.o"])
204
205 dnl test for getaddrinfo/getnameinfo
206 AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
207 AC_TRY_LINK([
208 #include <sys/types.h>
209 #if STDC_HEADERS
210 #include <stdlib.h>
211 #include <stddef.h>
212 #endif
213 #include <sys/socket.h>
214 #include <netdb.h>],
215 [
216 struct sockaddr sa;
217 struct addrinfo *ai = NULL;
218 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
219 if (ret != 0) {
220         const char *es = gai_strerror(ret);
221 }
222 freeaddrinfo(ai);
223 ret = getnameinfo(&sa, sizeof(sa),
224                 NULL, 0,
225                 NULL, 0, 0);
226
227 ],
228 libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)])
229
230 if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
231         # getaddrinfo is broken on some AIX systems
232         # see bug 5910, use our replacements if we detect
233         # a broken system.
234         AC_TRY_RUN([
235                 #include <stddef.h>
236                 #include <sys/types.h>
237                 #include <sys/socket.h>
238                 #include <netdb.h>
239                 int main(int argc, const char *argv[])
240                 {
241                         struct addrinfo hints = {0,};
242                         struct addrinfo *ppres;
243                         const char hostname1[] = "0.0.0.0";
244                         const char hostname2[] = "127.0.0.1";
245                         const char hostname3[] = "::";
246                         hints.ai_socktype = SOCK_STREAM;
247                         hints.ai_family = AF_UNSPEC;
248                         hints.ai_flags =
249                                 AI_NUMERICHOST|AI_PASSIVE|AI_ADDRCONFIG;
250                         /* Test for broken flag combination on AIX. */
251                         if (getaddrinfo(hostname1, NULL, &hints, &ppres) == EAI_BADFLAGS) {
252                                 /* This fails on an IPv6-only box, but not with
253                                    the EAI_BADFLAGS error. */
254                                 return 1;
255                         }
256                         if (getaddrinfo(hostname2, NULL, &hints, &ppres) == 0) {
257                                 /* IPv4 lookup works - good enough. */
258                                 return 0;
259                         }
260                         /* Uh-oh, no IPv4. Are we IPv6-only ? */
261                         return getaddrinfo(hostname3, NULL, &hints, &ppres) != 0 ? 1 : 0;
262                 }],
263                 libreplace_cv_HAVE_GETADDRINFO=yes,
264                 libreplace_cv_HAVE_GETADDRINFO=no)
265 fi
266
267 if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
268         AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo])
269         AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo])
270         AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
271         AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
272 else
273         LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getaddrinfo.o"
274 fi
275
276 AC_CHECK_HEADERS([ifaddrs.h])
277
278 dnl Used when getifaddrs is not available
279 AC_CHECK_MEMBERS([struct sockaddr.sa_len], 
280          [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
281          [],
282          [#include <sys/socket.h>])
283
284 dnl test for getifaddrs and freeifaddrs
285 AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
286 AC_TRY_LINK([
287 #include <sys/types.h>
288 #if STDC_HEADERS
289 #include <stdlib.h>
290 #include <stddef.h>
291 #endif
292 #include <sys/socket.h>
293 #include <netinet/in.h>
294 #include <arpa/inet.h>
295 #include <ifaddrs.h>
296 #include <netdb.h>],
297 [
298 struct ifaddrs *ifp = NULL;
299 int ret = getifaddrs (&ifp);
300 freeifaddrs(ifp);
301 ],
302 libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
303 if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
304     AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
305     AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
306         AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
307 fi
308
309 ##################
310 # look for a method of finding the list of network interfaces
311 iface=no;
312 AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
313 AC_TRY_RUN([
314 #define HAVE_IFACE_GETIFADDRS 1
315 #define NO_CONFIG_H 1
316 #define AUTOCONF_TEST 1
317 #define SOCKET_WRAPPER_NOT_REPLACE
318 #include "$libreplacedir/replace.c"
319 #include "$libreplacedir/inet_ntop.c"
320 #include "$libreplacedir/snprintf.c"
321 #include "$libreplacedir/getifaddrs.c"
322 #define getifaddrs_test main
323 #include "$libreplacedir/test/getifaddrs.c"],
324            libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
325 if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
326     iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
327 else
328         LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getifaddrs.o"
329 fi
330
331
332 if test $iface = no; then
333 AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
334 AC_TRY_RUN([
335 #define HAVE_IFACE_AIX 1
336 #define NO_CONFIG_H 1
337 #define AUTOCONF_TEST 1
338 #undef _XOPEN_SOURCE_EXTENDED
339 #define SOCKET_WRAPPER_NOT_REPLACE
340 #include "$libreplacedir/replace.c"
341 #include "$libreplacedir/inet_ntop.c"
342 #include "$libreplacedir/snprintf.c"
343 #include "$libreplacedir/getifaddrs.c"
344 #define getifaddrs_test main
345 #include "$libreplacedir/test/getifaddrs.c"],
346            libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
347 if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
348     iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
349 fi
350 fi
351
352
353 if test $iface = no; then
354 AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
355 AC_TRY_RUN([
356 #define HAVE_IFACE_IFCONF 1
357 #define NO_CONFIG_H 1
358 #define AUTOCONF_TEST 1
359 #define SOCKET_WRAPPER_NOT_REPLACE
360 #include "$libreplacedir/replace.c"
361 #include "$libreplacedir/inet_ntop.c"
362 #include "$libreplacedir/snprintf.c"
363 #include "$libreplacedir/getifaddrs.c"
364 #define getifaddrs_test main
365 #include "$libreplacedir/test/getifaddrs.c"],
366            libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
367 if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
368     iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
369 fi
370 fi
371
372 if test $iface = no; then
373 AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
374 AC_TRY_RUN([
375 #define HAVE_IFACE_IFREQ 1
376 #define NO_CONFIG_H 1
377 #define AUTOCONF_TEST 1
378 #define SOCKET_WRAPPER_NOT_REPLACE
379 #include "$libreplacedir/replace.c"
380 #include "$libreplacedir/inet_ntop.c"
381 #include "$libreplacedir/snprintf.c"
382 #include "$libreplacedir/getifaddrs.c"
383 #define getifaddrs_test main
384 #include "$libreplacedir/test/getifaddrs.c"],
385            libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
386 if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
387     iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
388 fi
389 fi
390
391 dnl Some old Linux systems have broken header files and
392 dnl miss the IPV6_V6ONLY define in netinet/in.h,
393 dnl but have it in linux/in6.h.
394 dnl We can't include both files so we just check if the value
395 dnl if defined and do the replacement in system/network.h
396 AC_CACHE_CHECK([for IPV6_V6ONLY support],libreplace_cv_HAVE_IPV6_V6ONLY,[
397         AC_TRY_COMPILE([
398 #include <stdlib.h> /* for NULL */
399 #include <sys/socket.h>
400 #include <sys/types.h>
401 #include <netdb.h>
402 #include <netinet/in.h>
403                 ],
404                 [
405 #ifndef IPV6_V6ONLY
406 #error no IPV6_V6ONLY
407 #endif
408                 ],[
409                 libreplace_cv_HAVE_IPV6_V6ONLY=yes
410                 ],[
411                 libreplace_cv_HAVE_IPV6_V6ONLY=no
412                 ])
413 ])
414 if test x"$libreplace_cv_HAVE_IPV6_V6ONLY" != x"yes"; then
415    dnl test for IPV6_V6ONLY
416    AC_CACHE_CHECK([for IPV6_V6ONLY in linux/in6.h],libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26,[
417         AC_TRY_COMPILE([
418         #include <linux/in6.h>
419                 ],
420                 [
421         #if (IPV6_V6ONLY != 26)
422         #error no linux IPV6_V6ONLY
423         #endif
424                 ],[
425                 libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26=yes
426                 ],[
427                 libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26=no
428                 ])
429         ])
430         if test x"$libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26" = x"yes"; then
431                 AC_DEFINE(HAVE_LINUX_IPV6_V6ONLY_26,1,[Whether the system has IPV6_V6ONLY in linux/in6.h])
432         fi
433 fi
434
435 dnl test for ipv6
436 AC_CACHE_CHECK([for ipv6 support],libreplace_cv_HAVE_IPV6,[
437         AC_TRY_LINK([
438 #include <stdlib.h> /* for NULL */
439 #include <sys/socket.h>
440 #include <sys/types.h>
441 #include <netdb.h>
442 #include <netinet/in.h>
443                 ],
444                 [
445 struct sockaddr_storage sa_store;
446 struct addrinfo *ai = NULL;
447 struct in6_addr in6addr;
448 int idx = if_nametoindex("iface1");
449 int s = socket(AF_INET6, SOCK_STREAM, 0);
450 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
451 if (ret != 0) {
452         const char *es = gai_strerror(ret);
453 }
454 freeaddrinfo(ai);
455 {
456         int val = 1;
457         #ifdef HAVE_LINUX_IPV6_V6ONLY_26
458         #define IPV6_V6ONLY 26
459         #endif
460         ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
461                          (const void *)&val, sizeof(val));
462 }
463                 ],[
464                 libreplace_cv_HAVE_IPV6=yes
465                 ],[
466                 libreplace_cv_HAVE_IPV6=no
467                 ])
468 ])
469 if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then
470     AC_DEFINE(HAVE_IPV6,1,[Whether the system has IPv6 support])
471 fi
472
473 LIBS=$old_LIBS
474 CPPFLAGS="$libreplace_SAVE_CPPFLAGS"
475
476 AC_CACHE_CHECK([for SO_PEERCRED],libreplace_cv_HAVE_PEERCRED,[
477 AC_TRY_COMPILE([#include <sys/types.h>
478 #include <sys/socket.h>],
479 [struct ucred cred;
480  socklen_t cred_len;
481  int ret = getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len);
482 ],
483 libreplace_cv_HAVE_PEERCRED=yes,libreplace_cv_HAVE_PEERCRED=no,libreplace_cv_HAVE_PEERCRED=cross)])
484 if test x"$libreplace_cv_HAVE_PEERCRED" = x"yes"; then
485     AC_DEFINE(HAVE_PEERCRED,1,[Whether we can use SO_PEERCRED to get socket credentials])
486 fi
487
488 AC_CACHE_CHECK([for getpeereid],libreplace_cv_HAVE_GETPEEREID,[
489 AC_TRY_LINK([#include <sys/types.h>
490 #include <unistd.h>],
491 [uid_t uid; gid_t gid; int ret;
492  ret = getpeereid(0, &uid, &gid);
493 ],
494 libreplace_cv_HAVE_GETPEEREID=yes,libreplace_cv_HAVE_GETPEEREID=no)])
495 if test x"$libreplace_cv_HAVE_GETPEEREID" = xyes; then
496    AC_DEFINE(HAVE_GETPEEREID,1,
497              [Whether we have getpeereid to get socket credentials])
498 fi
499
500 LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
501
502 echo "LIBREPLACE_NETWORK_CHECKS: END"
503 ]) dnl end AC_LIBREPLACE_NETWORK_CHECKS