Here is a fix to catch incomplete dotted-quad IP addresses that
may lead into more surprises than necessary.
In run into a problem when trying to use CIDR notation with shorthand
130.230/16. Ethereal did not complain, but did not show any matches
either. After some debugging I found out that since inet_aton() was
involved, the address became 0x820000e6. This behavior seems to be a
leftover from the classful days when using an address like "18.5" was
treated as net.host and turned automagically into 18.0.0.5.
Here is a patch for epan/resolv.c:get_host_ipaddr() which catches
incomplete dotted IP addresses.
Index: epan/resolv.c
===================================================================
RCS file: /cvsroot/ethereal/epan/resolv.c,v
retrieving revision 1.22
diff -u -p -r1.22 resolv.c
--- resolv.c 2002/03/02 20:48:10 1.22
+++ resolv.c 2002/03/03 21:23:52
@@ -1396,6 +1396,15 @@ gboolean get_host_ipaddr(const char *hos
} else {
return FALSE;
}
+ } else {
+ /* Does the string really contain dotted-quad IP?
+ * Check against inet_atons that accept strings such as
+ * "130.230" as valid addresses and try to convert them
+ * to some form of a classful (host.net) notation.
+ */
+ unsigned int a0, a1, a2, a3;
+ if (sscanf(host, "%d.%d.%d.%d", &a0, &a1, &a2, &a3) != 4)
+ return FALSE;
}
*addrp = ntohl(ipaddr.s_addr);
--
Heikki Vatiainen * hessu@xxxxxxxxx
Tampere University of Technology * Tampere, Finland