Move entries in libdnet-stripped/NMAP_MODIFICATIONS to reflect recent

upstream merges by Jay Fink.

http://code.google.com/p/libdnet/source/detail?r=654
http://code.google.com/p/libdnet/source/detail?r=655
http://code.google.com/p/libdnet/source/detail?r=656
This commit is contained in:
david 2010-02-24 01:54:56 +00:00
parent bf612ba7c9
commit 2099944ef0

View file

@ -35,157 +35,6 @@ o Added a check for socklen_t in configure.in and used socklen_t when
calling getsockname and getsockopt to avoid a "pointer targets differ
in signedness" warning on platforms where socklen_t is unsigned.
o Made some code changes to intf.c (the patch below). This does the following:
o Preserve the alias qualifier from interface name in more cases
(e.g. don't blow away :2 from eth0:2 when it may still be needed.
o Set the SO_BROADCAST flag on the interface list descriptor so that
broadcast/network IPs can be investigated.
o Update _match_intf_src so that it checks interface aliases for the
given source address rather than only the main interface address.
diff -Nruw old/src/intf.c nmap-3.83.new/src/intf.c
--- src/intf.c 2005-05-03 09:41:35.000000000 -0700
+++ src/intf.c 2005-07-16 20:55:05.000000000 -0700
@@ -119,12 +119,16 @@
intf_open(void)
{
intf_t *intf;
+ int one = 1;
if ((intf = calloc(1, sizeof(*intf))) != NULL) {
intf->fd = intf->fd6 = -1;
if ((intf->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return (intf_close(intf));
+
+ setsockopt(intf->fd, SOL_SOCKET, SO_BROADCAST,
+ (const char *) &one, sizeof(one));
#ifdef SIOCGIFNETMASK_IN6
if ((intf->fd6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
# ifdef EPROTONOSUPPORT
@@ -472,6 +476,7 @@
_intf_get_aliases(intf_t *intf, struct intf_entry *entry)
{
struct ifreq *ifr, *lifr;
+ struct ifreq tmpifr;
struct addr *ap, *lap;
char *p;
@@ -492,9 +497,12 @@
if ((p = strchr(ifr->ifr_name, ':')) != NULL)
*p = '\0';
- if (strcmp(ifr->ifr_name, entry->intf_name) != 0)
+ if (strcmp(ifr->ifr_name, entry->intf_name) != 0) {
+ if (p) *p = ':';
continue;
+ }
+ if (p) *p = ':'; /* Fix the name back up */
if (addr_ston(&ifr->ifr_addr, ap) < 0)
continue;
@@ -506,6 +514,11 @@
if (ap->addr_ip == entry->intf_addr.addr_ip ||
ap->addr_ip == entry->intf_dst_addr.addr_ip)
continue;
+ strlcpy(tmpifr.ifr_name, ifr->ifr_name,
+ sizeof(tmpifr.ifr_name));
+ if (ioctl(intf->fd, SIOCGIFNETMASK, &tmpifr) == 0)
+ addr_stob(&tmpifr.ifr_addr, &ap->addr_bits);
+
}
#ifdef SIOCGIFNETMASK_IN6
else if (ap->addr_type == ADDR_TYPE_IP6 && intf->fd6 != -1) {
@@ -547,10 +560,22 @@
static int
_match_intf_src(const struct intf_entry *entry, void *arg)
{
+ int matched = 0;
+ int cnt;
struct intf_entry *save = (struct intf_entry *)arg;
if (entry->intf_addr.addr_type == ADDR_TYPE_IP &&
- entry->intf_addr.addr_ip == save->intf_addr.addr_ip) {
+ entry->intf_addr.addr_ip == save->intf_addr.addr_ip)
+ matched = 1;
+
+ for (cnt = 0; !matched && cnt < (int) entry->intf_alias_num; cnt++) {
+ if (entry->intf_alias_addrs[cnt].addr_type != ADDR_TYPE_IP)
+ continue;
+ if (entry->intf_alias_addrs[cnt].addr_ip == save->intf_addr.addr_ip)
+ matched = 1;
+ }
+
+ if (matched) {
/* XXX - truncated result if entry is too small. */
if (save->intf_len < entry->intf_len)
memcpy(save, entry, save->intf_len);
@@ -678,14 +703,18 @@
if ((p = strchr(ifr->ifr_name, ':')) != NULL)
*p = '\0';
- if (pifr != NULL && strcmp(ifr->ifr_name, pifr->ifr_name) == 0)
+ if (pifr != NULL && strcmp(ifr->ifr_name, pifr->ifr_name) == 0) {
+ if (p) *p = ':';
continue;
+ }
memset(ebuf, 0, sizeof(ebuf));
strlcpy(entry->intf_name, ifr->ifr_name,
sizeof(entry->intf_name));
entry->intf_len = sizeof(ebuf);
+ /* Repair the alias name back up. */
+ if (p) *p = ':';
if (_intf_get_noalias(intf, entry) < 0)
return (-1);
if (_intf_get_aliases(intf, entry) < 0)
o Made some AIX/HP-UX portability changes sent in by Peter O'Gorman
(nmap-dev@mlists.thewrittenword.com), part 2:
Index: src/arp-ioctl.c
===================================================================
--- src/arp-ioctl.c (revision 3309)
+++ src/arp-ioctl.c (working copy)
@@ -383,7 +383,7 @@
}
return (ret);
}
-#elif defined(HAVE_NET_RADIX_H)
+#elif defined(HAVE_NET_RADIX_H) && !defined(_AIX)
/* XXX - Tru64, others? */
#include <netinet/if_ether.h>
#include <nlist.h>
Index: src/intf.c
===================================================================
--- src/intf.c (revision 3309)
+++ src/intf.c (working copy)
@@ -284,7 +284,9 @@
/* Set interface MTU. */
if (entry->intf_mtu != 0) {
ifr.ifr_mtu = entry->intf_mtu;
+#ifdef SIOCSIFMTU
if (ioctl(intf->fd, SIOCSIFMTU, &ifr) < 0)
+#endif
return (-1);
}
/* Set interface address. */
@@ -396,7 +398,9 @@
_intf_set_type(entry);
/* Get interface MTU. */
+#ifdef SIOCGIFMTU
if (ioctl(intf->fd, SIOCGIFMTU, &ifr) < 0)
+#endif
return (-1);
entry->intf_mtu = ifr.ifr_mtu;
o Made the following change for Windows Vista support (thanks to Dan
Griffin):
--- old/intf-win32.c 2005-12-28 16:30:38.000000000 -0800
@ -200,21 +49,6 @@ Griffin):
struct intf_handle {
struct ifcombo ifcombo[MIB_IF_TYPE_MAX];
o Fix a compiler "may be used unitialized" warning:
Index: addr-util.c
===================================================================
--- addr-util.c (revision 3855)
+++ addr-util.c (working copy)
@@ -177,6 +177,8 @@
struct { int base, len; } best, cur;
char *p = dst;
int i;
+
+ cur.len = best.len = 0;
if (len < 46)
return (NULL);
o Removed config.sub, config.guess, install-sh, ltmain.sh, and missing from the
config directory. These files are found in the parent (i.e., Nmap's)
directory. Also removed config/mkinstalldirs because it is replaced with
@ -380,11 +214,142 @@ Index: libdnet-stripped/src/intf-win32.c
} else
return (-1);
===CHANGES ALREADY MERGED TO UPSTREAM LIBDNET GO BELOW THIS LINE===
o Made some code changes to intf.c (the patch below). This does the following:
o Preserve the alias qualifier from interface name in more cases
(e.g. don't blow away :2 from eth0:2 when it may still be needed.
o Set the SO_BROADCAST flag on the interface list descriptor so that
broadcast/network IPs can be investigated.
o Update _match_intf_src so that it checks interface aliases for the
given source address rather than only the main interface address.
o merged upstream libdnet r655
diff -Nruw old/src/intf.c nmap-3.83.new/src/intf.c
--- src/intf.c 2005-05-03 09:41:35.000000000 -0700
+++ src/intf.c 2005-07-16 20:55:05.000000000 -0700
@@ -119,12 +119,16 @@
intf_open(void)
{
intf_t *intf;
+ int one = 1;
if ((intf = calloc(1, sizeof(*intf))) != NULL) {
intf->fd = intf->fd6 = -1;
if ((intf->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return (intf_close(intf));
+
+ setsockopt(intf->fd, SOL_SOCKET, SO_BROADCAST,
+ (const char *) &one, sizeof(one));
#ifdef SIOCGIFNETMASK_IN6
if ((intf->fd6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
# ifdef EPROTONOSUPPORT
@@ -472,6 +476,7 @@
_intf_get_aliases(intf_t *intf, struct intf_entry *entry)
{
struct ifreq *ifr, *lifr;
+ struct ifreq tmpifr;
struct addr *ap, *lap;
char *p;
@@ -492,9 +497,12 @@
if ((p = strchr(ifr->ifr_name, ':')) != NULL)
*p = '\0';
- if (strcmp(ifr->ifr_name, entry->intf_name) != 0)
+ if (strcmp(ifr->ifr_name, entry->intf_name) != 0) {
+ if (p) *p = ':';
continue;
+ }
+ if (p) *p = ':'; /* Fix the name back up */
if (addr_ston(&ifr->ifr_addr, ap) < 0)
continue;
@@ -506,6 +514,11 @@
if (ap->addr_ip == entry->intf_addr.addr_ip ||
ap->addr_ip == entry->intf_dst_addr.addr_ip)
continue;
+ strlcpy(tmpifr.ifr_name, ifr->ifr_name,
+ sizeof(tmpifr.ifr_name));
+ if (ioctl(intf->fd, SIOCGIFNETMASK, &tmpifr) == 0)
+ addr_stob(&tmpifr.ifr_addr, &ap->addr_bits);
+
}
#ifdef SIOCGIFNETMASK_IN6
else if (ap->addr_type == ADDR_TYPE_IP6 && intf->fd6 != -1) {
@@ -547,10 +560,22 @@
static int
_match_intf_src(const struct intf_entry *entry, void *arg)
{
+ int matched = 0;
+ int cnt;
struct intf_entry *save = (struct intf_entry *)arg;
if (entry->intf_addr.addr_type == ADDR_TYPE_IP &&
- entry->intf_addr.addr_ip == save->intf_addr.addr_ip) {
+ entry->intf_addr.addr_ip == save->intf_addr.addr_ip)
+ matched = 1;
+
+ for (cnt = 0; !matched && cnt < (int) entry->intf_alias_num; cnt++) {
+ if (entry->intf_alias_addrs[cnt].addr_type != ADDR_TYPE_IP)
+ continue;
+ if (entry->intf_alias_addrs[cnt].addr_ip == save->intf_addr.addr_ip)
+ matched = 1;
+ }
+
+ if (matched) {
/* XXX - truncated result if entry is too small. */
if (save->intf_len < entry->intf_len)
memcpy(save, entry, save->intf_len);
@@ -678,14 +703,18 @@
if ((p = strchr(ifr->ifr_name, ':')) != NULL)
*p = '\0';
- if (pifr != NULL && strcmp(ifr->ifr_name, pifr->ifr_name) == 0)
+ if (pifr != NULL && strcmp(ifr->ifr_name, pifr->ifr_name) == 0) {
+ if (p) *p = ':';
continue;
+ }
memset(ebuf, 0, sizeof(ebuf));
strlcpy(entry->intf_name, ifr->ifr_name,
sizeof(entry->intf_name));
entry->intf_len = sizeof(ebuf);
+ /* Repair the alias name back up. */
+ if (p) *p = ':';
if (_intf_get_noalias(intf, entry) < 0)
return (-1);
if (_intf_get_aliases(intf, entry) < 0)
o Fix a compiler "may be used unitialized" warning:
o Merged upstream r654
Index: addr-util.c
===================================================================
--- addr-util.c (revision 3855)
+++ addr-util.c (working copy)
@@ -177,6 +177,8 @@
struct { int base, len; } best, cur;
char *p = dst;
int i;
+
+ cur.len = best.len = 0;
if (len < 46)
return (NULL);
o Added eth_get_pcap_devname() that matches up a dnet name to its pcap
equivalent by matching hardwar addresses. It's similar to the code
used in eth_open()
o Handle the case of sa_len == 0 (meaning 0.0.0.0) in addr_stob.
o Merged upstream to libdnet r654
Index: src/addr.c
===================================================================
--- src/addr.c (revision 12591)
@ -430,6 +395,7 @@ Index: src/intf.c
while (fgets(buf, sizeof(buf), fp) != NULL) {
o Added casts to calls of ctype functions so that their arguments are explicitly
o Merged upstream libdnet r656
cast to (int) [Josh Marlow]
Index: src/blob.c
===================================================================
@ -458,8 +424,45 @@ Index: src/intf-win32.c
return (intf->ifcombo[type].idx[n]);
o Made some AIX/HP-UX portability changes sent in by Peter O'Gorman
(nmap-dev@mlists.thewrittenword.com), part 2:
Index: src/arp-ioctl.c
===================================================================
--- src/arp-ioctl.c (revision 3309)
+++ src/arp-ioctl.c (working copy)
@@ -383,7 +383,7 @@
}
return (ret);
}
-#elif defined(HAVE_NET_RADIX_H)
+#elif defined(HAVE_NET_RADIX_H) && !defined(_AIX)
/* XXX - Tru64, others? */
#include <netinet/if_ether.h>
#include <nlist.h>
Index: src/intf.c
===================================================================
--- src/intf.c (revision 3309)
+++ src/intf.c (working copy)
@@ -284,7 +284,9 @@
/* Set interface MTU. */
if (entry->intf_mtu != 0) {
ifr.ifr_mtu = entry->intf_mtu;
+#ifdef SIOCSIFMTU
if (ioctl(intf->fd, SIOCSIFMTU, &ifr) < 0)
+#endif
return (-1);
}
/* Set interface address. */
@@ -396,7 +398,9 @@
_intf_set_type(entry);
/* Get interface MTU. */
+#ifdef SIOCGIFMTU
if (ioctl(intf->fd, SIOCGIFMTU, &ifr) < 0)
+#endif
return (-1);
entry->intf_mtu = ifr.ifr_mtu;
===CHANGES ALREADY MERGED TO UPSTREAM LIBDNET GO BELOW THIS LINE===
o Made some AIX/HP-UX portability changes sent in by Peter O'Gorman
(nmap-dev@mlists.thewrittenword.com), part 1.