From 4c7c38e930805b84789cfb2472776d6939fc23f6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 16 Feb 2005 01:48:11 +0000 Subject: r5411: make network interface selection a bit saner - if we have no configured network interfaces, then don't start nbtd (when I add dynamic interface loading this will change to a delay until a network interface comes up) - choose the best interface by netmask for torture tests that need a specific IP (such as the WINS test). Added iface_best_ip() for that. - if specific interfaces are chosen in smb.conf, then keep that ordering, and default to the first one listed (This used to be commit 4d08c114079ef6d1d10a96195046fe43631aefa2) --- source4/lib/netif/interface.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/netif/interface.c b/source4/lib/netif/interface.c index 2d90df43cf..78f4456cd8 100644 --- a/source4/lib/netif/interface.c +++ b/source4/lib/netif/interface.c @@ -94,7 +94,7 @@ static void add_interface(struct in_addr ip, struct in_addr nmask) iface->nmask = tov4(nmask); iface->bcast.addr = MKBCADDR(iface->ip.addr, iface->nmask.addr); - DLIST_ADD(local_interfaces, iface); + DLIST_ADD_END(local_interfaces, iface, struct interface *); DEBUG(2,("added interface ip=%s ",sys_inet_ntoa(iface->ip))); DEBUG(2,("bcast=%s ",sys_inet_ntoa(iface->bcast))); @@ -339,3 +339,18 @@ const char *iface_n_netmask(int n) return NULL; } +/* + return the local IP address that best matches a destination IP, or + our first interface if none match +*/ +const char *iface_best_ip(const char *dest) +{ + struct interface *iface; + struct in_addr ip; + ip.s_addr = interpret_addr(dest); + iface = iface_find(ip, True); + if (iface) { + return sys_inet_ntoa(iface->ip); + } + return iface_n_ip(0); +} -- cgit