diff options
| author | Daniil Baturin <daniil@baturin.org> | 2013-06-02 00:22:53 -0700 |
|---|---|---|
| committer | Daniil Baturin <daniil@baturin.org> | 2013-06-02 00:22:53 -0700 |
| commit | a64770739a28b05f6c5a033a3f2085959662b447 (patch) | |
| tree | f34816ebaef15ba889eab36e2a5f7bf3eb051607 /src | |
| parent | 4822c9800c332da8501de67a1732f9b1651dfe97 (diff) | |
| download | ipaddrcheck-a64770739a28b05f6c5a033a3f2085959662b447.tar.gz ipaddrcheck-a64770739a28b05f6c5a033a3f2085959662b447.zip | |
Add missing IPv6 and protocol-agnostic format validation functions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ipaddrcheck.c | 18 | ||||
| -rw-r--r-- | src/ipaddrcheck_functions.c | 36 | ||||
| -rw-r--r-- | src/ipaddrcheck_functions.h | 2 |
3 files changed, 55 insertions, 1 deletions
diff --git a/src/ipaddrcheck.c b/src/ipaddrcheck.c index 80551e0..8b99b23 100644 --- a/src/ipaddrcheck.c +++ b/src/ipaddrcheck.c @@ -45,6 +45,8 @@ #define IS_IPV6_MULTICAST 190 #define IS_IPV6_LINKLOCAL 200 #define IS_VALID_INTF_ADDR 220 +#define IS_ANY_CIDR 230 +#define IS_ANY_SINGLE 240 static const struct option options[] = { @@ -52,6 +54,8 @@ static const struct option options[] = { "is-ipv4", no_argument, NULL, 'c' }, { "is-ipv4-cidr", no_argument, NULL, 'd' }, { "is-ipv4-single", no_argument, NULL, 'e' }, + { "is-any-cidr", no_argument, NULL, 'A' }, + { "is-any-single", no_argument, NULL, 'B' }, { "is-ipv4-host", no_argument, NULL, 'f' }, { "is-ipv4-net", no_argument, NULL, 'g' }, { "is-ipv4-broadcast", no_argument, NULL, 'h' }, @@ -97,7 +101,7 @@ int main(int argc, char* argv[]) return(EXIT_FAILURE); } - while( (optc = getopt_long(argc, argv, "abcdefghijklmnoprstuz?", options, &option_index)) != -1 ) + while( (optc = getopt_long(argc, argv, "acdefghijklmnoprstuzAB?", options, &option_index)) != -1 ) { switch(optc) { @@ -159,6 +163,12 @@ int main(int argc, char* argv[]) case 'u': action = IS_VALID_INTF_ADDR; break; + case 'A': + action = IS_ANY_CIDR; + break; + case 'B': + action = IS_ANY_SINGLE; + break; case '?': print_help(); return(0); @@ -257,6 +267,12 @@ int main(int argc, char* argv[]) case IS_IPV6_LINKLOCAL: result = is_ipv6_link_local(address); break; + case IS_ANY_CIDR: + result = is_any_cidr(address_str); + break; + case IS_ANY_SINGLE: + result = is_any_single(address_str); + break; } printf("action: %d\n", actions[action_count]); action_count--; diff --git a/src/ipaddrcheck_functions.c b/src/ipaddrcheck_functions.c index bb86ee7..dfcdcfb 100644 --- a/src/ipaddrcheck_functions.c +++ b/src/ipaddrcheck_functions.c @@ -145,6 +145,42 @@ int is_ipv6_single(char* address_str) return(result); } +/* Is it a CIDR-formatted IPv4 or IPv6 address? */ +int is_any_cidr(char* address_str) +{ + int result; + + if( (is_ipv4_cidr(address_str) == RESULT_SUCCESS) || + (is_ipv6_cidr(address_str) == RESULT_SUCCESS) ) + { + result = RESULT_SUCCESS; + } + else + { + result = RESULT_FAILURE; + } + + return(result); +} + +/* Is it a single IPv4 or IPv6 address? */ +int is_any_single(char* address_str) +{ + int result; + + if( (is_ipv4_single(address_str) == RESULT_SUCCESS) || + (is_ipv6_single(address_str) == RESULT_SUCCESS) ) + { + result = RESULT_SUCCESS; + } + else + { + result = RESULT_FAILURE; + } + + return(result); +} + /* * Address checking functions that rely on libcidr */ diff --git a/src/ipaddrcheck_functions.h b/src/ipaddrcheck_functions.h index 74a0372..34bb18e 100644 --- a/src/ipaddrcheck_functions.h +++ b/src/ipaddrcheck_functions.h @@ -47,6 +47,8 @@ int is_ipv4_cidr(char* address_str); int is_ipv4_single(char* address_str); int is_ipv6_cidr(char* address_str); int is_ipv6_single(char* address_str); +int is_any_cidr(char* address_str); +int is_any_single(char* address_str); int is_valid_address(CIDR *address); int is_ipv4(CIDR *address); int is_ipv4_host(CIDR *address); |
