summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2013-06-03 00:37:09 -0700
committerDaniil Baturin <daniil@baturin.org>2013-06-03 00:37:09 -0700
commit92bc23a0c6a51660e693a37f5ad6a836122c4105 (patch)
tree5b2fd6c72f9c41377c7b38a7ad07190804385316
parentc5613c1c765bc61da93e612011925ec146bb9df7 (diff)
downloadipaddrcheck-92bc23a0c6a51660e693a37f5ad6a836122c4105.tar.gz
ipaddrcheck-92bc23a0c6a51660e693a37f5ad6a836122c4105.zip
Add support for is-any-host and is-any-net checks.
-rw-r--r--src/ipaddrcheck.c30
-rw-r--r--src/ipaddrcheck_functions.c38
-rw-r--r--src/ipaddrcheck_functions.h2
3 files changed, 70 insertions, 0 deletions
diff --git a/src/ipaddrcheck.c b/src/ipaddrcheck.c
index 6c98bcc..1801406 100644
--- a/src/ipaddrcheck.c
+++ b/src/ipaddrcheck.c
@@ -48,6 +48,8 @@
#define IS_ANY_CIDR 230
#define IS_ANY_SINGLE 240
#define ALLOW_LOOPBACK 250
+#define IS_ANY_HOST 260
+#define IS_ANY_NET 270
#define NO_ACTION 500
static const struct option options[] =
@@ -182,6 +184,12 @@ int main(int argc, char* argv[])
allow_loopback = LOOPBACK_ALLOWED;
action = NO_ACTION;
break;
+ case 'D':
+ action = IS_ANY_HOST;
+ break;
+ case 'E':
+ action = IS_ANY_NET;
+ break;
case '?':
print_help(program_name);
return(EXIT_SUCCESS);
@@ -295,6 +303,26 @@ int main(int argc, char* argv[])
break;
case NO_ACTION:
break;
+ case IS_ANY_HOST:
+ if( !is_any_cidr(address_str) )
+ {
+ result = RESULT_FAILURE;
+ }
+ else
+ {
+ result = is_any_host(address);
+ }
+ break;
+ case IS_ANY_NET:
+ if( !is_any_cidr(address_str) )
+ {
+ result = RESULT_FAILURE;
+ }
+ else
+ {
+ result = is_any_net(address);
+ }
+ break;
default:
break;
}
@@ -328,6 +356,8 @@ Options:\n\
--is-any-cidr Check if STRING is a valid IPv4 or IPv6 address\n\
with prefix length\n\
--is-any-single Check if STRING is a valid single IPv4 or IPv6 address\n\
+ --is-any-host Check if STRING is a valid IPv4 or IPv6 host address\n\
+ --is-any-net Check if STRING is a valid IPv4 or IPv6 network address\n\
--is-ipv4 Check if STRING is a valid IPv4 address with mask \n\
--is-ipv4-cidr Check if STRING is a valid CIDR-formatted address \n\
--is-ipv4-single Check if STRING is a valid single address\n\
diff --git a/src/ipaddrcheck_functions.c b/src/ipaddrcheck_functions.c
index 92c2aca..59b30a4 100644
--- a/src/ipaddrcheck_functions.c
+++ b/src/ipaddrcheck_functions.c
@@ -467,3 +467,41 @@ int is_valid_intf_address(CIDR *address, char* address_str, int allow_loopback)
return(result);
}
+
+/* Is it an IPv4 or IPv6 host address? */
+int is_any_host(CIDR *address)
+{
+ int result;
+
+ if( (is_ipv4_host(address) == RESULT_SUCCESS) ||
+ (is_ipv6_host(address) == RESULT_SUCCESS) )
+ {
+ result = RESULT_SUCCESS;
+ }
+ else
+ {
+ result = RESULT_FAILURE;
+ }
+
+ return(result);
+}
+
+/* Is it an IPv4 or IPv6 network address? */
+int is_any_net(CIDR *address)
+{
+ int result;
+
+ if( (is_ipv4_net(address) == RESULT_SUCCESS) ||
+ (is_ipv6_net(address) == RESULT_SUCCESS) )
+ {
+ result = RESULT_SUCCESS;
+ }
+ else
+ {
+ result = RESULT_FAILURE;
+ }
+
+ return(result);
+}
+
+
diff --git a/src/ipaddrcheck_functions.h b/src/ipaddrcheck_functions.h
index 78378f7..e444508 100644
--- a/src/ipaddrcheck_functions.h
+++ b/src/ipaddrcheck_functions.h
@@ -72,3 +72,5 @@ int is_ipv6_net(CIDR *address);
int is_ipv6_multicast(CIDR *address);
int is_ipv6_link_local(CIDR *address);
int is_valid_intf_address(CIDR *address, char* address_str, int allow_loopback);
+int is_any_host(CIDR *address);
+int is_any_net(CIDR *address);