diff options
| author | Daniil Baturin <daniil@baturin.org> | 2013-06-01 13:26:42 -0700 |
|---|---|---|
| committer | Daniil Baturin <daniil@baturin.org> | 2013-06-01 13:26:42 -0700 |
| commit | 00f98b395795533a9a424fa9bd55e52957ad1031 (patch) | |
| tree | 94795ac4f40f10e2987fd9a951577ed75c7a83d1 /src/ipaddrcheck_functions.c | |
| parent | 962a4544caaa4b43a5000ccfab55ac5b621dfb5d (diff) | |
| download | ipaddrcheck-00f98b395795533a9a424fa9bd55e52957ad1031.tar.gz ipaddrcheck-00f98b395795533a9a424fa9bd55e52957ad1031.zip | |
Add missing address format validation functions.
Diffstat (limited to 'src/ipaddrcheck_functions.c')
| -rw-r--r-- | src/ipaddrcheck_functions.c | 54 |
1 files changed, 54 insertions, 0 deletions
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 */ |
