From skynyrd@opus.cts.cwu.edu  Sat Apr 19 16:18:07 1997
Received: from pahtoh.cwu.edu (root@pahtoh.cwu.edu [198.104.65.27])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id QAA21707
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 19 Apr 1997 16:18:05 -0700 (PDT)
Received: from opus.cts.cwu.edu (skynyrd@opus.cts.cwu.edu [198.104.92.71])
	by pahtoh.cwu.edu (8.8.5/8.8.5) with ESMTP id QAA09055
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 19 Apr 1997 16:17:33 -0700 (PDT)
Received: (from skynyrd@localhost)
	by opus.cts.cwu.edu (8.8.5/8.8.5) id QAA03006;
	Sat, 19 Apr 1997 16:17:32 -0700 (PDT)
Message-Id: <199704192317.QAA03006@opus.cts.cwu.edu>
Date: Sat, 19 Apr 1997 16:17:32 -0700 (PDT)
From: Chris Timmons <skynyrd@opus.cts.cwu.edu>
Reply-To: skynyrd@opus.cts.cwu.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: NTOHS(x) related compiler warnings and libpcap disfunction 
X-Send-Pr-Version: 3.2

>Number:         3353
>Category:       i386
>Synopsis:       NTOHS(x) related compiler warnings and libpcap disfunction
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    fenner
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 19 16:20:01 PDT 1997
>Closed-Date:    Mon May 26 19:00:10 PDT 1997
>Last-Modified:  Wed Mar 21 13:12:13 UTC 2012
>Originator:     Chris Timmons
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Central Washington University
>Environment:

3.0-CURRENT from today (world rebuilt)

>Description:

tcpdump(1) does not correctly process target ports for monitoring which are 
specified symbolically on the command line.  Given the command line: 

	tcpdump -d port time

the BPF packet matching code should be looking for 0x25 but instead looks 
for port 0x2500 - indicating a missed call to ntohs (on the value returned 
by getservbyname()):

        [snippet from the above tcpdump output]
	(009) jeq      #0x2500          jt 12   jf 10

tcpdump relies on pcap(3) to call getservbyname(), and coincidentally
interesting compilation warnings are issued when libpcap is built 
during make world:

/usr/src/lib/libpcap/../../contrib/libpcap/nametoaddr.c: 
    In function `pcap_nametoaddr':
/usr/src/lib/libpcap/../../contrib/libpcap/nametoaddr.c:89: 
    warning: statement with no effect

/usr/src/lib/libpcap/../../contrib/libpcap/nametoaddr.c: 
    In function `pcap_nametoport':
/usr/src/lib/libpcap/../../contrib/libpcap/nametoaddr.c:125: 
    warning: statement with no effect
/usr/src/lib/libpcap/../../contrib/libpcap/nametoaddr.c:141: 
    warning: statement with no effect


Line 125 of nametoaddr.c is a call to the NTOHS macro defined 
in sys/i386/include:

  123           sp = getservbyname(name, (char *)0);
  124           if (sp != NULL) {
  125                   NTOHS(sp->s_port);
  126                   *port = sp->s_port;


cc -E -c ../../contrib/libpcap/nametoaddr.c yields this 
(ostensibly correct per endian.h) expansion for line 125:

  (( sp->s_port ) = 
      __extension__ ({ register u_short __X = ( (u_short)( sp->s_port ) ); 
      __asm ("xchgb %h1, %b1"
           : "=q" (__X) 
           : "0" (__X));
       __X; }) ) ;


>How-To-Repeat:

I tried to reduce this to a simple test case, using NTOHS() in the same
way that libpcap does; I couldn't reproduce it.  So for now,

	cd /usr/src/lib/libpcap
	make

to get the compiler warnings, and use

	tcpdump -d udp port time to see the end result.


>Fix:
	
	unknown, but I'm going to review the #includes in 
	src/contrib/nametoaddr.c to see if there is perhaps
 	some heinous recursion or something else which might
	be confusing the compiler???   HELP!!!!
>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: FreeBSD-gnats-submit@freebsd.org, skynyrd@opus.cts.cwu.edu
Cc:  Subject: Re: i386/3353: NTOHS(x) related compiler warnings and libpcap disfunction
Date: Sun, 20 Apr 1997 21:11:49 +1000

 >tcpdump(1) does not correctly process target ports for monitoring which are 
 >specified symbolically on the command line.  Given the command line: 
 >...
 >tcpdump relies on pcap(3) to call getservbyname(), and coincidentally
 >interesting compilation warnings are issued when libpcap is built 
 >during make world:
 >
 >/usr/src/lib/libpcap/../../contrib/libpcap/nametoaddr.c: 
 >    In function `pcap_nametoaddr':
 >/usr/src/lib/libpcap/../../contrib/libpcap/nametoaddr.c:89: 
 >    warning: statement with no effect
 
 The bugs are that /usr/src/lib/libpcap/Makefile puts `-Dlint' in CFLAGS,
 and endian.h has broken ifdefs involving lint in -current (was broken
 in rev.1.14).  The Makefile has excessive -Wall flags and -Dlint is a
 wrong fix for them.  The Makefile also has bogus -I flags.  There are
 no sources in ${.CURDIR} except when ${.CURDIR} is the object directory,
 and this case is handled by `-I.'.  The sources are in ${PCAP_DISTDIR},
 etc.
 
 >cc -E -c ../../contrib/libpcap/nametoaddr.c yields this 
 >(ostensibly correct per endian.h) expansion for line 125:
 >
 >  (( sp->s_port ) = 
 >      __extension__ ({ register u_short __X = ( (u_short)( sp->s_port ) ); 
 >      __asm ("xchgb %h1, %b1"
 >           : "=q" (__X) 
 >           : "0" (__X));
 >       __X; }) ) ;
 
 You have to compile with the same CFLAGS as the Makefile to see the problem.
 CFLAGS is too long to type for contrib'ed sources :-(.
 
 I will fix endian.h.
 
 Bruce
Responsible-Changed-From-To: freebsd-bugs->fenner 
Responsible-Changed-By: fenner 
Responsible-Changed-When: Mon May 5 23:07:36 PDT 1997 
Responsible-Changed-Why:  
fenner is merging new libpcap and tcpdump (See PR#bin/3371) 

From: Bill Fenner <fenner@FreeBSD.org>
To: freebsd-gnats-submit
Cc:  Subject: Re: i386/3353: NTOHS(x) related compiler warnings and libpcap disfunction
Date: Mon, 5 May 1997 23:09:32 -0700 (PDT)

 Bruce's endian.h (rev 1.15) made libpcap work again, but the Makefile
 still needs to be fixed.  I will take care of this as part of my
 libpcap/tcpdump upgrade.
State-Changed-From-To: open->closed 
State-Changed-By: fenner 
State-Changed-When: Mon May 26 19:00:10 PDT 1997 
State-Changed-Why:  
libpcap Makefile fixed while upgrading to libpcap-0.3 . 
>Unformatted:
