Subject: bin/10484: ipmon tcp/udp port number to service name mapping error
To: None <gnats-bugs@gnats.netbsd.org>
From: None <hopha@casema.net>
List: netbsd-bugs
Date: 06/30/2000 02:46:20
>Number:         10484
>Category:       bin
>Synopsis:       ipmon tcp/udp port number to service name mapping error
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 30 02:47:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Hans Hoppe
>Release:        1.4.2 / current (2000/06/30)
>Organization:
>Environment:
System: NetBSD cluster 1.4.2 NetBSD 1.4.2 (cluster) #4: Tue May 23 22:05:03 CEST 2000 shadum@cluster:/usr/local/src/sys/arch/i386/compile/cluster i386
/usr/src/dist/ipf/ipmon.c: v1.2.2.1 / v1.4


>Description:
ipmon has an option (-n) to resolve IP addresses to DNS names and tcp/udp
port numbers to service names. The translation of port numbers into service
names fails because the system call that returns entries from /etc/services
(getservent()) returns the port number in network byte order, but the function
in ipmon.c that does the port name translation (portname()) expects the
port number to be in host byte order.
This is on 1.4.2, but afaik also in current.

>How-To-Repeat:
Setup ipf logging rules; ipmon -n
IP addresses get resolved; port numbers don't.
>Fix:
This is a diff for ipmon.c v1.2.2.1

--- usr/src/dist/ipf/ipmon.c.orig	Mon Dec 20 21:56:33 1999
+++ usr/src/dist/ipf/ipmon.c	Fri Jun 30 01:35:12 2000
@@ -209,11 +209,11 @@
 		if (s->s_proto == NULL)
 			continue;
 		else if (!strcmp(s->s_proto, "tcp")) {
-			port = (u_int)s->s_port;
+			port = (u_int)ntohs(s->s_port);
 			name = s->s_name;
 			tab = tcp_ports;
 		} else if (!strcmp(s->s_proto, "udp")) {
-			port = (u_int)s->s_port;
+			port = (u_int)ntohs(s->s_port);
 			name = s->s_name;
 			tab = udp_ports;
 		} else
>Release-Note:
>Audit-Trail:
>Unformatted: