Commit 94afda75 authored by Stephen Hemminger's avatar Stephen Hemminger

Compatiable network abbreviation support

Handle 10/8 as 10.0.0.0/8 and check for bogus values like 256/8.
This is a comprimise between original iproute2 parsing and standard BSD
parsing of abbreviated IPV4 addresses.
parent 750a405a
...@@ -246,6 +246,9 @@ int get_s8(__s8 *val, const char *arg, int base) ...@@ -246,6 +246,9 @@ int get_s8(__s8 *val, const char *arg, int base)
int get_addr_1(inet_prefix *addr, const char *name, int family) int get_addr_1(inet_prefix *addr, const char *name, int family)
{ {
unsigned long n;
char *endp;
memset(addr, 0, sizeof(*addr)); memset(addr, 0, sizeof(*addr));
if (strcmp(name, "default") == 0 || if (strcmp(name, "default") == 0 ||
...@@ -284,8 +287,25 @@ int get_addr_1(inet_prefix *addr, const char *name, int family) ...@@ -284,8 +287,25 @@ int get_addr_1(inet_prefix *addr, const char *name, int family)
addr->family = AF_INET; addr->family = AF_INET;
if (family != AF_UNSPEC && family != AF_INET) if (family != AF_UNSPEC && family != AF_INET)
return -1; return -1;
if (inet_aton(name, addr->data) <= 0)
n = strtoul(name, &endp, 0);
if (n > 255)
return -1; /* bogus network value */
if (endp == name) /* not a number */
return -1;
/* compatable with older usage (ie 10/8 = 10.0.0.0/8) */
if (strchr(name, '.') == NULL) {
addr->data[0] = n;
addr->bytelen = 4;
addr->bitlen = -1;
return 0;
}
if (inet_aton(name, (struct in_addr *)addr->data) <= 0)
return -1; return -1;
addr->bytelen = 4; addr->bytelen = 4;
addr->bitlen = -1; addr->bitlen = -1;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment