From pete@ns.altadena.net  Thu May 31 16:03:59 2001
Return-Path: <pete@ns.altadena.net>
Received: from ns.altadena.net (ns.altadena.net [206.126.144.2])
	by hub.freebsd.org (Postfix) with ESMTP id 83BC137B422
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 31 May 2001 16:03:57 -0700 (PDT)
	(envelope-from pete@ns.altadena.net)
Received: (from pete@localhost)
	by ns.altadena.net (8.11.3/8.8.8) id f4VN0Bh81406;
	Thu, 31 May 2001 16:00:11 -0700 (PDT)
	(envelope-from pete)
Message-Id: <200105312300.f4VN0Bh81406@ns.altadena.net>
Date: Thu, 31 May 2001 16:00:11 -0700 (PDT)
From: pete@altadena.net
Reply-To: pete@altadena.net
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Enhancement to sort(1)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         27803
>Category:       gnu
>Synopsis:       Enhancement to sort(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    ceri
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 31 16:10:03 PDT 2001
>Closed-Date:    Sun Jun 08 11:01:43 PDT 2003
>Last-Modified:  Sun Jun 08 11:01:43 PDT 2003
>Originator:     Pete Carah
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
Altadena Internet
>Environment:
System: FreeBSD ns.altadena.net 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Sat Apr 28 22:19:41 PDT 2001 pete@ns.altadena.net:/usr/src/sys/compile/PUFFIN i386


>Description:
	Enhance sort with -I data type (IP address; parsing and byte
	ordering handled with system macros, thus possibly unsuitable
	for some systems.  I think freebsd always has netinet/*.h, etc.

	This probably should be submitted to gnu-bugs instead of here;
	if submitted there it will need autoconf stuff to detect the
	presence of network code.

>How-To-Repeat:
	IP addresses normally sorted lexically; this is a pain

>Fix:

diff -c /usr/src/gnu/usr.bin/sort/sort.c sort/sort.c
*** /usr/src/gnu/usr.bin/sort/sort.c	Sun Apr  8 02:21:56 2001
--- sort/sort.c	Thu May 31 15:55:47 2001
***************
*** 38,43 ****
--- 38,48 ----
  #include "error.h"
  #include "xstrtod.h"
  
+ /* added for -I - uses inet_addr and ntohl macros */
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
+ 
  #ifdef HAVE_LIMITS_H
  #include <limits.h>
  #else
***************
*** 99,104 ****
--- 104,110 ----
    int skipsblanks;		/* Skip leading white space at start. */
    int eword;			/* Zero-origin first word after field. */
    int echar;			/* Additional characters in field. */
+   int ipaddr;			/* field is an IP address. */
    int skipeblanks;		/* Skip trailing white space at finish. */
    int *ignore;			/* Boolean array of characters to ignore. */
    char *translate;		/* Translation applied to characters. */
***************
*** 1076,1081 ****
--- 1082,1111 ----
  	    return key->reverse ? -diff : diff;
  	  continue;
  	}
+       else if (key->ipaddr)	
+ 	{
+ 	unsigned long a, b;
+ 
+ 	if (*lima || *limb) 
+ 	  {
+ 	    char savea = *lima, saveb = *limb;
+ 	    *lima = *limb = '\0';
+ 	    a = ntohl(inet_addr(texta));
+ 	    b = ntohl(inet_addr(textb));
+ 	    *lima = savea;
+ 	    *limb = saveb;
+ 	  }
+ 	else
+ 	  {
+ 	    a = ntohl(inet_addr(texta));
+ 	    b = ntohl(inet_addr(textb));
+ 	  }
+ 
+ 	    if (a > b) return key->reverse ? -1 : 1;
+ 	    else if (b > a) return key->reverse ? 1 : -1;
+ 
+ 	    continue;
+ 	}
        else if (key->month)
  	{
  	  diff = getmonth (texta, lena) - getmonth (textb, lenb);
***************
*** 1701,1706 ****
--- 1731,1740 ----
  	  break;
  	case 'i':
  	  key->ignore = nonprinting;
+ 	  break;
+ 	case 'I':
+ 	  key->ipaddr = 1;
+ 	  key->skipsblanks = key->skipeblanks = 1;
  	  break;
  	case 'M':
  	  key->month = 1;

>Release-Note:
>Audit-Trail:

From: Kris Kennaway <kris@obsecurity.org>
To: pete@altadena.net
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: gnu/27803: Enhancement to sort(1)
Date: Sat, 2 Jun 2001 02:30:46 -0700

 --/2994txjAzEdQwm5
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 On Thu, May 31, 2001 at 04:00:11PM -0700, pete@altadena.net wrote:
 
 > 	This probably should be submitted to gnu-bugs instead of here;
 > 	if submitted there it will need autoconf stuff to detect the
 > 	presence of network code.
 
 Correct; we don't like to change externally-maintained code, because
 it often causes enormous hassles trying to update it to a later vendor
 release.
 
 Kris
 
 --/2994txjAzEdQwm5
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.6 (FreeBSD)
 Comment: For info see http://www.gnupg.org
 
 iD8DBQE7GLJGWry0BWjoQKURAnfqAKCVkaVAbJHBevzzzadpa6gEqgTN7QCfV2Gg
 5eLkdfjKNTRmEBGx6j2JDis=
 =CaSL
 -----END PGP SIGNATURE-----
 
 --/2994txjAzEdQwm5--
State-Changed-From-To: open->feedback 
State-Changed-By: johan 
State-Changed-When: Wed Jun 19 17:15:58 PDT 2002 
State-Changed-Why:  
Can you report this to the sort developer 
at GNU. Then when it is fixed can you also 
submitt a follow-up to this PR, please. 

We can then import the new sort version. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=27803 
State-Changed-From-To: feedback->closed 
State-Changed-By: ceri 
State-Changed-When: Sun Jun 8 11:01:41 PDT 2003 
State-Changed-Why:  
Feedback timeout (6 months or more). 
I will handle any feedback that this closure generates. 


Responsible-Changed-From-To: freebsd-bugs->ceri 
Responsible-Changed-By: ceri 
Responsible-Changed-When: Sun Jun 8 11:01:41 PDT 2003 
Responsible-Changed-Why:  
Feedback timeout (6 months or more). 
I will handle any feedback that this closure generates. 

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