handle NULL when parsing IPv6 address (check for formatting)

Change-Id: I42e1288689946c295e0bd1490a5eb4d8befb5877
This commit is contained in:
Ivan Delamer 2011-10-28 13:54:16 -06:00
parent edcc859b58
commit 21333d0f18

View File

@ -91,12 +91,14 @@ ip6addr_aton(const char *cp, ip6_addr_t *addr)
current_block_value = 0;
for (s = cp; *s != 0; s++) {
if (*s == ':') {
if (addr) {
if (current_block_index & 0x1) {
addr->addr[addr_index++] |= current_block_value;
}
else {
addr->addr[addr_index] = current_block_value << 16;
}
}
current_block_index++;
current_block_value = 0;
if (current_block_index > 7) {
@ -110,8 +112,10 @@ ip6addr_aton(const char *cp, ip6_addr_t *addr)
addr_index++;
}
else {
if (addr) {
addr->addr[addr_index] = 0;
}
}
current_block_index++;
}
}
@ -126,24 +130,27 @@ ip6addr_aton(const char *cp, ip6_addr_t *addr)
}
}
if (addr) {
if (current_block_index & 0x1) {
addr->addr[addr_index++] |= current_block_value;
}
else {
addr->addr[addr_index] = current_block_value << 16;
}
}
/* convert to network byte order. */
if (addr) {
for (addr_index = 0; addr_index < 4; addr_index++) {
addr->addr[addr_index] = htonl(addr->addr[addr_index]);
}
}
if (current_block_index != 7) {
return 0;
}
return 1;
}
/**