svn commit: samba r8002 - in branches/SAMBA_4_0/source: lib/netif libcli/resolve

tridge at samba.org tridge at samba.org
Thu Jun 30 01:26:53 GMT 2005


Author: tridge
Date: 2005-06-30 01:26:52 +0000 (Thu, 30 Jun 2005)
New Revision: 8002

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=8002

Log:
favor addresses on our local interfaces in NBT name resolution if
possible. This is needed because w2k3 will return bogus IPs in its
name resolution replies when it has an unplugged network interface.

Modified:
   branches/SAMBA_4_0/source/lib/netif/interface.c
   branches/SAMBA_4_0/source/libcli/resolve/nbtlist.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/netif/interface.c
===================================================================
--- branches/SAMBA_4_0/source/lib/netif/interface.c	2005-06-30 01:04:51 UTC (rev 8001)
+++ branches/SAMBA_4_0/source/lib/netif/interface.c	2005-06-30 01:26:52 UTC (rev 8002)
@@ -353,3 +353,16 @@
 	}
 	return iface_n_ip(0);
 }
+
+/*
+  return True if an IP is one one of our local networks
+*/
+BOOL iface_is_local(const char *dest)
+{
+	struct in_addr ip;
+	ip.s_addr = interpret_addr(dest);
+	if (iface_find(ip, True)) {
+		return True;
+	}
+	return False;
+}

Modified: branches/SAMBA_4_0/source/libcli/resolve/nbtlist.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/resolve/nbtlist.c	2005-06-30 01:04:51 UTC (rev 8001)
+++ branches/SAMBA_4_0/source/libcli/resolve/nbtlist.c	2005-06-30 01:26:52 UTC (rev 8002)
@@ -66,8 +66,21 @@
 			c->state = SMBCLI_REQUEST_ERROR;
 			c->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
 		} else {
+			struct nbt_name_query *q = &state->io_queries[i];
 			c->state = SMBCLI_REQUEST_DONE;
-			state->reply_addr = talloc_steal(state, state->io_queries[i].out.reply_addrs[0]);
+			/* favor a local address if possible */
+			state->reply_addr = NULL;
+			for (i=0;i<q->out.num_addrs;i++) {
+				if (iface_is_local(q->out.reply_addrs[i])) {
+					state->reply_addr = talloc_steal(state, 
+									 q->out.reply_addrs[i]);
+					break;
+				}
+			}
+			if (state->reply_addr == NULL) {
+				state->reply_addr = talloc_steal(state, 
+								 q->out.reply_addrs[0]);
+			}
 		}
 	}
 



More information about the samba-cvs mailing list