From pckizer@nostrum.com  Sat Apr 14 01:14:46 2007
Return-Path: <pckizer@nostrum.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 499BB16A404
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 14 Apr 2007 01:14:46 +0000 (UTC)
	(envelope-from pckizer@nostrum.com)
Received: from nostrum.com (shaman.nostrum.com [72.232.15.10])
	by mx1.freebsd.org (Postfix) with ESMTP id C9CFB13C46A
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 14 Apr 2007 01:14:45 +0000 (UTC)
	(envelope-from pckizer@nostrum.com)
Received: from shaman.nostrum.com (pckizer@localhost.layeredtech.com [127.0.0.1])
	by nostrum.com (8.13.8/8.13.8) with ESMTP id l3E0jGbV061704
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Fri, 13 Apr 2007 19:45:16 -0500 (CDT)
	(envelope-from pckizer@shaman.nostrum.com)
Received: (from pckizer@localhost)
	by shaman.nostrum.com (8.13.8/8.13.8/Submit) id l3E0jFAi061703;
	Fri, 13 Apr 2007 19:45:15 -0500 (CDT)
	(envelope-from pckizer)
Message-Id: <200704140045.l3E0jFAi061703@shaman.nostrum.com>
Date: Fri, 13 Apr 2007 19:45:15 -0500 (CDT)
From: Philip Kizer <pckizer@nostrum.com>
Reply-To: Philip Kizer <pckizer@nostrum.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: jharris@widomaker.com
Subject: ports/net/fping patch to add -S source_addr option
X-Send-Pr-Version: 3.113
X-GNATS-Notify: jharris@widomaker.com

>Number:         111549
>Category:       ports
>Synopsis:       ports/net/fping patch to add -S source_addr option
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 14 01:20:02 GMT 2007
>Closed-Date:    Sat Sep 08 13:31:37 GMT 2007
>Last-Modified:  Sat Sep  8 13:40:02 GMT 2007
>Originator:     Philip Kizer
>Release:        FreeBSD 6.2-STABLE i386
>Organization:
>Environment:
System: FreeBSD shaman.nostrum.com 6.2-STABLE FreeBSD 6.2-STABLE #1: Tue Mar 20 23:33:38 CDT 2007 root@shaman:/usr/obj/usr/src/sys/CUSTOM i386


>Description:
	Several people have produced some patches for fping that adds an
	option to select the IP source_address for queries and some have
	said they submitted them to the sourceforge fping maintainer.
	Since I did not see any official fping distributions that include
	any of those patches, I recently Cc-ed the sourceforge fping
	maintainer's address in a question to the smokeping mailing-list
	asking about that patch but so far I have heard back only from
	that list with a pointer to a debian patch.  Per request from
	Jason Harris, I include here a copy of the patch that is usable
	in ports/net/fping/files that adds that option.

>How-To-Repeat:
	n/a

>Fix:

	The patch from:
		http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=198486
	was adapted to apply to the ports system.

	Put the following patch into
	ports/net/fping/files/patch-fping.c-dash-S and re-install fping.
	It will then take a <-S source_address> command-line option for
	selecting the out-going source IP:

diff -ru ../fping-2.4b2_to-ipv6-orig/fping.c ./fping.c
--- ../fping-2.4b2_to-ipv6-orig/fping.c	Sun Jan 20 19:06:30 2002
+++ ./fping.c	Fri Apr 13 14:36:02 2007
@@ -283,6 +283,12 @@
 u_int count = 1;
 u_int trials;
 u_int report_interval = 0;
+int src_addr_present = 0;
+#ifndef IPV6
+struct in_addr src_addr;
+#else
+struct in6_addr src_addr;
+#endif
 
 /* global stats */
 long max_reply = 0;
@@ -408,6 +414,11 @@
 	struct protoent *proto;
 	char *buf;
 	uid_t uid;
+#ifndef IPV6
+	struct sockaddr_in sa;
+#else
+	struct sockaddr_in6 sa;
+#endif
 	/* check if we are root */
 
 	if( geteuid() )
@@ -491,7 +502,7 @@
 
 	/* get command line options */
 
-	while( ( c = getopt( argc, argv, "gedhlmnqusaAvz:t:i:p:f:r:c:b:C:Q:B:" ) ) != EOF )
+	while( ( c = getopt( argc, argv, "gedhlmnqusaAvz:t:i:p:f:r:c:b:C:Q:B:S:" ) ) != EOF )
 	{
 		switch( c )
 		{
@@ -639,6 +650,16 @@
 			generate_flag = 1;
 			break;
 
+		case 'S':
+#ifndef IPV6
+			if( ! inet_pton( AF_INET, optarg, &src_addr ) )
+#else
+			if( ! inet_pton( AF_INET6, optarg, &src_addr ) )
+#endif
+				usage();
+			src_addr_present = 1;
+			break;
+
 		default:
 			usage();
 			break;
@@ -962,6 +983,22 @@
 	if( !num_hosts )
 		exit( 2 );
 
+	/* set the source address */
+
+	if( src_addr_present )
+	{
+		memset( &sa, 0, sizeof( sa ) );
+#ifndef IPV6
+		sa.sin_family = AF_INET;
+		sa.sin_addr = src_addr;
+#else
+		sa.sin6_family = AF_INET6;
+		sa.sin6_addr = src_addr;
+#endif
+		if ( bind( s, (struct sockaddr *)&sa, sizeof( sa ) ) < 0 )
+			errno_crash_and_burn( "cannot bind source address" );
+	}
+
 	/* allocate array to hold outstanding ping requests */
 
 	table = ( HOST_ENTRY** )malloc( sizeof( HOST_ENTRY* ) * num_hosts );
@@ -2732,6 +2769,7 @@
 	fprintf( stderr, "   -Q n       same as -q, but show summary every n seconds\n" );
 	fprintf( stderr, "   -r n       number of retries (default %d)\n", retry );
 	fprintf( stderr, "   -s         print final stats\n" );
+	fprintf( stderr, "   -S addr    set source address\n" );
 	fprintf( stderr, "   -t n       individual target initial timeout (in millisec) (default %d)\n", timeout / 100 );
 	fprintf( stderr, "   -u         show targets that are unreachable\n" );
 	fprintf( stderr, "   -v         show version\n" );



>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: edwin 
State-Changed-When: Sat Apr 14 01:20:10 UTC 2007 
State-Changed-Why:  
Awaiting maintainers feedback 

http://www.freebsd.org/cgi/query-pr.cgi?pr=111549 
State-Changed-From-To: feedback->closed 
State-Changed-By: edwin 
State-Changed-When: Sat Sep 8 13:31:25 UTC 2007 
State-Changed-Why:  
Committed, thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/111549: commit references a PR
Date: Sat,  8 Sep 2007 13:31:28 +0000 (UTC)

 edwin       2007-09-08 13:31:22 UTC
 
   FreeBSD ports repository
 
   Modified files:
     net/fping            Makefile 
   Added files:
     net/fping/files      patch-sourceaddr 
   Log:
   ports/net/fping patch to add -S source_addr option
   
           Several people have produced some patches for fping that adds an
           option to select the IP source_address for queries and some have
           said they submitted them to the sourceforge fping maintainer.
           Since I did not see any official fping distributions that include
           any of those patches, I recently Cc-ed the sourceforge fping
           maintainer's address in a question to the smokeping mailing-list
           asking about that patch but so far I have heard back only from
           that list with a pointer to a debian patch. Per request from
           Jason Harris, I include here a copy of the patch that is usable
           in ports/net/fping/files that adds that option.
   
   PR:             ports/111549
   Submitted by:   Philip Kizer <pckizer@nostrum.com>
   Approved by:    maintainer timeout
   
   Revision  Changes    Path
   1.25      +1 -0      ports/net/fping/Makefile
   1.1       +88 -0     ports/net/fping/files/patch-sourceaddr (new)
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
