Date: Sun, 13 Dec 2009 21:59:17 GMT From: "Alexander V. Chernikov" <melifaro@ipfw.ru> To: freebsd-gnats-submit@FreeBSD.org Subject: ports/141437: [patch] net-mgmt/grepcidr search anywhere in line patch Message-ID: <200912132159.nBDLxH7X006251@www.freebsd.org> Resent-Message-ID: <200912132200.nBDM07tW044656@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 141437 >Category: ports >Synopsis: [patch] net-mgmt/grepcidr search anywhere in line patch >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Dec 13 22:00:07 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Alexander V. Chernikov >Release: 9.0-CURRENT amd64 >Organization: >Environment: FreeBSD ws.ipfw.ru 9.0-CURRENT FreeBSD 9.0-CURRENT #0: Fri Oct 23 22:14:57 MSD 2009 root@ws.ipfw.ru:/var/ports_tmp/usj/obj/usr/src/sys/WS amd64 >Description: * Add an option to apply patch allowing to search for pattern anywhere in line * Add -DHAVE_STRING_H to make compiler happy * Bump PORTREVISION >How-To-Repeat: >Fix: Patch attached with submission follows: diff -urN grepcidr.orig/Makefile grepcidr/Makefile --- grepcidr.orig/Makefile 2009-12-14 00:38:17.261417278 +0300 +++ grepcidr/Makefile 2009-12-14 00:50:37.902385077 +0300 @@ -7,19 +7,28 @@ PORTNAME= grepcidr PORTVERSION= 1.3 +PORTREVISION= 1 CATEGORIES= net-mgmt textproc MASTER_SITES= http://www.pc-tools.net/files/unix/ MAINTAINER= doug+ports@idmf.net COMMENT= Filter IP addresses matching IPv4 CIDR/network specification +OPTIONS= SEARCH "Enable pattern search anywhere in line" off + PLIST_FILES= bin/grepcidr +.include <bsd.port.pre.mk> + +.if defined(WITH_SEARCH) +EXTRA_PATCHES+= ${FILESDIR}/find_anywhere.diff +.endif + do-configure: @${REINPLACE_CMD} \ -e 's|/usr/local/bin|${PREFIX}/bin|' \ - -e 's|-s -O3 -Wall -pedantic|${CFLAGS}|' \ + -e 's|-s -O3 -Wall -pedantic|${CFLAGS} -DHAVE_STRING_H|' \ -e 's|gcc|${CC}|' \ ${WRKSRC}/Makefile -.include <bsd.port.mk> +.include <bsd.port.post.mk> diff -urN grepcidr.orig/files/find_anywhere.diff grepcidr/files/find_anywhere.diff --- grepcidr.orig/files/find_anywhere.diff 1970-01-01 03:00:00.000000000 +0300 +++ grepcidr/files/find_anywhere.diff 2009-12-14 00:38:50.490126204 +0300 @@ -0,0 +1,65 @@ +--- grepcidr.c.orig 2005-06-06 15:16:09.000000000 +0200 ++++ grepcidr.c 2005-06-06 15:19:15.000000000 +0200 +@@ -81,13 +81,38 @@ + Convert IP address string to 32-bit integer version + Returns 0 on failure + */ +-unsigned int ip_to_uint(const char* ip) ++unsigned int ip_to_uint(char** ip) + { + unsigned int IP[4]; /* 4 octets for IP address */ +- if ((sscanf(ip, "%u.%u.%u.%u", &IP[0], &IP[1], &IP[2], &IP[3]) == 4) && VALID_IP(IP)) ++ char *p = *ip; ++ char *dot; ++ ++ while (*p) { ++ while (*p && (*p < '0' || *p > '9')) ++ p++; ++ if (!*p) ++ break; ++ ++ /* speedup: check if the first digits are followed by a dot */ ++ dot = p + 1; ++ while (*dot >= '0' && *dot <='9') ++ dot++; ++ if (dot > p+3 || *dot != '.') { ++ p = dot; ++ continue; ++ } ++ ++ if ((sscanf(p, "%u.%u.%u.%u", &IP[0], &IP[1], &IP[2], &IP[3]) == 4) && VALID_IP(IP)) { ++ /* point to next possible integer */ ++ while (*p >= '0' && *p <= '9') ++ p++; ++ *ip = p; + return BUILD_IP(IP); +- else +- return 0; ++ } ++ p++; ++ } ++ *ip = p; ++ return 0; + } + + +@@ -276,7 +301,10 @@ + while (fgets(line, sizeof(line), inp_stream)) + { + struct netspec key; +- if ((key.min=ip_to_uint(line))) ++ char *ptr; ++ ++ ptr = line; ++ while ((key.min=ip_to_uint(&ptr))) + { + int match = 0; + if (bsearch(&key, array, patterns, sizeof(struct netspec), netsearch)) +@@ -288,6 +316,7 @@ + counting++; + else + printf("%s", line); ++ break; /* match only once per line */ + } + } + } >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912132159.nBDLxH7X006251>