aboutsummaryrefslogtreecommitdiffstats
path: root/nametoaddr.c
diff options
context:
space:
mode:
authorguy <guy>2005-04-19 04:25:00 +0000
committerguy <guy>2005-04-19 04:25:00 +0000
commit97a8e5112d9f004bec63db30c42e16a96e0aab0b (patch)
tree41dfe802a98622ba4db42735acbaa06b37310a3a /nametoaddr.c
parentb423e170246706185004faa75aab6cbe68000280 (diff)
From Patrick Marie <mycroft@virgaria.org>: add support for port ranges
in tests - "portrange X-Y" matches all ports in the range [X,Y]. Support added for port ranges with IPv6. Fix some comments.
Diffstat (limited to 'nametoaddr.c')
-rw-r--r--nametoaddr.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/nametoaddr.c b/nametoaddr.c
index 8f033b4..c6e74a0 100644
--- a/nametoaddr.c
+++ b/nametoaddr.c
@@ -24,7 +24,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.77 2005-03-27 22:26:25 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/nametoaddr.c,v 1.78 2005-04-19 04:25:01 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -216,6 +216,51 @@ pcap_nametoport(const char *name, int *port, int *proto)
return 0;
}
+/*
+ * Convert a string in the form PPP-PPP, where correspond to ports, to
+ * a starting and ending port in a port range.
+ * Return 0 on failure.
+ */
+int
+pcap_nametoportrange(const char *name, int *port1, int *port2, int *proto)
+{
+ u_int p1, p2;
+ char *off, *cpy;
+ int save_proto;
+
+ if (sscanf(name, "%d-%d", &p1, &p2) != 2) {
+ if ((cpy = strdup(name)) == NULL)
+ return 0;
+
+ if ((off = strchr(cpy, '-')) == NULL) {
+ free(cpy);
+ return 0;
+ }
+
+ *off = '\0';
+
+ if (pcap_nametoport(cpy, port1, proto) == 0) {
+ free(cpy);
+ return 0;
+ }
+ save_proto = *proto;
+
+ if (pcap_nametoport(off + 1, port2, proto) == 0) {
+ free(cpy);
+ return 0;
+ }
+
+ if (*proto != save_proto)
+ *proto = PROTO_UNDEF;
+ } else {
+ *port1 = p1;
+ *port2 = p2;
+ *proto = PROTO_UNDEF;
+ }
+
+ return 1;
+}
+
int
pcap_nametoproto(const char *str)
{