mirror of
https://git.FreeBSD.org/ports.git
synced 2025-01-11 07:22:22 +00:00
* 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)
This commit is contained in:
parent
96278172d8
commit
d780ccf8fb
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=247894
@ -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>
|
||||
|
65
net-mgmt/grepcidr/files/patch-grepcidr.c
Normal file
65
net-mgmt/grepcidr/files/patch-grepcidr.c
Normal file
@ -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 */
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user