1
# gethostname.m4 serial 13
2
dnl Copyright (C) 2002, 2008-2013 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.
8
# - the gethostname() function,
9
# - the HOST_NAME_MAX macro in <limits.h>.
10
AC_DEFUN([gl_FUNC_GETHOSTNAME],
12
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
13
gl_PREREQ_SYS_H_WINSOCK2
15
dnl Where is gethostname() defined?
16
dnl - On native Windows, it is in ws2_32.dll.
17
dnl - Otherwise it is in libc.
19
AC_CHECK_FUNCS([gethostname], , [
20
AC_CACHE_CHECK([for gethostname in winsock2.h and -lws2_32],
21
[gl_cv_w32_gethostname],
22
[gl_cv_w32_gethostname=no
25
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
26
#ifdef HAVE_WINSOCK2_H
30
]], [[gethostname(NULL, 0);]])], [gl_cv_w32_gethostname=yes])
33
if test "$gl_cv_w32_gethostname" = "yes"; then
34
GETHOSTNAME_LIB="-lws2_32"
37
AC_SUBST([GETHOSTNAME_LIB])
39
if test "$ac_cv_func_gethostname" = no; then
43
gl_PREREQ_HOST_NAME_MAX
46
# Provide HOST_NAME_MAX when <limits.h> lacks it.
47
AC_DEFUN([gl_PREREQ_HOST_NAME_MAX], [
48
dnl - On most Unix systems, use MAXHOSTNAMELEN from <sys/param.h> instead.
49
dnl - On Solaris, Cygwin, BeOS, use MAXHOSTNAMELEN from <netdb.h> instead.
50
dnl - On mingw, use 256, because
51
dnl <http://msdn.microsoft.com/en-us/library/ms738527.aspx> says:
52
dnl "if a buffer of 256 bytes is passed in the name parameter and
53
dnl the namelen parameter is set to 256, the buffer size will always
55
dnl With this, there is no need to use sysconf (_SC_HOST_NAME_MAX), which
56
dnl is not a compile-time constant.
57
dnl We cannot override <limits.h> using the usual technique, because
58
dnl gl_CHECK_NEXT_HEADERS does not work for <limits.h>. Therefore retrieve
59
dnl the value of HOST_NAME_MAX at configure time.
60
AC_CHECK_HEADERS_ONCE([sys/param.h])
61
AC_CHECK_HEADERS_ONCE([sys/socket.h])
62
AC_CHECK_HEADERS_ONCE([netdb.h])
63
AC_CACHE_CHECK([for HOST_NAME_MAX], [gl_cv_decl_HOST_NAME_MAX], [
64
gl_cv_decl_HOST_NAME_MAX=
65
AC_EGREP_CPP([lucky], [
70
], [gl_cv_decl_HOST_NAME_MAX=yes])
71
if test -z "$gl_cv_decl_HOST_NAME_MAX"; then
72
dnl It's not defined in <limits.h>. Substitute it.
73
if test "$gl_cv_w32_gethostname" = yes; then
75
gl_cv_decl_HOST_NAME_MAX=256
77
_AC_COMPUTE_INT([MAXHOSTNAMELEN], [gl_cv_decl_HOST_NAME_MAX], [
78
#include <sys/types.h>
80
# include <sys/param.h>
83
# include <sys/socket.h>
89
[dnl The system does not define MAXHOSTNAMELEN in any of the common
90
dnl headers. Use a safe fallback.
91
gl_cv_decl_HOST_NAME_MAX=256
96
if test "$gl_cv_decl_HOST_NAME_MAX" != yes; then
97
AC_DEFINE_UNQUOTED([HOST_NAME_MAX], [$gl_cv_decl_HOST_NAME_MAX],
98
[Define HOST_NAME_MAX when <limits.h> does not define it.])
102
# Prerequisites of lib/gethostname.c.
103
AC_DEFUN([gl_PREREQ_GETHOSTNAME], [
104
if test "$gl_cv_w32_gethostname" != "yes"; then
105
AC_CHECK_FUNCS([uname])