aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-05-30 23:32:09 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-06-01 19:19:25 +0300
commit2db0eabd118370fd2937bd9021ade9b0e40473fa (patch)
tree480e21fbc818471dea52e642e1c8611b5c347e66
parent2a59d367d6ff2be09d5cc952f3ece82517062702 (diff)
downloadlibmicrohttpd-2db0eabd118370fd2937bd9021ade9b0e40473fa.tar.gz
libmicrohttpd-2db0eabd118370fd2937bd9021ade9b0e40473fa.zip
configure: fixed detection of 'getsockname' on some systems (W32 x32),
do not use 'getsockname()' if it is not detected by configure.
-rw-r--r--configure.ac40
-rw-r--r--m4/mhd_check_func.m480
-rw-r--r--src/microhttpd/daemon.c2
3 files changed, 102 insertions, 20 deletions
diff --git a/configure.ac b/configure.ac
index 203b9d30..bcb4e45d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -789,12 +789,25 @@ AC_CHECK_MEMBERS([struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len,
789#endif 789#endif
790 ]) 790 ])
791 791
792AC_CHECK_DECLS([getsockname], 792MHD_CHECK_FUNC([getsockname],
793 [[
794#ifdef HAVE_SYS_TYPES_H
795#include <sys/types.h>
796#endif
797#ifdef HAVE_SYS_SOCKET_H
798#include <sys/socket.h>
799#endif
800#ifdef HAVE_WINSOCK2_H
801#include <winsock2.h>
802#endif
803 ]],
793 [ 804 [
794 AC_CHECK_FUNCS([getsockname], 805 struct sockaddr_storage ss;
795 [ 806 (void)getsockname(socket(0,0,0),(struct sockaddr *)&ss,(void*)0);
796 AC_CACHE_CHECK([[whether getsockname() is usable]], [[mhc_cv_getsockname_usable]], 807 ],
797 [ 808 [
809 AC_CACHE_CHECK([[whether getsockname() is usable]], [[mhc_cv_getsockname_usable]],
810 [
798 AC_RUN_IFELSE( 811 AC_RUN_IFELSE(
799 [ 812 [
800 AC_LANG_SOURCE( 813 AC_LANG_SOURCE(
@@ -888,22 +901,9 @@ int main(void)
888 ) 901 )
889 ] 902 ]
890 ) 903 )
891 AS_VAR_IF([[mhc_cv_getsockname_usable]], [["no"]], [:], 904 AS_VAR_IF([[mhc_cv_getsockname_usable]], [["no"]], [:],
892 [AC_DEFINE([[MHD_USE_GETSOCKNAME]], [[1]], [Define if you have usable `getsockname' function.])]) 905 [AC_DEFINE([[MHD_USE_GETSOCKNAME]], [[1]], [Define if you have usable `getsockname' function.])])
893 ] 906 ]
894 )
895 ], [],
896 [[
897#ifdef HAVE_SYS_TYPES_H
898#include <sys/types.h>
899#endif
900#ifdef HAVE_SYS_SOCKET_H
901#include <sys/socket.h>
902#endif
903#ifdef HAVE_WINSOCK2_H
904#include <winsock2.h>
905#endif
906 ]]
907) 907)
908 908
909# Check for inter-thread signaling type 909# Check for inter-thread signaling type
diff --git a/m4/mhd_check_func.m4 b/m4/mhd_check_func.m4
new file mode 100644
index 00000000..983d0306
--- /dev/null
+++ b/m4/mhd_check_func.m4
@@ -0,0 +1,80 @@
1# SYNOPSIS
2#
3# MHD_CHECK_FUNC([FUNCTION_NAME],
4# [INCLUDES=AC_INCLUDES_DEFAULT], [CHECK_CODE],
5# [ACTION-IF-AVAILABLE], [ACTION-IF-NOT-AVAILABLE],
6# [ADDITIONAL_LIBS])
7#
8# DESCRIPTION
9#
10# This macro checks for presence of specific function by including
11# specified headers and compiling and linking CHECK_CODE.
12# This check both declaration and presence in library.
13# Unlike AC_CHECK_FUNCS macro, this macro do not produce false
14# negative result if function is declared with specific calling
15# conventions like __stdcall' or attribute like
16# __attribute__((__dllimport__)) and linker failed to build test
17# program if library contains function with calling conventions
18# different from declared.
19# By using definition from provided headers, this macro ensures that
20# correct calling convention is used for detection.
21#
22# Example usage:
23#
24# MHD_CHECK_FUNC([memmem],
25# [[#include <string.h>]],
26# [const void *ptr = memmem("aa", 2, "a", 1); (void)ptr;],
27# [var_use_memmem='yes'], [var_use_memmem='no'])
28#
29# Defined cache variable used in check so if any test will not work
30# correctly on some platform, user may simply fix it by giving cache
31# variable in configure parameters, for example:
32#
33# ./configure mhd_cv_func_memmem_have=no
34#
35# This simplify building from source on exotic platforms as patching
36# of configure.ac is not required to change results of tests.
37#
38# LICENSE
39#
40# Copyright (c) 2019 Karlson2k (Evgeny Grin) <k2k@narod.ru>
41#
42# Copying and distribution of this file, with or without modification, are
43# permitted in any medium without royalty provided the copyright notice
44# and this notice are preserved. This file is offered as-is, without any
45# warranty.
46
47#serial 1
48
49AC_DEFUN([MHD_CHECK_FUNC],[dnl
50 AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifblank, m4_ifnblank
51 m4_ifblank(m4_translit([$1],[()],[ ]), [m4_fatal([First macro argument must not be empty])])dnl
52 m4_ifblank([$3], [m4_fatal([Third macro argument must not be empty])])dnl
53 m4_bmatch(m4_normalize([$1]), [\s],dnl
54 [m4_fatal([First macro argument must not contain whitespaces])])dnl
55 m4_if(m4_index([$3], m4_normalize(m4_translit([$1],[()],[ ]))), [-1], dnl
56 [m4_fatal([CHECK_CODE parameter (third macro argument) do not contain ']m4_normalize([$1])[' token])])dnl
57 AS_VAR_PUSHDEF([cv_Var], [mhd_cv_func_]m4_bpatsubst(m4_normalize(m4_translit([$1],[()],[ ])),[[^a-zA-Z0-9]],[_]))dnl
58 dnl
59 AC_CACHE_CHECK([for function $1], [cv_Var],
60 [dnl
61 m4_ifnblank([$6],[dnl
62 mhd_check_func_SAVE_LIBS="$LIBS"
63 LIBS="$LIBS m4_normalize([$6])"
64 ])dnl
65 AC_LINK_IFELSE(
66 [AC_LANG_PROGRAM([m4_default_nblank([$2],[AC_INCLUDES_DEFAULT])], [$3]) ],
67 [AS_VAR_SET([cv_Var],["yes"])], [AS_VAR_SET([cv_Var],["no"])] )
68 m4_ifnblank([$6],[dnl
69 LIBS="${mhd_check_func_SAVE_LIBS}"
70 AS_UNSET([mhd_check_func_SAVE_LIBS])
71 ])dnl
72 ])
73 AS_VAR_IF([cv_Var], ["yes"],
74 [AC_DEFINE([[HAVE_]]m4_bpatsubst(m4_toupper(m4_normalize(m4_translit([$1],[()],[ ]))),[[^A-Z0-9]],[_]),
75 [1], [Define to 1 if you have the `]m4_normalize(m4_translit([$1],[()],[ ]))[' function.])
76 m4_n([$4])dnl
77 ], [$5])
78 AS_VAR_POPDEF([cv_Var])dnl
79])
80
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index fdca4de2..7d186025 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -6092,6 +6092,7 @@ MHD_start_daemon_va (unsigned int flags,
6092 listen_fd = daemon->listen_fd; 6092 listen_fd = daemon->listen_fd;
6093 } 6093 }
6094 6094
6095#ifdef HAVE_GETSOCKNAME
6095 if ( (0 == daemon->port) && 6096 if ( (0 == daemon->port) &&
6096 (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) ) 6097 (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET)) )
6097 { /* Get port number. */ 6098 { /* Get port number. */
@@ -6160,6 +6161,7 @@ MHD_start_daemon_va (unsigned int flags,
6160 } 6161 }
6161 } 6162 }
6162 } 6163 }
6164#endif /* HAVE_GETSOCKNAME */
6163 6165
6164 if ( (MHD_INVALID_SOCKET != listen_fd) && 6166 if ( (MHD_INVALID_SOCKET != listen_fd) &&
6165 (! MHD_socket_nonblocking_ (listen_fd)) ) 6167 (! MHD_socket_nonblocking_ (listen_fd)) )