Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 Aug 2001 10:42:44 +0100
From:      Rasputin <rasputin@shaft.techsupport.co.uk>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/30235: /usr/sbin/portmap cannot listen to localhost UDP only (patch)
Message-ID:  <E15ckp2-0001vs-00@shaft.techsupport.co.uk>

next in thread | raw e-mail | index | archive | help

>Number:         30235
>Category:       bin
>Synopsis:       /usr/sbin/portmap cannot listen to localhost UDP only (patch)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 31 06:20:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Rasputin
>Release:        FreeBSD 4.4-PRERELEASE i386
>Organization:
SubMonkey.net
>Environment:
System: FreeBSD shaft.techsupport.co.uk 4.4-PRERELEASE FreeBSD 4.4-PRERELEASE #2: Wed Aug 8 17:59:16 BST 2001 setantae@shaft.techsupport.co.uk:/usr/obj/usr/src/sys/SHAFT i386


	
>Description:
	portmap(8) states that the -h commandline flag specifies
	specific IP addresses to listen on for UDP. It also states that 127.0.0.1
	is added to the list automatically.
	This causes portmap to attmept to bind twice to 127.0.0.1 if given
	'-h 127.0.0.1', preventing it from starting.

	Without this flag, there is no way to bind only to localhost
	(omitting -h causes portmap to bind to INADDR_ANY).

	The folllowing patch brings portmap into line with its manpage
	(i.e the behaviour of tcp ports has not been changed)
>How-To-Repeat:
	portmap -h 127.0.0.1
>Fix:

--- portmap.c.orig	Tue Apr 10 00:35:19 2001
+++ portmap.c	Thu Aug 30 13:51:06 2001
@@ -159,12 +159,26 @@
 	 * If no hosts were specified, just bind to INADDR_ANY.  Otherwise
 	 * make sure 127.0.0.1 is added to the list.
 	 */
-	++nhosts;
-	hosts = realloc(hosts, nhosts * sizeof(char *));
-	if (nhosts == 1)
+	if (nhosts == 0){
+		++nhosts;
+		hosts = realloc(hosts, nhosts * sizeof(char *));
 		hosts[0] = "0.0.0.0";
-	else
-		hosts[nhosts - 1] = "127.0.0.1";
+		}
+	else {
+	/* add localhost if not already there */
+
+		int n, lh_requested = 0;
+
+		for(n=0;n<nhosts;n++) {
+		if(!strcmp(hosts[n],"127.0.0.1")) lh_requested = 1;
+		}
+
+		if (!lh_requested) {
+			++nhosts;
+			hosts = realloc(hosts, nhosts * sizeof(char *));
+			hosts[nhosts - 1] = "127.0.0.1";
+		}
+	}
 
 	/*
 	 * Add UDP socket(s) - bind to specific IPs if asked to
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E15ckp2-0001vs-00>