From alex@zen.nash.org  Mon May 27 18:51:00 1996
Received: from zen.nash.org (nash.pr.mcs.net [204.95.47.72])
          by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id SAA19809;
          Mon, 27 May 1996 18:50:42 -0700 (PDT)
Received: (from alex@localhost) by zen.nash.org (8.7.5/8.6.12) id UAA00814; Mon, 27 May 1996 20:50:12 -0500 (CDT)
Message-Id: <199605280150.UAA00814@zen.nash.org>
Date: Mon, 27 May 1996 20:50:12 -0500 (CDT)
From: Alex Nash <alex@zen.nash.org>
Reply-To: nash@mcs.com
To: FreeBSD-gnats-submit@freebsd.org
Cc: phk@freebsd.org
Subject: IPFW: Resolve service names with -N option
X-Send-Pr-Version: 3.2

>Number:         1266
>Category:       bin
>Synopsis:       IPFW: Resolve service names with -N option
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    alex
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 27 19:00:02 PDT 1996
>Closed-Date:    Sun Jun 9 16:49:56 PDT 1996
>Last-Modified:  Sun Jun  9 16:50:14 PDT 1996
>Originator:     Alex Nash
>Release:        FreeBSD 2.1-STABLE i386
>Organization:
>Environment:

2.1.0-STABLE/CURRENT running IPFW.

>Description:

The -N option to ipfw resolves host names but not service names
(perhaps this is intentional?).

>How-To-Repeat:

# ipfw -N l

>Fix:

NOTE: These diffs are against those submitted in bin/1220.  
      The version numbers do not correspond to those in the FreeBSD 
      CVS tree.


	
Index: ipfw.c
===================================================================
RCS file: /home/alex/cvs/ipfw/ipfw.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -c -r1.4 -r1.5
*** ipfw.c	1996/05/19 18:28:45	1.4
--- ipfw.c	1996/05/28 01:16:42	1.5
***************
*** 15,21 ****
   *
   * NEW command line interface for IP firewall facility
   *
!  * $Id: ipfw.c,v 1.4 1996/05/19 18:28:45 alex Exp $
   *
   */
  
--- 15,21 ----
   *
   * NEW command line interface for IP firewall facility
   *
!  * $Id: ipfw.c,v 1.5 1996/05/28 01:16:42 alex Exp $
   *
   */
  
***************
*** 65,70 ****
--- 65,104 ----
  }                         
  
  void
+ print_port(port, comma, flg)
+ 	u_short port,flg;
+ 	const char *comma;
+ {
+ 	int printed = 0;
+ 
+ 	if (do_resolv) {
+ 		struct servent *se;
+ 		const char *protocol;
+ 
+ 		switch (flg & IP_FW_F_KIND) {
+ 			case IP_FW_F_TCP:
+ 				protocol = "tcp";
+ 				break;
+ 			case IP_FW_F_UDP:
+ 				protocol = "udp";
+ 				break;
+ 			default:
+ 				protocol = NULL;
+ 				break;
+ 		}
+ 
+ 		se = getservbyport(htons(port), protocol);
+ 
+ 		if (se) {
+ 			printf("%s%s", comma, se->s_name);
+ 			printed = 1;
+ 		}
+ 	} 
+ 	if (!printed)
+ 		printf("%s%d",comma,port);
+ }
+ 
+ void
  show_ipfw(chain)
  	struct ip_fw *chain;
  {
***************
*** 73,78 ****
--- 107,114 ----
  	struct hostent *he;
  	int i,mb;
  
+ 	if (do_resolv)
+ 		setservent(1/*stayopen*/);
  
  	printf("%05u ", chain->fw_number);
  
***************
*** 152,158 ****
  
  	comma = " ";
  	for (i=0;i<chain->fw_nsp; i++ ) {
! 		printf("%s%d",comma,chain->fw_pts[i]);
  		if (i==0 && (chain->fw_flg & IP_FW_F_SRNG))
  			comma = "-";
  		else
--- 188,194 ----
  
  	comma = " ";
  	for (i=0;i<chain->fw_nsp; i++ ) {
! 		print_port(chain->fw_pts[i], comma, chain->fw_flg);
  		if (i==0 && (chain->fw_flg & IP_FW_F_SRNG))
  			comma = "-";
  		else
***************
*** 190,196 ****
  
  	comma = " ";
  	for (i=0;i<chain->fw_ndp;i++) {
! 		printf("%s%d",comma,chain->fw_pts[chain->fw_nsp+i]);
  		if (i==0 && (chain->fw_flg & IP_FW_F_DRNG))
  			comma = "-";
  		else
--- 226,232 ----
  
  	comma = " ";
  	for (i=0;i<chain->fw_ndp;i++) {
! 		print_port(chain->fw_pts[chain->fw_nsp+i], comma, chain->fw_flg);
  		if (i==0 && (chain->fw_flg & IP_FW_F_DRNG))
  			comma = "-";
  		else
***************
*** 272,277 ****
--- 308,316 ----
  			}
  	}
  	printf("\n");
+ 
+ 	if (do_resolv)
+ 		endservent();
  }
  
  void


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->alex 
Responsible-Changed-By: alex 
Responsible-Changed-When: Wed May 29 16:40:04 PDT 1996 
Responsible-Changed-Why:  
I now have a chance to fix the things I complained about :) 
State-Changed-From-To: open->closed 
State-Changed-By: alex 
State-Changed-When: Sun Jun 9 16:49:56 PDT 1996 
State-Changed-Why:  
Changes entered into -current under the following versions: 

src/sbin/ipfw.c:         1.25 
src/sys/netinet/ip_fw.c: 1.37 
src/sys/netinet/ip_fw.h: 1.20 

>Unformatted:
