Browse Source

Use struct sockaddr_storage (in liSockAddr) as base for getsockname/getpeername

personal/stbuehler/wip
Stefan Bühler 12 years ago
parent
commit
faf2985a79
  1. 10
      configure.ac
  2. 4
      include/lighttpd/sys-socket.h
  3. 7
      src/CMakeLists.txt
  4. 12
      src/common/utils.c
  5. 1
      src/config.h.cmake
  6. 9
      wscript

10
configure.ac

@ -160,6 +160,16 @@ if test x$ipv6 = xtrue; then
fi
fi
dnl Check for struct sockaddr_storage
AC_CACHE_CHECK([for struct sockaddr_storage support], ac_cv_sockaddr_storage_support,
[AC_TRY_LINK([ #include <sys/socket.h> ], [struct sockaddr_storage s; ],
[ac_cv_sockaddr_storage_support=yes], [ac_cv_sockaddr_storage_support=no])])
if test "ac_cv_sockaddr_storage_support" = yes; then
AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[Whether we have struct sockaddr_storage])
fi
dnl Check for openssl
AC_MSG_CHECKING(for OpenSSL)

4
include/lighttpd/sys-socket.h

@ -76,6 +76,10 @@ union liSockAddr {
struct sockaddr_un un;
#endif
struct sockaddr plain;
#ifdef HAVE_SOCKADDR_STORAGE
struct sockaddr_storage storage;
#endif
};
typedef struct liSocketAddress liSocketAddress;

7
src/CMakeLists.txt

@ -80,6 +80,13 @@ CHECK_C_SOURCE_COMPILES("
struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
return 0;
}" HAVE_IPV6)
CHECK_C_SOURCE_COMPILES("
#include <sys/socket.h>
int main() {
struct sockaddr_storage s;
return 0;
}" HAVE_SOCKADDR_STORAGE)
# glib/gthread
pkg_check_modules(GTHREAD REQUIRED gthread-2.0)

12
src/common/utils.c

@ -641,11 +641,11 @@ liSocketAddress li_sockaddr_from_string(const GString *str, guint tcp_default_po
}
liSocketAddress li_sockaddr_local_from_socket(gint fd) {
socklen_t l = 0;
static struct sockaddr sa;
static liSockAddr sa;
socklen_t l = sizeof(sa);
liSocketAddress saddr = { 0, NULL };
if (-1 == getsockname(fd, &sa, &l)) {
if (-1 == getsockname(fd, &sa.plain, &l)) {
return saddr;
}
@ -657,11 +657,11 @@ liSocketAddress li_sockaddr_local_from_socket(gint fd) {
}
liSocketAddress li_sockaddr_remote_from_socket(gint fd) {
socklen_t l = 0;
static struct sockaddr sa;
static liSockAddr sa;
socklen_t l = sizeof(sa);
liSocketAddress saddr = { 0, NULL };
if (-1 == getpeername(fd, &sa, &l)) {
if (-1 == getpeername(fd, &sa.plain, &l)) {
return saddr;
}

1
src/config.h.cmake

@ -29,6 +29,7 @@
#cmakedefine HAVE_PTHREAD_H
#cmakedefine HAVE_INET_ATON
#cmakedefine HAVE_IPV6
#cmakedefine HAVE_SOCKADDR_STORAGE
/* XATTR */
#cmakedefine HAVE_ATTR_ATTRIBUTES_H

9
wscript

@ -183,6 +183,15 @@ def configure(conf):
define_name='HAVE_IPV6'
)
conf.check(
fragment='''
#include <sys/socket.h>
int main() {struct sockaddr_storage s; return 0;}
''',
msg='Checking for struct sockaddr_storage support',
define_name='HAVE_SOCKADDR_STORAGE'
)
conf.sub_config('src/common')
conf.sub_config('src/angel')
conf.sub_config('src/main')

Loading…
Cancel
Save