From 97050349949763dba212711ba2178e652e1b8780 Mon Sep 17 00:00:00 2001 From: Shane Kerr Date: Tue, 14 Aug 2007 14:08:16 +0000 Subject: [PATCH] Fix for interface detection when no IPv4 addresses available. See RT ticket #17086 for more. --- RELNOTES | 3 +++ common/discover.c | 26 +++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/RELNOTES b/RELNOTES index 650224676..3e88863e7 100644 --- a/RELNOTES +++ b/RELNOTES @@ -53,6 +53,9 @@ suggested fixes to . Changes since 4.0.0a2 +- Fix for startup where there are no IPv4 addresses on an interface. + Thanks to Marcus Goller for reporting the bug. + - Fixed file descriptor leak on listen failure. Thanks to Tom Clark. - Bug in server configuration parser caused server to get stuck on diff --git a/common/discover.c b/common/discover.c index 362280bb3..c2488dc7b 100644 --- a/common/discover.c +++ b/common/discover.c @@ -233,7 +233,7 @@ begin_iface_scan(struct iface_conf_list *ifaces) { int lifnum; #endif - ifaces->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + ifaces->sock = socket(local_family, SOCK_DGRAM, IPPROTO_UDP); if (ifaces->sock < 0) { log_error("Error creating socket to list interfaces; %m"); return 0; @@ -1152,12 +1152,24 @@ discover_interfaces(int state) { ? tmp -> shared_network -> subnets : (struct subnet *)0); subnet; subnet = subnet -> next_sibling) { - if (!subnet -> interface_address.len) { - /* Set the interface address for this subnet - to the first address we found. */ - subnet -> interface_address.len = 4; - memcpy (subnet -> interface_address.iabuf, - &tmp->addresses[0].s_addr, 4); + /* Set the interface address for this subnet + to the first address we found. */ + if (subnet->interface_address.len == 0) { + if (tmp->address_count > 0) { + subnet->interface_address.len = 4; + memcpy(subnet->interface_address.iabuf, + &tmp->addresses[0].s_addr, 4); + } else if (tmp->v6address_count > 0) { + subnet->interface_address.len = 16; + memcpy(subnet->interface_address.iabuf, + &tmp->v6addresses[0].s6_addr, + 16); + } else { + /* XXX: should be one */ + log_error("%s missing an interface " + "address", tmp->name); + continue; + } } } -- 2.39.2