aboutsummaryrefslogtreecommitdiff
path: root/net-mgmt/grepcidr
diff options
context:
space:
mode:
authorPhilip M. Gollucci <pgollucci@FreeBSD.org>2010-01-14 23:19:21 +0000
committerPhilip M. Gollucci <pgollucci@FreeBSD.org>2010-01-14 23:19:21 +0000
commitd780ccf8fbf8e9ec1d823feb4a39489269aa7cc5 (patch)
treea6a22357af5c469ebc09671480edda46375904e1 /net-mgmt/grepcidr
parent96278172d88fa26c68483e562eaaec1a521bf56f (diff)
downloadports-d780ccf8fbf8e9ec1d823feb4a39489269aa7cc5.tar.gz
ports-d780ccf8fbf8e9ec1d823feb4a39489269aa7cc5.zip
* Add an option to apply patch allowing to search for pattern anywhere in line
* Add -DHAVE_STRING_H to make compiler happy * Bump PORTREVISION PR: ports/141437 Submitted by: "Alexander V. Chernikov" <melifaro@ipfw.ru> Approved by: maintainer timeout (1 month)
Notes
Notes: svn path=/head/; revision=247894
Diffstat (limited to 'net-mgmt/grepcidr')
-rw-r--r--net-mgmt/grepcidr/Makefile13
-rw-r--r--net-mgmt/grepcidr/files/patch-grepcidr.c65
2 files changed, 76 insertions, 2 deletions
diff --git a/net-mgmt/grepcidr/Makefile b/net-mgmt/grepcidr/Makefile
index cf65612018a0..4a7b9c6f2390 100644
--- a/net-mgmt/grepcidr/Makefile
+++ b/net-mgmt/grepcidr/Makefile
@@ -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 --git a/net-mgmt/grepcidr/files/patch-grepcidr.c b/net-mgmt/grepcidr/files/patch-grepcidr.c
new file mode 100644
index 000000000000..8ec6e16a50e1
--- /dev/null
+++ b/net-mgmt/grepcidr/files/patch-grepcidr.c
@@ -0,0 +1,65 @@
+--- ./grepcidr.c.orig 2005-04-23 18:00:16.000000000 -0400
++++ ./grepcidr.c 2010-01-14 18:17:58.469773170 -0500
+@@ -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 */
+ }
+ }
+ }