summaryrefslogtreecommitdiffstats
path: root/contrib/libpcap/nametoaddr.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libpcap/nametoaddr.c')
-rw-r--r--contrib/libpcap/nametoaddr.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/contrib/libpcap/nametoaddr.c b/contrib/libpcap/nametoaddr.c
index ac56539..a795e49 100644
--- a/contrib/libpcap/nametoaddr.c
+++ b/contrib/libpcap/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.77.2.3 2005/04/20 11:13:51 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -74,7 +74,7 @@ struct rtentry; /* declarations in <net/if.h> */
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
-#include <memory.h>
+#include <string.h>
#include <stdio.h>
#include "pcap-int.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)
{
@@ -413,6 +458,11 @@ pcap_ether_hostton(const char *name)
#else
#if !defined(HAVE_DECL_ETHER_HOSTTON) || !HAVE_DECL_ETHER_HOSTTON
+#ifndef HAVE_STRUCT_ETHER_ADDR
+struct ether_addr {
+ unsigned char ether_addr_octet[6];
+};
+#endif
extern int ether_hostton(const char *, struct ether_addr *);
#endif
OpenPOWER on IntegriCloud