From 00f98b395795533a9a424fa9bd55e52957ad1031 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Sat, 1 Jun 2013 13:26:42 -0700 Subject: Add missing address format validation functions. --- src/ipaddrcheck_functions.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/ipaddrcheck_functions.c') diff --git a/src/ipaddrcheck_functions.c b/src/ipaddrcheck_functions.c index 27a33fb..061ba8f 100644 --- a/src/ipaddrcheck_functions.c +++ b/src/ipaddrcheck_functions.c @@ -109,6 +109,60 @@ int is_ipv4_single(char* address_str) return(result); } +/* Is it an IPv6 address with prefix length? */ +int is_ipv6_cidr(char* address_str) +{ + int result; + + int offsets[1]; + pcre *re; + int rc; + const char *error; + int erroffset; + + re = pcre_compile("^((([0-9a-fA-F\\:])+)(\\/\\d{1,3}))$", + 0, &error, &erroffset, NULL); + rc = pcre_exec(re, NULL, address_str, strlen(address_str), 0, 0, offsets, 1); + + if( rc < 0 ) + { + result = RESULT_FAILURE; + } + else + { + result = RESULT_SUCCESS; + } + + return(result); +} + +/* Is it a single IPv6 address? */ +int is_ipv6_single(char* address_str) +{ + int result; + + int offsets[1]; + pcre *re; + int rc; + const char *error; + int erroffset; + + re = pcre_compile("^(([0-9a-fA-F\\:])+)$", + 0, &error, &erroffset, NULL); + rc = pcre_exec(re, NULL, address_str, strlen(address_str), 0, 0, offsets, 1); + + if( rc < 0 ) + { + result = RESULT_FAILURE; + } + else + { + result = RESULT_SUCCESS; + } + + return(result); +} + /* * Address checking functions that rely on libcidr */ -- cgit v1.2.3