r8002: favor addresses on our local interfaces in NBT name resolution if
authorAndrew Tridgell <tridge@samba.org>
Thu, 30 Jun 2005 01:26:52 +0000 (01:26 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:18:57 +0000 (13:18 -0500)
possible. This is needed because w2k3 will return bogus IPs in its
name resolution replies when it has an unplugged network interface.
(This used to be commit 2fafc230520fb5bbe9f763de94aaba87b56f5411)

source4/lib/netif/interface.c
source4/libcli/resolve/nbtlist.c

index 80041d53509127495c2a017091fef3586c54f1b7..670913ab6fe33fea1877ff313209521c600ca55e 100644 (file)
@@ -353,3 +353,16 @@ const char *iface_best_ip(const char *dest)
        }
        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;
+}
index d5b01e06d933aabfd869a3b01933ae0311768a26..0026c6fceba4b30cc4a7a3c77f1a282583506371 100644 (file)
@@ -66,8 +66,21 @@ static void nbtlist_handler(struct nbt_name_request *req)
                        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]);
+                       }
                }
        }