From owner-freebsd-bugs Mon Mar 11 11:50:16 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id D378737B417 for ; Mon, 11 Mar 2002 11:50:09 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g2BJo9n86017; Mon, 11 Mar 2002 11:50:09 -0800 (PST) (envelope-from gnats) Date: Mon, 11 Mar 2002 11:50:09 -0800 (PST) Message-Id: <200203111950.g2BJo9n86017@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Alan Bawden Subject: Re: bin/34843: `tcpdump port echo' filters for port 4 instead of 7 Reply-To: Alan Bawden Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/34843; it has been noted by GNATS. From: Alan Bawden 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