| 1 |
Description: Patch which allows ffproxy to be bound on the same port for ipv4 and ipv6 |
| 2 |
Author: Emmanuel Bouthenot <[email protected]> |
| 3 |
Bug-Debian: http://bugs.debian.org/453510 |
| 4 |
Last-Update: 2007-11-30 |
| 5 |
--- a/socket.c |
| 6 |
+++ b/socket.c |
| 7 |
@@ -71,6 +71,13 @@ |
| 8 |
int num_fd; |
| 9 |
int isipv4; |
| 10 |
|
| 11 |
+ if (config.bind_ipv4 && config.bind_ipv6) { |
| 12 |
+ if (*config.ipv4 == '\0' && *config.ipv6 != '\0') |
| 13 |
+ fatal("error: while binding port on ipv4 and ipv6, if option 'bind_ipv4_host' is set, bind_ipv6_host must be set too"); |
| 14 |
+ if (*config.ipv4 != '\0' && *config.ipv6 == '\0') |
| 15 |
+ fatal("error: while binding port on ipv4 and ipv6, if option 'bind_ipv6_host' is set, bind_ipv4_host must be set too"); |
| 16 |
+ } |
| 17 |
+ |
| 18 |
if (config.port == 0) |
| 19 |
config.port = DFLT_PORT; |
| 20 |
(void) snprintf(strport, sizeof(strport), "%d", config.port); |
| 21 |
@@ -80,13 +87,25 @@ |
| 22 |
num_fd++; |
| 23 |
if (config.bind_ipv6) |
| 24 |
num_fd++; |
| 25 |
- |
| 26 |
+ |
| 27 |
+ if (config.bind_ipv4 && config.bind_ipv6 |
| 28 |
+ && *config.ipv4 == '\0' && *config.ipv6 == '\0') |
| 29 |
+ num_fd--; |
| 30 |
+ |
| 31 |
i = 0; |
| 32 |
(void) memset(s, 0, sizeof(s)); |
| 33 |
s[0].fd = s[1].fd = 0; |
| 34 |
while (i < num_fd) { |
| 35 |
(void) memset(&hints[i], 0, sizeof(struct addrinfo)); |
| 36 |
- hints[i].ai_family = (i == 0 && config.bind_ipv4) ? PF_INET : PF_INET6; |
| 37 |
+ |
| 38 |
+ if (config.bind_ipv4 && config.bind_ipv6 |
| 39 |
+ && *config.ipv4 == '\0' && *config.ipv6 == '\0') |
| 40 |
+ hints[i].ai_family = PF_UNSPEC; |
| 41 |
+ else if (i == 0 && config.bind_ipv4) |
| 42 |
+ hints[i].ai_family = PF_INET; |
| 43 |
+ else |
| 44 |
+ hints[i].ai_family = PF_INET6; |
| 45 |
+ |
| 46 |
hints[i].ai_socktype = SOCK_STREAM; |
| 47 |
hints[i].ai_flags = AI_PASSIVE; |
| 48 |
if (i == 0 && config.bind_ipv4) { |
| 49 |
@@ -113,12 +132,8 @@ |
| 50 |
fatal("setsockopt() failed for (%s) %s", ip_add, (i == 0 && config.bind_ipv4) ? "IPv4" : "IPv6"); |
| 51 |
} |
| 52 |
if (bind(s[i].fd, (struct sockaddr *) res->ai_addr, res->ai_addrlen) < 0) { |
| 53 |
- (void) close(s[i].fd); |
| 54 |
-#if defined(__linux__) |
| 55 |
- if (i == 1) |
| 56 |
- fatal("could not bind to IPv6, possibly because of\nLinux's ``feature'' to bind to IPv4 also.\nTry -b or binding to specific IPv6 address via -C\nif you're using IPv6 with Linux 2.4\nError message"); |
| 57 |
-#endif /* __linux__ */ |
| 58 |
- fatal("bind() failed for (%s) %s", ip_add, (i == 0 && config.bind_ipv4) ? "IPv4" : "IPv6"); |
| 59 |
+ (void) close(s[i].fd); |
| 60 |
+ fatal("bind() failed for (%s) %s", ip_add, (i == 0 && config.bind_ipv4) ? "IPv4" : "IPv6"); |
| 61 |
} |
| 62 |
if (listen(s[i].fd, config.backlog) != 0) { |
| 63 |
(void) close(s[i].fd); |