File curl-8.13.0-CloseSocket.patch of Package curl

From 22352e627da60fc1b3965f4aa95ef5219a9df845 Mon Sep 17 00:00:00 2001
From: Viktor Szakats <commit@vsz.me>
Date: Wed, 2 Apr 2025 12:24:43 +0200
Subject: [PATCH] configure: restore link checks

The omitted link checks were not what I though they were. Omitting one
caused a mis-detection on Solaris, where the compile check alone
mis-detects `CloseSocket` as present.

Restore link checks for these functions:
`closesocket`, `ioctlsocket`, `socket`, `freeaddrinfo`, `getaddrinfo`,
`gethostname`, `getpeername`, `getsockname`,
`CloseSocket` (AmigaOS), `IoctlSocket` (AmigaOS).

Also re-sync link check code snippets with the ones in current master.

Partial revert of, regression from bd9f9b085aa242a5e93be0b2da96ce498d7813c4 #16377
Reported-by: Dagobert Michelsen
Bug: https://curl.se/mail/lib-2025-04/0004.html
Fixes #16915
Closes #16917
---
 m4/curl-functions.m4 | 351 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 282 insertions(+), 69 deletions(-)

diff --git a/m4/curl-functions.m4 b/m4/curl-functions.m4
index fe55cb922af2..7c5588cc006e 100644
--- a/m4/curl-functions.m4
+++ b/m4/curl-functions.m4
@@ -650,21 +650,40 @@ dnl HAVE_CLOSESOCKET will be defined.
 AC_DEFUN([CURL_CHECK_FUNC_CLOSESOCKET], [
   AC_REQUIRE([CURL_INCLUDES_WINSOCK2])dnl
   #
+  tst_links_closesocket="unknown"
   tst_proto_closesocket="unknown"
   tst_compi_closesocket="unknown"
   tst_allow_closesocket="unknown"
   #
-  AC_MSG_CHECKING([if closesocket is prototyped])
-  AC_EGREP_CPP([closesocket],[
-    $curl_includes_winsock2
+  AC_MSG_CHECKING([if closesocket can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([[
+      $curl_includes_winsock2
+    ]],[[
+      if(0 != closesocket(0))
+        return 1;
+    ]])
   ],[
     AC_MSG_RESULT([yes])
-    tst_proto_closesocket="yes"
+    tst_links_closesocket="yes"
   ],[
     AC_MSG_RESULT([no])
-    tst_proto_closesocket="no"
+    tst_links_closesocket="no"
   ])
   #
+  if test "$tst_links_closesocket" = "yes"; then
+    AC_MSG_CHECKING([if closesocket is prototyped])
+    AC_EGREP_CPP([closesocket],[
+      $curl_includes_winsock2
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_closesocket="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_closesocket="no"
+    ])
+  fi
+  #
   if test "$tst_proto_closesocket" = "yes"; then
     AC_MSG_CHECKING([if closesocket is compilable])
     AC_COMPILE_IFELSE([
@@ -695,7 +714,8 @@ AC_DEFUN([CURL_CHECK_FUNC_CLOSESOCKET], [
   fi
   #
   AC_MSG_CHECKING([if closesocket might be used])
-  if test "$tst_proto_closesocket" = "yes" &&
+  if test "$tst_links_closesocket" = "yes" &&
+     test "$tst_proto_closesocket" = "yes" &&
      test "$tst_compi_closesocket" = "yes" &&
      test "$tst_allow_closesocket" = "yes"; then
     AC_MSG_RESULT([yes])
@@ -721,11 +741,12 @@ AC_DEFUN([CURL_CHECK_FUNC_CLOSESOCKET_CAMEL], [
   AC_REQUIRE([CURL_INCLUDES_SYS_SOCKET])dnl
   AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
   #
+  tst_links_closesocket_camel="unknown"
   tst_compi_closesocket_camel="unknown"
   tst_allow_closesocket_camel="unknown"
   #
-  AC_MSG_CHECKING([if CloseSocket is compilable])
-  AC_COMPILE_IFELSE([
+  AC_MSG_CHECKING([if CloseSocket can be linked])
+  AC_LINK_IFELSE([
     AC_LANG_PROGRAM([[
       $curl_includes_bsdsocket
       $curl_includes_sys_socket
@@ -735,12 +756,31 @@ AC_DEFUN([CURL_CHECK_FUNC_CLOSESOCKET_CAMEL], [
     ]])
   ],[
     AC_MSG_RESULT([yes])
-    tst_compi_closesocket_camel="yes"
+    tst_links_closesocket_camel="yes"
   ],[
     AC_MSG_RESULT([no])
-    tst_compi_closesocket_camel="no"
+    tst_links_closesocket_camel="no"
   ])
   #
+  if test "$tst_links_closesocket_camel" = "yes"; then
+    AC_MSG_CHECKING([if CloseSocket is compilable])
+    AC_COMPILE_IFELSE([
+      AC_LANG_PROGRAM([[
+        $curl_includes_bsdsocket
+        $curl_includes_sys_socket
+      ]],[[
+        if(0 != CloseSocket(0))
+          return 1;
+      ]])
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_compi_closesocket_camel="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_compi_closesocket_camel="no"
+    ])
+  fi
+  #
   if test "$tst_compi_closesocket_camel" = "yes"; then
     AC_MSG_CHECKING([if CloseSocket usage allowed])
     if test "x$curl_disallow_closesocket_camel" != "xyes"; then
@@ -753,7 +793,8 @@ AC_DEFUN([CURL_CHECK_FUNC_CLOSESOCKET_CAMEL], [
   fi
   #
   AC_MSG_CHECKING([if CloseSocket might be used])
-  if test "$tst_compi_closesocket_camel" = "yes" &&
+  if test "$tst_links_closesocket_camel" = "yes" &&
+     test "$tst_compi_closesocket_camel" = "yes" &&
      test "$tst_allow_closesocket_camel" = "yes"; then
     AC_MSG_RESULT([yes])
     AC_DEFINE_UNQUOTED(HAVE_CLOSESOCKET_CAMEL, 1,
@@ -927,23 +968,43 @@ AC_DEFUN([CURL_CHECK_FUNC_FREEADDRINFO], [
   AC_REQUIRE([CURL_INCLUDES_SYS_SOCKET])dnl
   AC_REQUIRE([CURL_INCLUDES_NETDB])dnl
   #
+  tst_links_freeaddrinfo="unknown"
   tst_proto_freeaddrinfo="unknown"
   tst_compi_freeaddrinfo="unknown"
   tst_allow_freeaddrinfo="unknown"
   #
-  AC_MSG_CHECKING([if freeaddrinfo is prototyped])
-  AC_EGREP_CPP([freeaddrinfo],[
-    $curl_includes_ws2tcpip
-    $curl_includes_sys_socket
-    $curl_includes_netdb
+  AC_MSG_CHECKING([if freeaddrinfo can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([[
+      $curl_includes_ws2tcpip
+      $curl_includes_sys_socket
+      $curl_includes_netdb
+    ]],[[
+      freeaddrinfo(0);
+    ]])
   ],[
     AC_MSG_RESULT([yes])
-    tst_proto_freeaddrinfo="yes"
+    tst_links_freeaddrinfo="yes"
   ],[
     AC_MSG_RESULT([no])
-    tst_proto_freeaddrinfo="no"
+    tst_links_freeaddrinfo="no"
   ])
   #
+  if test "$tst_links_freeaddrinfo" = "yes"; then
+    AC_MSG_CHECKING([if freeaddrinfo is prototyped])
+    AC_EGREP_CPP([freeaddrinfo],[
+      $curl_includes_ws2tcpip
+      $curl_includes_sys_socket
+      $curl_includes_netdb
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_freeaddrinfo="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_freeaddrinfo="no"
+    ])
+  fi
+  #
   if test "$tst_proto_freeaddrinfo" = "yes"; then
     AC_MSG_CHECKING([if freeaddrinfo is compilable])
     AC_COMPILE_IFELSE([
@@ -975,7 +1036,8 @@ AC_DEFUN([CURL_CHECK_FUNC_FREEADDRINFO], [
   fi
   #
   AC_MSG_CHECKING([if freeaddrinfo might be used])
-  if test "$tst_proto_freeaddrinfo" = "yes" &&
+  if test "$tst_links_freeaddrinfo" = "yes" &&
+     test "$tst_proto_freeaddrinfo" = "yes" &&
      test "$tst_compi_freeaddrinfo" = "yes" &&
      test "$tst_allow_freeaddrinfo" = "yes"; then
     AC_MSG_RESULT([yes])
@@ -1215,25 +1277,47 @@ AC_DEFUN([CURL_CHECK_FUNC_GETADDRINFO], [
   AC_REQUIRE([CURL_INCLUDES_NETDB])dnl
   AC_REQUIRE([CURL_CHECK_NATIVE_WINDOWS])dnl
   #
+  tst_links_getaddrinfo="unknown"
   tst_proto_getaddrinfo="unknown"
   tst_compi_getaddrinfo="unknown"
   tst_works_getaddrinfo="unknown"
   tst_allow_getaddrinfo="unknown"
   tst_tsafe_getaddrinfo="unknown"
   #
-  AC_MSG_CHECKING([if getaddrinfo is prototyped])
-  AC_EGREP_CPP([getaddrinfo],[
-    $curl_includes_ws2tcpip
-    $curl_includes_sys_socket
-    $curl_includes_netdb
+  AC_MSG_CHECKING([if getaddrinfo can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([[
+      $curl_includes_ws2tcpip
+      $curl_includes_sys_socket
+      $curl_includes_netdb
+    ]],[[
+      struct addrinfo *ai = 0;
+      if(0 != getaddrinfo(0, 0, 0, &ai))
+        return 1;
+    ]])
   ],[
     AC_MSG_RESULT([yes])
-    tst_proto_getaddrinfo="yes"
+    tst_links_getaddrinfo="yes"
   ],[
     AC_MSG_RESULT([no])
-    tst_proto_getaddrinfo="no"
+    tst_links_getaddrinfo="no"
   ])
   #
+  if test "$tst_links_getaddrinfo" = "yes"; then
+    AC_MSG_CHECKING([if getaddrinfo is prototyped])
+    AC_EGREP_CPP([getaddrinfo],[
+      $curl_includes_ws2tcpip
+      $curl_includes_sys_socket
+      $curl_includes_netdb
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_getaddrinfo="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_getaddrinfo="no"
+    ])
+  fi
+  #
   if test "$tst_proto_getaddrinfo" = "yes"; then
     AC_MSG_CHECKING([if getaddrinfo is compilable])
     AC_COMPILE_IFELSE([
@@ -1564,23 +1648,45 @@ AC_DEFUN([CURL_CHECK_FUNC_GETHOSTNAME], [
   AC_REQUIRE([CURL_INCLUDES_UNISTD])dnl
   AC_REQUIRE([CURL_PREPROCESS_CALLCONV])dnl
   #
+  tst_links_gethostname="unknown"
   tst_proto_gethostname="unknown"
   tst_compi_gethostname="unknown"
   tst_allow_gethostname="unknown"
   #
-  AC_MSG_CHECKING([if gethostname is prototyped])
-  AC_EGREP_CPP([gethostname],[
-    $curl_includes_winsock2
-    $curl_includes_unistd
-    $curl_includes_bsdsocket
+  AC_MSG_CHECKING([if gethostname can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([[
+      $curl_includes_winsock2
+      $curl_includes_unistd
+      $curl_includes_bsdsocket
+    ]],[[
+      char s[1];
+      if(0 != gethostname((void *)s, 0))
+        return 1;
+    ]])
   ],[
     AC_MSG_RESULT([yes])
-    tst_proto_gethostname="yes"
+    tst_links_gethostname="yes"
   ],[
     AC_MSG_RESULT([no])
-    tst_proto_gethostname="no"
+    tst_links_gethostname="no"
   ])
   #
+  if test "$tst_links_gethostname" = "yes"; then
+    AC_MSG_CHECKING([if gethostname is prototyped])
+    AC_EGREP_CPP([gethostname],[
+      $curl_includes_winsock2
+      $curl_includes_unistd
+      $curl_includes_bsdsocket
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_gethostname="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_gethostname="no"
+    ])
+  fi
+  #
   if test "$tst_proto_gethostname" = "yes"; then
     AC_MSG_CHECKING([if gethostname is compilable])
     AC_COMPILE_IFELSE([
@@ -1650,7 +1756,8 @@ AC_DEFUN([CURL_CHECK_FUNC_GETHOSTNAME], [
   fi
   #
   AC_MSG_CHECKING([if gethostname might be used])
-  if test "$tst_proto_gethostname" = "yes" &&
+  if test "$tst_links_gethostname" = "yes" &&
+     test "$tst_proto_gethostname" = "yes" &&
      test "$tst_compi_gethostname" = "yes" &&
      test "$tst_allow_gethostname" = "yes"; then
     AC_MSG_RESULT([yes])
@@ -1677,23 +1784,44 @@ AC_DEFUN([CURL_CHECK_FUNC_GETPEERNAME], [
   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 is prototyped])
-  AC_EGREP_CPP([getpeername],[
-    $curl_includes_winsock2
-    $curl_includes_bsdsocket
-    $curl_includes_sys_socket
+  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_proto_getpeername="yes"
+    tst_links_getpeername="yes"
   ],[
     AC_MSG_RESULT([no])
-    tst_proto_getpeername="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([
@@ -1726,7 +1854,8 @@ AC_DEFUN([CURL_CHECK_FUNC_GETPEERNAME], [
   fi
   #
   AC_MSG_CHECKING([if getpeername might be used])
-  if test "$tst_proto_getpeername" = "yes" &&
+  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])
@@ -1753,23 +1882,44 @@ AC_DEFUN([CURL_CHECK_FUNC_GETSOCKNAME], [
   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 is prototyped])
-  AC_EGREP_CPP([getsockname],[
-    $curl_includes_winsock2
-    $curl_includes_bsdsocket
-    $curl_includes_sys_socket
+  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_proto_getsockname="yes"
+    tst_links_getsockname="yes"
   ],[
     AC_MSG_RESULT([no])
-    tst_proto_getsockname="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([
@@ -1802,7 +1952,8 @@ AC_DEFUN([CURL_CHECK_FUNC_GETSOCKNAME], [
   fi
   #
   AC_MSG_CHECKING([if getsockname might be used])
-  if test "$tst_proto_getsockname" = "yes" &&
+  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])
@@ -2578,21 +2729,40 @@ dnl HAVE_IOCTLSOCKET will be defined.
 AC_DEFUN([CURL_CHECK_FUNC_IOCTLSOCKET], [
   AC_REQUIRE([CURL_INCLUDES_WINSOCK2])dnl
   #
+  tst_links_ioctlsocket="unknown"
   tst_proto_ioctlsocket="unknown"
   tst_compi_ioctlsocket="unknown"
   tst_allow_ioctlsocket="unknown"
   #
-  AC_MSG_CHECKING([if ioctlsocket is prototyped])
-  AC_EGREP_CPP([ioctlsocket],[
-    $curl_includes_winsock2
+  AC_MSG_CHECKING([if ioctlsocket can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([[
+      $curl_includes_winsock2
+    ]],[[
+      if(0 != ioctlsocket(0, 0, 0))
+        return 1;
+    ]])
   ],[
     AC_MSG_RESULT([yes])
-    tst_proto_ioctlsocket="yes"
+    tst_links_ioctlsocket="yes"
   ],[
     AC_MSG_RESULT([no])
-    tst_proto_ioctlsocket="no"
+    tst_links_ioctlsocket="no"
   ])
   #
+  if test "$tst_links_ioctlsocket" = "yes"; then
+    AC_MSG_CHECKING([if ioctlsocket is prototyped])
+    AC_EGREP_CPP([ioctlsocket],[
+      $curl_includes_winsock2
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_ioctlsocket="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_ioctlsocket="no"
+    ])
+  fi
+  #
   if test "$tst_proto_ioctlsocket" = "yes"; then
     AC_MSG_CHECKING([if ioctlsocket is compilable])
     AC_COMPILE_IFELSE([
@@ -2623,7 +2793,8 @@ AC_DEFUN([CURL_CHECK_FUNC_IOCTLSOCKET], [
   fi
   #
   AC_MSG_CHECKING([if ioctlsocket might be used])
-  if test "$tst_proto_ioctlsocket" = "yes" &&
+  if test "$tst_links_ioctlsocket" = "yes" &&
+     test "$tst_proto_ioctlsocket" = "yes" &&
      test "$tst_compi_ioctlsocket" = "yes" &&
      test "$tst_allow_ioctlsocket" = "yes"; then
     AC_MSG_RESULT([yes])
@@ -2705,11 +2876,12 @@ dnl then HAVE_IOCTLSOCKET_CAMEL will be defined.
 AC_DEFUN([CURL_CHECK_FUNC_IOCTLSOCKET_CAMEL], [
   AC_REQUIRE([CURL_INCLUDES_BSDSOCKET])dnl
   #
+  tst_links_ioctlsocket_camel="unknown"
   tst_compi_ioctlsocket_camel="unknown"
   tst_allow_ioctlsocket_camel="unknown"
   #
-  AC_MSG_CHECKING([if IoctlSocket is compilable])
-  AC_COMPILE_IFELSE([
+  AC_MSG_CHECKING([if IoctlSocket can be linked])
+  AC_LINK_IFELSE([
     AC_LANG_PROGRAM([[
       $curl_includes_bsdsocket
     ]],[[
@@ -2718,12 +2890,30 @@ AC_DEFUN([CURL_CHECK_FUNC_IOCTLSOCKET_CAMEL], [
     ]])
   ],[
     AC_MSG_RESULT([yes])
-    tst_compi_ioctlsocket_camel="yes"
+    tst_links_ioctlsocket_camel="yes"
   ],[
     AC_MSG_RESULT([no])
-    tst_compi_ioctlsocket_camel="no"
+    tst_links_ioctlsocket_camel="no"
   ])
   #
+  if test "$tst_links_ioctlsocket_camel" = "yes"; then
+    AC_MSG_CHECKING([if IoctlSocket is compilable])
+    AC_COMPILE_IFELSE([
+      AC_LANG_PROGRAM([[
+        $curl_includes_bsdsocket
+      ]],[[
+        if(0 != IoctlSocket(0, 0, 0))
+          return 1;
+      ]])
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_compi_ioctlsocket_camel="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_compi_ioctlsocket_camel="no"
+    ])
+  fi
+  #
   if test "$tst_compi_ioctlsocket_camel" = "yes"; then
     AC_MSG_CHECKING([if IoctlSocket usage allowed])
     if test "x$curl_disallow_ioctlsocket_camel" != "xyes"; then
@@ -2736,7 +2926,8 @@ AC_DEFUN([CURL_CHECK_FUNC_IOCTLSOCKET_CAMEL], [
   fi
   #
   AC_MSG_CHECKING([if IoctlSocket might be used])
-  if test "$tst_compi_ioctlsocket_camel" = "yes" &&
+  if test "$tst_links_ioctlsocket_camel" = "yes" &&
+     test "$tst_compi_ioctlsocket_camel" = "yes" &&
      test "$tst_allow_ioctlsocket_camel" = "yes"; then
     AC_MSG_RESULT([yes])
     AC_DEFINE_UNQUOTED(HAVE_IOCTLSOCKET_CAMEL, 1,
@@ -3285,23 +3476,44 @@ AC_DEFUN([CURL_CHECK_FUNC_SOCKET], [
   AC_REQUIRE([CURL_INCLUDES_WINSOCK2])dnl
   AC_REQUIRE([CURL_INCLUDES_SYS_SOCKET])dnl
   #
+  tst_links_socket="unknown"
   tst_proto_socket="unknown"
   tst_compi_socket="unknown"
   tst_allow_socket="unknown"
   #
-  AC_MSG_CHECKING([if socket is prototyped])
-  AC_EGREP_CPP([socket],[
-    $curl_includes_winsock2
-    $curl_includes_bsdsocket
-    $curl_includes_sys_socket
+  AC_MSG_CHECKING([if socket can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([[
+      $curl_includes_winsock2
+      $curl_includes_bsdsocket
+      $curl_includes_sys_socket
+    ]],[[
+      if(0 != socket(0, 0, 0))
+        return 1;
+    ]])
   ],[
     AC_MSG_RESULT([yes])
-    tst_proto_socket="yes"
+    tst_links_socket="yes"
   ],[
     AC_MSG_RESULT([no])
-    tst_proto_socket="no"
+    tst_links_socket="no"
   ])
   #
+  if test "$tst_links_socket" = "yes"; then
+    AC_MSG_CHECKING([if socket is prototyped])
+    AC_EGREP_CPP([socket],[
+      $curl_includes_winsock2
+      $curl_includes_bsdsocket
+      $curl_includes_sys_socket
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_socket="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_socket="no"
+    ])
+  fi
+  #
   if test "$tst_proto_socket" = "yes"; then
     AC_MSG_CHECKING([if socket is compilable])
     AC_COMPILE_IFELSE([
@@ -3334,7 +3546,8 @@ AC_DEFUN([CURL_CHECK_FUNC_SOCKET], [
   fi
   #
   AC_MSG_CHECKING([if socket might be used])
-  if test "$tst_proto_socket" = "yes" &&
+  if test "$tst_links_socket" = "yes" &&
+     test "$tst_proto_socket" = "yes" &&
      test "$tst_compi_socket" = "yes" &&
      test "$tst_allow_socket" = "yes"; then
     AC_MSG_RESULT([yes])
openSUSE Build Service is sponsored by