Update copyright notices.
[tinc] / src / subnet_parse.c
index 88513f6..32b7e0a 100644 (file)
@@ -1,6 +1,6 @@
 /*
     subnet_parse.c -- handle subnet parsing
-    Copyright (C) 2000-2012 Guus Sliepen <guus@tinc-vpn.org>,
+    Copyright (C) 2000-2021 Guus Sliepen <guus@tinc-vpn.org>,
                   2000-2005 Ivo Timmermans
 
     This program is free software; you can redistribute it and/or modify
@@ -87,6 +87,17 @@ void maskcpy(void *va, const void *vb, int masklen, int len) {
        }
 }
 
+bool subnetcheck(const subnet_t subnet) {
+       if(((subnet.type == SUBNET_IPV4)
+                       && !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof(subnet.net.ipv4.address)))
+                       || ((subnet.type == SUBNET_IPV6)
+                           && !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof(subnet.net.ipv6.address)))) {
+               return false;
+       }
+
+       return true;
+}
+
 bool maskcheck(const void *va, int masklen, int len) {
        int i;
        const char *a = va;
@@ -371,7 +382,7 @@ bool str2net(subnet_t *subnet, const char *subnetstr) {
 
 bool net2str(char *netstr, int len, const subnet_t *subnet) {
        if(!netstr || !subnet) {
-               logger(DEBUG_ALWAYS, LOG_ERR, "net2str() was called with netstr=%p, subnet=%p!", netstr, subnet);
+               logger(DEBUG_ALWAYS, LOG_ERR, "net2str() was called with netstr=%p, subnet=%p!", (void *)netstr, (void *)subnet);
                return false;
        }