From 962a4544caaa4b43a5000ccfab55ac5b621dfb5d Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Sat, 1 Jun 2013 09:18:59 -0700 Subject: Improve IPv4 regular expressions. --- src/ipaddrcheck_functions.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ipaddrcheck_functions.c b/src/ipaddrcheck_functions.c index e1ac23d..27a33fb 100644 --- a/src/ipaddrcheck_functions.c +++ b/src/ipaddrcheck_functions.c @@ -66,7 +66,7 @@ int is_ipv4_cidr(char* address_str) const char *error; int erroffset; - re = pcre_compile("^\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}/\\d{1,2}$", + re = pcre_compile("^((([1-9]\\d{0,2}|0)\\.){3}([1-9]\\d{0,2}|0)(\\/([1-3][0-9]|0)))$", 0, &error, &erroffset, NULL); rc = pcre_exec(re, NULL, address_str, strlen(address_str), 0, 0, offsets, 1); @@ -93,7 +93,7 @@ int is_ipv4_single(char* address_str) const char *error; int erroffset; - re = pcre_compile("^\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}$", + re = pcre_compile("^((([1-9]\\d{0,2}|0)\\.){3}([1-9]\\d{0,2}|0))$", 0, &error, &erroffset, NULL); rc = pcre_exec(re, NULL, address_str, strlen(address_str), 0, 0, offsets, 1); -- cgit v1.2.3