X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fsubnet_parse.c;h=d877c7fd1b2cdfc6db49038b9218c75fccb1600a;hb=7ab400aebdc38e7ee5dafc0a2291bbbea25e3f7c;hp=d5b84eb647f6fa710e4f3eeb9ab2ced28ded7ae2;hpb=1c475ecb575367a6b3f9328b0f643ad636155341;p=tinc diff --git a/src/subnet_parse.c b/src/subnet_parse.c index d5b84eb6..d877c7fd 100644 --- a/src/subnet_parse.c +++ b/src/subnet_parse.c @@ -1,6 +1,6 @@ /* subnet_parse.c -- handle subnet parsing - Copyright (C) 2000-2012 Guus Sliepen , + Copyright (C) 2000-2021 Guus Sliepen , 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; @@ -175,9 +186,7 @@ static int subnet_compare_ipv6(const subnet_t *a, const subnet_t *b) { } int subnet_compare(const subnet_t *a, const subnet_t *b) { - int result; - - result = a->type - b->type; + int result = (int)a->type - (int)b->type; if(result) { return result;