From Paul.Hernaus@nl.origin-it.com Thu Aug 12 05:38:55 1999
Return-Path: <Paul.Hernaus@nl.origin-it.com>
Received: from gw-nl3.philips.com (gw-nl3.philips.com [192.68.44.35])
	by hub.freebsd.org (Postfix) with ESMTP id 11B3015757
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 12 Aug 1999 05:38:50 -0700 (PDT)
	(envelope-from Paul.Hernaus@nl.origin-it.com)
Received: from smtprelay-nl1.philips.com (localhost.philips.com [127.0.0.1])
          by gw-nl3.philips.com with ESMTP id OAA12497
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 12 Aug 1999 14:38:40 +0200 (MEST)
          (envelope-from Paul.Hernaus@nl.origin-it.com)
Received: from smtprelay-eur1.philips.com(130.139.36.3) by gw-nl3.philips.com via mwrap (4.0a)
	id xma012490; Thu, 12 Aug 99 14:38:40 +0200
Received: from itchy.mpn.cp.philips.com (itchy.mpn.cp.philips.com [130.139.64.191]) 
	by smtprelay-nl1.philips.com (8.9.3/8.8.5-1.2.2m-19990317) with ESMTP id OAA15995
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 12 Aug 1999 14:38:39 +0200 (MET DST)
Received: by itchy.mpn.cp.philips.com (Postfix, from userid 100)
	id 64135702C; Thu, 12 Aug 1999 14:38:39 +0200 (CEST)
Message-Id: <19990812123839.64135702C@itchy.mpn.cp.philips.com>
Date: Thu, 12 Aug 1999 14:38:39 +0200 (CEST)
From: Paul.Hernaus@nl.origin-it.com
Reply-To: Paul.Hernaus@nl.origin-it.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: Fetch doesn't default to the correct http-port when no port is specified in the environment
X-Send-Pr-Version: 3.2

>Number:         13092
>Category:       bin
>Synopsis:       Fetch doesn't default to the correct http-port when no port is specifie d in the environment
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 12 05:40:01 PDT 1999
>Closed-Date:    Thu Aug 31 07:54:26 PDT 2000
>Last-Modified:  Thu Aug 31 07:54:39 PDT 2000
>Originator:     Paul Hernaus
>Release:        FreeBSD 3.2-STABLE i386
>Organization:
Origin Nederland B.V.
>Environment:
stable as of now


>Description:

[~] paul@itchy> setenv HTTP_PROXY www-proxy.mpn.cp.philips.com
[~] paul@itchy> fetch http://www.freebsd.org/index.html
fetch: sendmsg: www-proxy.mpn.cp.philips.com: Can't assign requested address
[~] paul@itchy>

>How-To-Repeat:

See above

>Fix:

Apply the following patch against stable. Note that this also fixes a
missing dependency on fetch.h.


diff -u /usr/src/usr.bin/fetch/Makefile /tmp/fetch/Makefile
--- /usr/src/usr.bin/fetch/Makefile	Thu Jan 30 22:43:35 1997
+++ /tmp/fetch/Makefile	Thu Aug 12 14:15:51 1999
@@ -1,5 +1,5 @@
 PROG = fetch
-SRCS = file.c ftp.c http.c main.c util.c uri.c
+SRCS = fetch.h file.c ftp.c http.c main.c util.c uri.c
 
 CFLAGS+=	-Wall -Wwrite-strings -Wmissing-prototypes
 
diff -u /usr/src/usr.bin/fetch/fetch.h /tmp/fetch/fetch.h
--- /usr/src/usr.bin/fetch/fetch.h	Tue Dec  8 14:00:49 1998
+++ /tmp/fetch/fetch.h	Thu Aug 12 14:16:05 1999
@@ -37,6 +37,9 @@
 #define	FETCH_VERSION "fetch/1.0"
 #define PATH_CP "/bin/cp"
 
+#define DEFAULT_FTP_PORT 21
+#define DEFAULT_HTTP_PORT 80
+
 struct fetch_state {
 	const char *fs_status;
 	const char *fs_outputfile;
diff -u /usr/src/usr.bin/fetch/ftp.c /tmp/fetch/ftp.c
--- /usr/src/usr.bin/fetch/ftp.c	Fri Jun 25 04:57:24 1999
+++ /tmp/fetch/ftp.c	Thu Aug 12 14:13:21 1999
@@ -117,7 +117,7 @@
 
 		port = ul;
 	} else {
-		port = 21;
+		port = DEFAULT_FTP_PORT;
 	}
 
 	p = slash + 1;
@@ -253,7 +253,7 @@
 	hostname = getenv("FTP_PROXY");
 	port = strchr(hostname, ':');
 	if (port == 0) {
-		portno = 21;
+		portno = DEFAULT_FTP_PORT;
 	} else {
 		unsigned long ul;
 		char *ep;
@@ -289,12 +289,13 @@
 	user = ftps->ftp_user ? ftps->ftp_user : "anonymous";
 	/* user @ hostname [ @port ] \0 */
 	newuser = safe_malloc(strlen(user) + 1 + strlen(ftps->ftp_hostname)
-			      + ((ftps->ftp_port != 21) ? 6 : 0) + 1);
+			      + ((ftps->ftp_port != DEFAULT_FTP_PORT) ? 6 : 0)
+			      + 1);
 
 	strcpy(newuser, user);
 	strcat(newuser, "@");
 	strcat(newuser, ftps->ftp_hostname);
-	if (ftps->ftp_port != 21) {
+	if (ftps->ftp_port != DEFAULT_FTP_PORT) {
 		char numbuf[6];
 
 		snprintf(numbuf, sizeof(numbuf), "%d", ftps->ftp_port);
diff -u /usr/src/usr.bin/fetch/http.c /tmp/fetch/http.c
--- /usr/src/usr.bin/fetch/http.c	Fri Jun 25 04:57:26 1999
+++ /tmp/fetch/http.c	Thu Aug 12 14:12:19 1999
@@ -179,7 +179,7 @@
 
 		port = ul;
 	} else {
-		port = 80;
+		port = DEFAULT_HTTP_PORT;
 	}
 
 	p = slash;
@@ -476,7 +476,9 @@
 	memset(&sin, 0, sizeof sin);
 	sin.sin_family = AF_INET;
 	sin.sin_len = sizeof sin;
-	sin.sin_port = htons(https->http_port);
+	sin.sin_port = htons(https->http_port != 0
+				? https->http_port
+				: DEFAULT_HTTP_PORT);
 
 	fs->fs_status = "looking up hostname";
 	if (inet_aton(https->http_hostname, &sin.sin_addr) == 0) {

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: des 
Responsible-Changed-When: Thu Aug 12 06:24:07 PDT 1999 
Responsible-Changed-Why:  
I'll handle it. 

From: Dag-Erling Smorgrav <des@flood.ping.uio.no>
To: Paul.Hernaus@nl.origin-it.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/13092: Fetch doesn't default to the correct http-port when no port is specified in the environment
Date: 12 Aug 1999 15:24:17 +0200

 Paul.Hernaus@nl.origin-it.com writes:
 > +#define DEFAULT_FTP_PORT 21
 > +#define DEFAULT_HTTP_PORT 80
 
 No, the correct fix is to use getservbyname() to obtain the port
 numbers.
 
 DES
 -- 
 Dag-Erling Smorgrav - des@flood.ping.uio.no
 
State-Changed-From-To: open->closed 
State-Changed-By: des 
State-Changed-When: Thu Aug 31 07:54:26 PDT 2000 
State-Changed-Why:  
Fixed in 4.x and 5.x. 3.x is no longer supported. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=13092 
>Unformatted:
