From 451082eb1b2f8fc5cbacbb65cd4e48348192b477 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 15 Mar 2011 17:01:29 +0100 Subject: [PATCH] Add ./configure --disable-ipv6 to use IPv4 only. For networks stacks which don't support any IPv6. --- configure.ac | 7 +++++++ src/tlsproxy.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/configure.ac b/configure.ac index 4a3786a..1717a3a 100644 --- a/configure.ac +++ b/configure.ac @@ -24,6 +24,13 @@ AC_ARG_ENABLE([debug], AC_DEFINE([DEBUG], 1, [Define to enable debug output.]) fi]) +AC_ARG_ENABLE([ipv6], + [AC_HELP_STRING([--disable-ipv6], + [disable IPv6, for IPv4 only network stacks])], + [if test "x$enableval" = xno; then + AC_DEFINE([USE_IPV4_ONLY], 1, [Define to not use IPv6.]) + fi]) + AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile]) AC_OUTPUT diff --git a/src/tlsproxy.c b/src/tlsproxy.c index 5fed554..a54a6e9 100644 --- a/src/tlsproxy.c +++ b/src/tlsproxy.c @@ -89,7 +89,11 @@ static void worker_thread(void); int main(int argc, char **argv) { int port; int client_socket, server_socket; +#ifdef USE_IPV4_ONLY + struct sockaddr_in server_in; +#else struct sockaddr_in6 server_in; +#endif size_t i; pthread_t *threads; @@ -154,7 +158,11 @@ int main(int argc, char **argv) { threads[i] = thread; } +#ifdef USE_IPV4_ONLY + server_socket = socket(PF_INET, SOCK_STREAM, 0); +#else server_socket = socket(PF_INET6, SOCK_STREAM, 0); +#endif if (-1 == server_socket) { perror("socket()"); return EXIT_FAILURE; @@ -171,9 +179,15 @@ int main(int argc, char **argv) { /* Bind to the listen socket. */ memset(&server_in, 0, sizeof(server_in)); +#ifdef USE_IPV4_ONLY + server_in.sin_family = AF_INET; /* IPv4 only */ + server_in.sin_addr.s_addr = INADDR_ANY; /* bind to any address */ + server_in.sin_port = htons((uint16_t)port); /* port to bind to */ +#else server_in.sin6_family = AF_INET6; /* IPv6 (and IPv4) */ server_in.sin6_addr = in6addr_any; /* bind to any address */ server_in.sin6_port = htons((uint16_t)port); /* port to bind to */ +#endif if (-1 == bind(server_socket, (struct sockaddr *)&server_in, sizeof(server_in))) { perror("bind()"); -- 2.45.2