Date: Mon, 11 Mar 2002 11:50:09 -0800 (PST) From: Alan Bawden <Alan@LCS.MIT.EDU> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/34843: `tcpdump port echo' filters for port 4 instead of 7 Message-ID: <200203111950.g2BJo9n86017@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/34843; it has been noted by GNATS.
From: Alan Bawden <Alan@LCS.MIT.EDU>
To: freebsd-gnats-submit@FreeBSD.org
Cc:
Subject: Re: bin/34843: `tcpdump port echo' filters for port 4 instead of 7
Date: Mon, 11 Mar 2002 14:43:59 -0500 (EST)
Here's a patch that fixes the problem. (Assuming you think other protocols
(e.g. "ddp") are entitled to call their own services by their own names in
/etc/services.) This does change the command line behavior of the tcpdump
command, but only to the extent of improving its error checking.
I've tested this on a FreeBSD 4.3 machine, but it looks like it should work
fine in all subsequent releases.
--- contrib/libpcap/nametoaddr.c.orig Wed Jul 19 12:07:37 2000
+++ contrib/libpcap/nametoaddr.c Mon Mar 11 13:58:14 2002
@@ -142,36 +142,38 @@
pcap_nametoport(const char *name, int *port, int *proto)
{
struct servent *sp;
- char *other;
+ int tcp_port = -1;
+ int udp_port = -1;
- sp = getservbyname(name, (char *)0);
- if (sp != NULL) {
- NTOHS(sp->s_port);
- *port = sp->s_port;
- *proto = pcap_nametoproto(sp->s_proto);
- /*
- * We need to check /etc/services for ambiguous entries.
- * If we find the ambiguous entry, and it has the
- * same port number, change the proto to PROTO_UNDEF
- * so both TCP and UDP will be checked.
- */
- if (*proto == IPPROTO_TCP)
- other = "udp";
- else
- other = "tcp";
-
- sp = getservbyname(name, other);
- if (sp != 0) {
- NTOHS(sp->s_port);
+ /*
+ * We need to check /etc/services for ambiguous entries.
+ * If we find the ambiguous entry, and it has the
+ * same port number, change the proto to PROTO_UNDEF
+ * so both TCP and UDP will be checked.
+ */
+ sp = getservbyname(name, "tcp");
+ if (sp != NULL) tcp_port = ntohs(sp->s_port);
+ sp = getservbyname(name, "udp");
+ if (sp != NULL) udp_port = ntohs(sp->s_port);
+ if (tcp_port >= 0) {
+ *port = tcp_port;
+ *proto = IPPROTO_TCP;
+ if (udp_port >= 0) {
+ if (udp_port == tcp_port)
+ *proto = PROTO_UNDEF;
#ifdef notdef
- if (*port != sp->s_port)
+ else
/* Can't handle ambiguous names that refer
to different port numbers. */
warning("ambiguous port %s in /etc/services",
name);
#endif
- *proto = PROTO_UNDEF;
}
+ return 1;
+ }
+ if (udp_port >= 0) {
+ *port = udp_port;
+ *proto = IPPROTO_UDP;
return 1;
}
#if defined(ultrix) || defined(__osf__)
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203111950.g2BJo9n86017>
