From nobody@FreeBSD.org  Thu Mar  2 18:27:12 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 0E4B316A422
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  2 Mar 2006 18:27:12 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id C28DC43D46
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  2 Mar 2006 18:27:11 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k22IRBXv093171
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 2 Mar 2006 18:27:11 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k22IRBWs093170;
	Thu, 2 Mar 2006 18:27:11 GMT
	(envelope-from nobody)
Message-Id: <200603021827.k22IRBWs093170@www.freebsd.org>
Date: Thu, 2 Mar 2006 18:27:11 GMT
From: Josh Carroll <josh.carroll@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Enhancement to pkg_add to add -4 flag to force ipv4
X-Send-Pr-Version: www-2.3

>Number:         94032
>Category:       bin
>Synopsis:       [patch] Enhancement to pkg_add(1) to add -4 flag to force ipv4
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    portmgr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 02 18:30:04 GMT 2006
>Closed-Date:    Wed May 28 14:56:29 UTC 2014
>Last-Modified:  Wed May 28 14:56:29 UTC 2014
>Originator:     Josh Carroll
>Release:        6.0-RELEASE-p4
>Organization:
n/a
>Environment:
FreeBSD pflog.net 6.0-RELEASE-p4 FreeBSD 6.0-RELEASE-p4 #11: Wed Jan 25 09:11:41 PST 2006     root@pflog.net:/usr/obj/usr/src/sys/DEBLIN  i386

>Description:
In some circumstances, a user with both IPv4 and IPv6 will have trouble with pkg_add, as it tries to use the PF_INET6 family. The fetch program supports a -4 flags, but currently, pkg_add does not have a way to force use of IPv4. It appears as though libfetch supports this, so I have added a -4 flag to pkg_add, which sets the proper flag in the call to fetchGetURL.

The attached patch appears to patch cleanly against 5.4-R, 6.0-R, and 6.1-BETA2, and should be 100% backward compatible (e.g. unless the user supplies the -4 flag, it should operate the same as before).

Thanks,
Josh
>How-To-Repeat:
n/a
>Fix:
To apply:

cd /usr/src
patch -p1 < /path/to/pkg_install.patch

diff -u -p -r src.old/usr.sbin/pkg_install/add/main.c src/usr.sbin/pkg_install/add/main.c
--- src.old/usr.sbin/pkg_install/add/main.c	Thu Oct 27 11:38:48 2005
+++ src/usr.sbin/pkg_install/add/main.c	Wed Mar  1 18:57:12 2006
@@ -27,7 +27,7 @@ __FBSDID("$FreeBSD: src/usr.sbin/pkg_ins
 #include "lib.h"
 #include "add.h"
 
-static char Options[] = "hvIRfnrp:SMt:C:";
+static char Options[] = "hvIRfnrp:SMt:C:4";
 
 char	*Prefix		= NULL;
 char	*Chroot		= NULL;
@@ -147,6 +147,10 @@ main(int argc, char **argv)
 
 	case 'C':
 	    Chroot = optarg;
+	    break;
+
+	case '4':
+	    ForceIpv4 = TRUE;
 	    break;
 
 	case 'h':
diff -u -p -r src.old/usr.sbin/pkg_install/add/pkg_add.1 src/usr.sbin/pkg_install/add/pkg_add.1
--- src.old/usr.sbin/pkg_install/add/pkg_add.1	Sun Feb 13 14:25:30 2005
+++ src/usr.sbin/pkg_install/add/pkg_add.1	Thu Mar  2 10:12:58 2006
@@ -23,7 +23,7 @@
 .Nd a utility for installing software package distributions
 .Sh SYNOPSIS
 .Nm
-.Op Fl vInfrRMS
+.Op Fl vInfrRMS4
 .Op Fl t Ar template
 .Op Fl p Ar prefix
 .Op Fl C Ar chrootdir
@@ -82,6 +82,8 @@ will search them in each directory named
 .Ev PKG_PATH .
 .It Fl v
 Turn on verbose output.
+.It Fl 4
+Use ipv4.
 .It Fl I
 If any installation scripts (pre-install or post-install) exist for a given
 package, do not execute them.
diff -u -p -r src.old/usr.sbin/pkg_install/lib/global.c src/usr.sbin/pkg_install/lib/global.c
--- src.old/usr.sbin/pkg_install/lib/global.c	Sun Oct 17 22:34:54 2004
+++ src/usr.sbin/pkg_install/lib/global.c	Wed Mar  1 18:57:12 2006
@@ -27,6 +27,7 @@ __FBSDID("$FreeBSD: src/usr.sbin/pkg_ins
 /* These are global for all utils */
 Boolean	Quiet		= FALSE;
 Boolean	Verbose		= FALSE;
+Boolean	ForceIpv4	= FALSE;
 Boolean	Fake		= FALSE;
 Boolean	Force		= FALSE;
 int AutoAnswer		= FALSE;
diff -u -p -r src.old/usr.sbin/pkg_install/lib/lib.h src/usr.sbin/pkg_install/lib/lib.h
--- src.old/usr.sbin/pkg_install/lib/lib.h	Tue Jun 14 08:05:43 2005
+++ src/usr.sbin/pkg_install/lib/lib.h	Wed Mar  1 18:57:12 2006
@@ -229,6 +229,7 @@ int		version_cmp(const char *, const cha
 /* Externs */
 extern Boolean	Quiet;
 extern Boolean	Verbose;
+extern Boolean	ForceIpv4;
 extern Boolean	Fake;
 extern Boolean  Force;
 extern int	AutoAnswer;
diff -u -p -r src.old/usr.sbin/pkg_install/lib/url.c src/usr.sbin/pkg_install/lib/url.c
--- src.old/usr.sbin/pkg_install/lib/url.c	Tue Jun 29 12:06:42 2004
+++ src/usr.sbin/pkg_install/lib/url.c	Thu Mar  2 10:15:17 2006
@@ -42,6 +42,9 @@ fileGetURL(const char *base, const char 
     int pfd[2], pstat, r, w = 0;
     char *hint;
     int fd;
+	/* support up to 15 optional flags to fetchGetURL */
+	char flags[16];
+	char *pflags = flags;
 
     rp = NULL;
     /* Special tip that sysinstall left for us */
@@ -95,8 +98,14 @@ fileGetURL(const char *base, const char 
     else
 	strcpy(fname, spec);
 
-    if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
-	printf("Error: FTP Unable to get %s: %s\n",
+	if(Verbose)
+		*pflags++ = 'v';
+	if(ForceIpv4)
+		*pflags++ = '4';
+	*pflags = '\0';
+
+    if ((ftp = fetchGetURL(fname, pflags)) == NULL) {
+		printf("Error: FTP Unable to get %s: %s\n",
 	       fname, fetchLastErrString);
 	return NULL;
     }
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->krion 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Mar 2 19:42:02 UTC 2006 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94032 
State-Changed-From-To: open->feedback 
State-Changed-By: krion 
State-Changed-When: Wed Mar 15 01:25:39 UTC 2006 
State-Changed-Why:  
Could you tell under what circumstances pkg_add tries to us PF_INET6 ? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94032 

From: Bruce Cran <bruce@cran.org.uk>
To: bug-followup@FreeBSD.org, josh.carroll@gmail.com
Cc:  
Subject: Re: bin/94032: [patch] Enhancement to pkg_add(1) to add -4 flag to
 force ipv4
Date: Mon, 25 Feb 2008 23:22:02 +0000

 At least on FreeBSD 7.0-RC, pkg_add will try and connect over IPv6 if an 
     address is configured, before falling back to IPv4 if that fails. 
 On my machine which has both v4 and v6 working properly, pkg_add will 
 always fetch packages over the v6 route.
 
 --
 Bruce
State-Changed-From-To: feedback->open 
State-Changed-By: gavin 
State-Changed-When: Wed May 21 16:35:50 UTC 2008 
State-Changed-Why:  
Mark as open - the feedback requested has been provided by brucec 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94032 
Responsible-Changed-From-To: krion->portmgr 
Responsible-Changed-By: flz 
Responsible-Changed-When: Fri Jul 17 13:41:46 UTC 2009 
Responsible-Changed-Why:  
pkg_install is maintained by portmgr. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94032 
State-Changed-From-To: open->closed 
State-Changed-By: bapt 
State-Changed-When: Wed May 28 14:56:29 UTC 2014 
State-Changed-Why:  
pkg_install is not being worked on anymore 

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