Date: Mon, 27 May 1996 20:50:12 -0500 (CDT) From: Alex Nash <alex@zen.nash.org> To: FreeBSD-gnats-submit@freebsd.org Cc: phk@freebsd.org Subject: bin/1266: IPFW: Resolve service names with -N option Message-ID: <199605280150.UAA00814@zen.nash.org> Resent-Message-ID: <199605280200.TAA20306@freefall.freebsd.org>
index | next in thread | raw e-mail
>Number: 1266
>Category: bin
>Synopsis: IPFW: Resolve service names with -N option
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Mon May 27 19:00:02 PDT 1996
>Last-Modified:
>Originator: Alex Nash
>Organization:
>Release: FreeBSD 2.1-STABLE i386
>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
>Audit-Trail:
>Unformatted:
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605280150.UAA00814>
