Commit 1a2b8896 authored by Yang Tse's avatar Yang Tse
Browse files

Initial step towards a configure time ares_socklen_t definition

parent f7a188a6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ Makefile.in
aclocal.m4
adig
ahost
ares_build.h
ares_version.h.dist
autom4te.cache
config.guess
+5 −2
Original line number Diff line number Diff line
@@ -46,7 +46,9 @@ noinst_PROGRAMS =$(PROGS)
EXTRA_DIST = AUTHORS CHANGES README.cares Makefile.inc Makefile.dj	   \
 Makefile.m32 Makefile.netware Makefile.vc6 $(man_MANS) $(MSVCFILES)	   \
 config-win32.h RELEASE-NOTES libcares.pc.in buildconf get_ver.awk maketgz \
 TODO
 TODO ares_build.h.in

DISTCLEANFILES = ares_build.h

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libcares.pc
@@ -96,7 +98,8 @@ libcares_la_SOURCES = $(CSOURCES) $(HHEADERS)
# where to install the c-ares headers
libcares_ladir = $(includedir)
# what headers to install on 'make install':
libcares_la_HEADERS = ares.h ares_version.h ares_dns.h
libcares_la_HEADERS = ares.h ares_version.h ares_dns.h \
	ares_build.h ares_rules.h

ahost_SOURCES = ahost.c ares_getopt.c ares_getopt.h
ahost_LDADD = $(top_builddir)/$(lib_LTLIBRARIES)
+2 −1
Original line number Diff line number Diff line
@@ -10,7 +10,8 @@ ares_parse_ns_reply.c ares_llist.c ares__timeval.c ares_strcasecmp.c

HHEADERS = ares.h ares_private.h setup.h ares_dns.h ares_version.h          \
 nameser.h inet_net_pton.h inet_ntop.h ares_ipv6.h bitncmp.h setup_once.h   \
 ares_llist.h ares_strdup.h ares_strcasecmp.h ares_writev.h
 ares_llist.h ares_strdup.h ares_strcasecmp.h ares_writev.h ares_build.h    \
 ares_rules.h

MANPAGES= ares_destroy.3 ares_expand_name.3 ares_expand_string.3 ares_fds.3 \
 ares_free_hostent.3 ares_free_string.3 ares_gethostbyaddr.3		    \
+162 −0
Original line number Diff line number Diff line
@@ -1737,6 +1737,168 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
])


dnl CARES_DEFINE_UNQUOTED (VARIABLE, [VALUE])
dnl -------------------------------------------------
dnl Like AC_DEFINE_UNQUOTED this macro will define a C preprocessor
dnl symbol that can be further used in custom template configuration
dnl files. This macro, unlike AC_DEFINE_UNQUOTED, does not use a third
dnl argument for the description. Symbol definitions done with this
dnl macro are intended to be exclusively used in handcrafted *.h.in
dnl template files. Contrary to what AC_DEFINE_UNQUOTED does, this one
dnl prevents autoheader generation and insertion of symbol template
dnl stub and definition into the first configuration header file. Do
dnl not use this macro as a replacement for AC_DEFINE_UNQUOTED, each
dnl one serves different functional needs.

AC_DEFUN([CARES_DEFINE_UNQUOTED], [
cat >>confdefs.h <<_EOF
[@%:@define] $1 ifelse($#, 2, [$2], 1)
_EOF
])


dnl CARES_CONFIGURE_LONG
dnl -------------------------------------------------
dnl Find out the size of long as reported by sizeof() and define
dnl CARES_SIZEOF_LONG as appropriate to be used in template file
dnl ares_build.h.in to properly configure the library.
dnl The size of long is a build time characteristic and as such
dnl must be recorded in ares_build.h

AC_DEFUN([CARES_CONFIGURE_LONG], [
  if test -z "$ac_cv_sizeof_long" ||
    test "$ac_cv_sizeof_long" -eq "0"; then
    AC_MSG_ERROR([cannot find out size of long.])
  fi
  CARES_DEFINE_UNQUOTED([CARES_SIZEOF_LONG], [$ac_cv_sizeof_long])
])


dnl CARES_CONFIGURE_ARES_SOCKLEN_T
dnl -------------------------------------------------
dnl Find out suitable ares_socklen_t data type definition and size, making
dnl appropriate definitions for template file ares_build.h.in
dnl to properly configure and use the library.
dnl
dnl The need for the ares_socklen_t definition arises mainly to properly
dnl interface HP-UX systems which on one hand have a typedef'ed socklen_t
dnl data type which is 32 or 64-Bit wide depending on the data model being
dnl used, and that on the other hand is only actually used when interfacing
dnl the X/Open sockets provided in the xnet library.

AC_DEFUN([CARES_CONFIGURE_ARES_SOCKLEN_T], [
  AC_REQUIRE([CARES_INCLUDES_WS2TCPIP])dnl
  AC_REQUIRE([CARES_INCLUDES_SYS_SOCKET])dnl
  AC_REQUIRE([CARES_PREPROCESS_CALLCONV])dnl
  #
  AC_MSG_CHECKING([for ares_socklen_t data type])
  cares_typeof_ares_socklen_t="unknown"
  for arg1 in int SOCKET; do
    for arg2 in 'struct sockaddr' void; do
      for t in socklen_t int size_t 'unsigned int' long 'unsigned long' void; do
        if test "$cares_typeof_ares_socklen_t" = "unknown"; then
          AC_COMPILE_IFELSE([
            AC_LANG_PROGRAM([[
              $cares_includes_ws2tcpip
              $cares_includes_sys_socket
              $cares_preprocess_callconv
              extern int FUNCALLCONV getpeername($arg1, $arg2 *, $t *);
            ]],[[
              $t *lenptr = 0;
              if(0 != getpeername(0, 0, lenptr))
                return 1;
            ]])
          ],[
            cares_typeof_ares_socklen_t="$t"
          ])
        fi
      done
    done
  done
  for t in socklen_t int; do
    if test "$cares_typeof_ares_socklen_t" = "void"; then
      AC_COMPILE_IFELSE([
        AC_LANG_PROGRAM([[
          $cares_includes_sys_socket
          typedef $t ares_socklen_t;
        ]],[[
          ares_socklen_t dummy;
        ]])
      ],[
        cares_typeof_ares_socklen_t="$t"
      ])
    fi
  done
  AC_MSG_RESULT([$cares_typeof_ares_socklen_t])
  if test "$cares_typeof_ares_socklen_t" = "void" ||
    test "$cares_typeof_ares_socklen_t" = "unknown"; then
    AC_MSG_ERROR([cannot find data type for ares_socklen_t.])
  fi
  #
  AC_MSG_CHECKING([size of ares_socklen_t])
  cares_sizeof_ares_socklen_t="unknown"
  cares_pull_headers_socklen_t="unknown"
  if test "$ac_cv_header_ws2tcpip_h" = "yes"; then
    tst_pull_header_checks='none ws2tcpip'
    tst_size_checks='4'
  else
    tst_pull_header_checks='none systypes syssocket'
    tst_size_checks='4 8 2'
  fi
  for tst_size in $tst_size_checks; do
    for tst_pull_headers in $tst_pull_header_checks; do
      if test "$cares_sizeof_ares_socklen_t" = "unknown"; then
        case $tst_pull_headers in
          ws2tcpip)
            tmp_includes="$cares_includes_ws2tcpip"
            ;;
          systypes)
            tmp_includes="$cares_includes_sys_types"
            ;;
          syssocket)
            tmp_includes="$cares_includes_sys_socket"
            ;;
          *)
            tmp_includes=""
            ;;
        esac
        AC_COMPILE_IFELSE([
          AC_LANG_PROGRAM([[
            $tmp_includes
            typedef $cares_typeof_ares_socklen_t ares_socklen_t;
            typedef char dummy_arr[sizeof(ares_socklen_t) == $tst_size ? 1 : -1];
          ]],[[
            ares_socklen_t dummy;
          ]])
        ],[
          cares_sizeof_ares_socklen_t="$tst_size"
          cares_pull_headers_socklen_t="$tst_pull_headers"
        ])
      fi
    done
  done
  AC_MSG_RESULT([$cares_sizeof_ares_socklen_t])
  if test "$cares_sizeof_ares_socklen_t" = "unknown"; then
    AC_MSG_ERROR([cannot find out size of ares_socklen_t.])
  fi
  #
  case $cares_pull_headers_socklen_t in
    ws2tcpip)
      CARES_DEFINE_UNQUOTED([CARES_PULL_WS2TCPIP_H])
      ;;
    systypes)
      CARES_DEFINE_UNQUOTED([CARES_PULL_SYS_TYPES_H])
      ;;
    syssocket)
      CARES_DEFINE_UNQUOTED([CARES_PULL_SYS_TYPES_H])
      CARES_DEFINE_UNQUOTED([CARES_PULL_SYS_SOCKET_H])
      ;;
  esac
  CARES_DEFINE_UNQUOTED([CARES_TYPEOF_ARES_SOCKLEN_T], [$cares_typeof_ares_socklen_t])
  CARES_DEFINE_UNQUOTED([CARES_SIZEOF_ARES_SOCKLEN_T], [$cares_sizeof_ares_socklen_t])
])


dnl This macro determines if the specified struct exists in the specified file
dnl Syntax:
dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include "inet_ntop.h"
#include "inet_net_pton.h"
#include "ares_getopt.h"
#include "ares_ipv6.h"

#ifndef HAVE_STRDUP
#  include "ares_strdup.h"
Loading