diff options
| author | Daniil Baturin <daniil@baturin.org> | 2013-06-02 05:53:13 -0700 |
|---|---|---|
| committer | Daniil Baturin <daniil@baturin.org> | 2013-06-02 05:53:13 -0700 |
| commit | 83cf00e0117c4b41001a56f93cf4beae720cc6a0 (patch) | |
| tree | f9be4ab75a0a7df11f1a35103987a83f218bb13a /src/ipaddrcheck_functions.c | |
| parent | a64770739a28b05f6c5a033a3f2085959662b447 (diff) | |
| download | ipaddrcheck-83cf00e0117c4b41001a56f93cf4beae720cc6a0.tar.gz ipaddrcheck-83cf00e0117c4b41001a56f93cf4beae720cc6a0.zip | |
Add interface address validation support.
Fix IPv4 CIDR regex to support one-digit mask properly.
Diffstat (limited to 'src/ipaddrcheck_functions.c')
| -rw-r--r-- | src/ipaddrcheck_functions.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ipaddrcheck_functions.c b/src/ipaddrcheck_functions.c index dfcdcfb..0240914 100644 --- a/src/ipaddrcheck_functions.c +++ b/src/ipaddrcheck_functions.c @@ -48,7 +48,7 @@ int is_ipv4_cidr(char* address_str) const char *error; int erroffset; - re = pcre_compile("^((([1-9]\\d{0,2}|0)\\.){3}([1-9]\\d{0,2}|0)(\\/([1-3][0-9]|0)))$", + re = pcre_compile("^((([1-9]\\d{0,2}|0)\\.){3}([1-9]\\d{0,2}|0)\\/([1-9]\\d*|0))$", 0, &error, &erroffset, NULL); rc = pcre_exec(re, NULL, address_str, strlen(address_str), 0, 0, offsets, 1); @@ -443,3 +443,26 @@ int is_ipv6_link_local(CIDR *address) return(result); } +/* Is it an address that can belong an interface? */ +int is_valid_intf_address(CIDR *address, char* address_str, int allow_loopback) +{ + int result; + + if( (is_ipv4_broadcast(address) == RESULT_FAILURE) && + (is_ipv4_multicast(address) == RESULT_FAILURE) && + (is_ipv6_multicast(address) == RESULT_FAILURE) && + ((is_ipv4_loopback(address) == RESULT_FAILURE) || (allow_loopback == LOOPBACK_ALLOWED)) && + (cidr_equals(address, cidr_from_str(IPV6_LOOPBACK)) != 0) && + (cidr_equals(address, cidr_from_str(IPV4_UNSPECIFIED)) != 0) && + (cidr_contains(cidr_from_str(IPV4_THIS), address) != 0) && + (is_any_cidr(address_str) == RESULT_SUCCESS) ) + { + result = RESULT_SUCCESS; + } + else + { + result = RESULT_FAILURE; + } + + return(result); +} |
