]> granicus.if.org Git - curl/commitdiff
configure: detect getsockname and getpeername on windows too
authorDaniel Stenberg <daniel@haxx.se>
Tue, 21 May 2019 08:06:06 +0000 (10:06 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 21 May 2019 11:42:25 +0000 (13:42 +0200)
Made detection macros for these two functions in the same style as other
functions possibly in winsock in the hope this will work better to
detect these functions when cross-compiling for Windows.

Follow-up to e91e4816123

Fixes #3913
Closes #3915

configure.ac
m4/curl-functions.m4

index 13e8e297b37fd26c78a07bce6389e5a6292d4d54..3e45b51511729cad2e1de76926d09eb01df2fc7a 100755 (executable)
@@ -3719,6 +3719,8 @@ CURL_CHECK_FUNC_GETHOSTBYADDR_R
 CURL_CHECK_FUNC_GETHOSTBYNAME
 CURL_CHECK_FUNC_GETHOSTBYNAME_R
 CURL_CHECK_FUNC_GETHOSTNAME
+CURL_CHECK_FUNC_GETPEERNAME
+CURL_CHECK_FUNC_GETSOCKNAME
 CURL_CHECK_FUNC_GETIFADDRS
 CURL_CHECK_FUNC_GETSERVBYPORT_R
 CURL_CHECK_FUNC_GMTIME_R
@@ -3772,8 +3774,6 @@ AC_CHECK_FUNCS([fnmatch \
   getpwuid_r \
   getrlimit \
   gettimeofday \
-  getpeername \
-  getsockname \
   if_nametoindex \
   mach_absolute_time \
   pipe \
index 8249108bb92b989a7b804fd389f45e3807ccd217..b79e181987d5b5c7bd757408cb5e3b911a39928a 100644 (file)
@@ -2912,6 +2912,201 @@ AC_DEFUN([CURL_CHECK_FUNC_GETHOSTNAME], [
   fi
 ])
 
+dnl CURL_CHECK_FUNC_GETPEERNAME
+dnl -------------------------------------------------
+dnl Verify if getpeername is available, prototyped, and
+dnl can be compiled. If all of these are true, and
+dnl usage has not been previously disallowed with
+dnl shell variable curl_disallow_getpeername, then
+dnl HAVE_GETPEERNAME will be defined.
+
+AC_DEFUN([CURL_CHECK_FUNC_GETPEERNAME], [
+  AC_REQUIRE([CURL_INCLUDES_WINSOCK2])dnl
+  AC_REQUIRE([CURL_INCLUDES_UNISTD])dnl
+  AC_REQUIRE([CURL_PREPROCESS_CALLCONV])dnl
+  AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
+  #
+  tst_links_getpeername="unknown"
+  tst_proto_getpeername="unknown"
+  tst_compi_getpeername="unknown"
+  tst_allow_getpeername="unknown"
+  #
+  AC_MSG_CHECKING([if getpeername can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([[
+      $curl_includes_winsock2
+      $curl_includes_bsdsocket
+      $curl_includes_sys_socket
+    ]],[[
+      if(0 != getpeername(0, (void *)0, (void *)0))
+        return 1;
+    ]])
+  ],[
+    AC_MSG_RESULT([yes])
+    tst_links_getpeername="yes"
+  ],[
+    AC_MSG_RESULT([no])
+    tst_links_getpeername="no"
+  ])
+  #
+  if test "$tst_links_getpeername" = "yes"; then
+    AC_MSG_CHECKING([if getpeername is prototyped])
+    AC_EGREP_CPP([getpeername],[
+      $curl_includes_winsock2
+      $curl_includes_bsdsocket
+      $curl_includes_sys_socket
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_getpeername="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_getpeername="no"
+    ])
+  fi
+  #
+  if test "$tst_proto_getpeername" = "yes"; then
+    AC_MSG_CHECKING([if getpeername is compilable])
+    AC_COMPILE_IFELSE([
+      AC_LANG_PROGRAM([[
+        $curl_includes_winsock2
+        $curl_includes_bsdsocket
+        $curl_includes_sys_socket
+      ]],[[
+        if(0 != getpeername(0, (void *)0, (void *)0))
+          return 1;
+      ]])
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_compi_getpeername="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_compi_getpeername="no"
+    ])
+  fi
+  #
+  if test "$tst_compi_getpeername" = "yes"; then
+    AC_MSG_CHECKING([if getpeername usage allowed])
+    if test "x$curl_disallow_getpeername" != "xyes"; then
+      AC_MSG_RESULT([yes])
+      tst_allow_getpeername="yes"
+    else
+      AC_MSG_RESULT([no])
+      tst_allow_getpeername="no"
+    fi
+  fi
+  #
+  AC_MSG_CHECKING([if getpeername might be used])
+  if test "$tst_links_getpeername" = "yes" &&
+     test "$tst_proto_getpeername" = "yes" &&
+     test "$tst_compi_getpeername" = "yes" &&
+     test "$tst_allow_getpeername" = "yes"; then
+    AC_MSG_RESULT([yes])
+    AC_DEFINE_UNQUOTED(HAVE_GETPEERNAME, 1,
+      [Define to 1 if you have the getpeername function.])
+    curl_cv_func_getpeername="yes"
+  else
+    AC_MSG_RESULT([no])
+    curl_cv_func_getpeername="no"
+  fi
+])
+
+dnl CURL_CHECK_FUNC_GETSOCKNAME
+dnl -------------------------------------------------
+dnl Verify if getsockname is available, prototyped, and
+dnl can be compiled. If all of these are true, and
+dnl usage has not been previously disallowed with
+dnl shell variable curl_disallow_getsockname, then
+dnl HAVE_GETSOCKNAME will be defined.
+
+AC_DEFUN([CURL_CHECK_FUNC_GETSOCKNAME], [
+  AC_REQUIRE([CURL_INCLUDES_WINSOCK2])dnl
+  AC_REQUIRE([CURL_INCLUDES_UNISTD])dnl
+  AC_REQUIRE([CURL_PREPROCESS_CALLCONV])dnl
+  AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
+  #
+  tst_links_getsockname="unknown"
+  tst_proto_getsockname="unknown"
+  tst_compi_getsockname="unknown"
+  tst_allow_getsockname="unknown"
+  #
+  AC_MSG_CHECKING([if getsockname can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([[
+      $curl_includes_winsock2
+      $curl_includes_bsdsocket
+      $curl_includes_sys_socket
+    ]],[[
+      if(0 != getsockname(0, (void *)0, (void *)0))
+        return 1;
+    ]])
+  ],[
+    AC_MSG_RESULT([yes])
+    tst_links_getsockname="yes"
+  ],[
+    AC_MSG_RESULT([no])
+    tst_links_getsockname="no"
+  ])
+  #
+  if test "$tst_links_getsockname" = "yes"; then
+    AC_MSG_CHECKING([if getsockname is prototyped])
+    AC_EGREP_CPP([getsockname],[
+      $curl_includes_winsock2
+      $curl_includes_bsdsocket
+      $curl_includes_sys_socket
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_getsockname="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_getsockname="no"
+    ])
+  fi
+  #
+  if test "$tst_proto_getsockname" = "yes"; then
+    AC_MSG_CHECKING([if getsockname is compilable])
+    AC_COMPILE_IFELSE([
+      AC_LANG_PROGRAM([[
+        $curl_includes_winsock2
+        $curl_includes_bsdsocket
+        $curl_includes_sys_socket
+      ]],[[
+        if(0 != getsockname(0, (void *)0, (void *)0))
+          return 1;
+      ]])
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_compi_getsockname="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_compi_getsockname="no"
+    ])
+  fi
+  #
+  if test "$tst_compi_getsockname" = "yes"; then
+    AC_MSG_CHECKING([if getsockname usage allowed])
+    if test "x$curl_disallow_getsockname" != "xyes"; then
+      AC_MSG_RESULT([yes])
+      tst_allow_getsockname="yes"
+    else
+      AC_MSG_RESULT([no])
+      tst_allow_getsockname="no"
+    fi
+  fi
+  #
+  AC_MSG_CHECKING([if getsockname might be used])
+  if test "$tst_links_getsockname" = "yes" &&
+     test "$tst_proto_getsockname" = "yes" &&
+     test "$tst_compi_getsockname" = "yes" &&
+     test "$tst_allow_getsockname" = "yes"; then
+    AC_MSG_RESULT([yes])
+    AC_DEFINE_UNQUOTED(HAVE_GETSOCKNAME, 1,
+      [Define to 1 if you have the getsockname function.])
+    curl_cv_func_getsockname="yes"
+  else
+    AC_MSG_RESULT([no])
+    curl_cv_func_getsockname="no"
+  fi
+])
 
 dnl CURL_CHECK_FUNC_GETIFADDRS
 dnl -------------------------------------------------