X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=utils.c;h=e01b633c09e0143ebf98dbdb62ef77deecacaf73;hp=aa4132be103b2a2191dbebcbcfb323cb85d4019d;hb=c007f08413edc15805c248a8d65f075bb5fb0bdd;hpb=8663e9de716248bf72832aee70090f574b3ff5d2 diff --git a/utils.c b/utils.c index aa4132b..e01b633 100644 --- a/utils.c +++ b/utils.c @@ -17,6 +17,7 @@ #include #include +#include #ifdef __APPLE__ #include @@ -118,6 +119,7 @@ int parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask) { char *astr = alloca(strlen(str) + 1); + int ret = 0; strcpy(astr, str); if (!split_netmask(astr, netmask, af == AF_INET6)) @@ -131,7 +133,23 @@ parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask) return 0; } - return inet_pton(af, astr, addr); + ret = inet_pton(af, astr, addr); + if (ret > 0) { + if (af == AF_INET) { + struct in_addr *ip4_addr = (struct in_addr *)addr; + uint32_t host_addr = ntohl(ip4_addr->s_addr); + + if (IN_EXPERIMENTAL(host_addr)) { + return 0; + } + } + else if (af == AF_INET6) { + if (IN6_IS_ADDR_MULTICAST((struct in6_addr *)addr)) { + return 0; + } + } + } + return ret; } char *