if (sscanf(str, "%u.%u.%u.%u", &a1, &a2, &a3, &a4) != 4) {
SAYF("Malformed IPv4 address.");
-- exit(1);
-- }
++ exit(1);
++ }
- if (a1 > 255 || a2 > 255 || a3 > 255 || a3 > 255) {
+ if (a1 > 255 || a2 > 255 || a3 > 255 || a4 > 255) {
SAYF("Malformed IPv4 address.");
-- exit(1);
-- }
++ exit(1);
++ }
ret[0] = a1;
ret[1] = a2;
exit(1);
}
-
- if (sscanf((char*)str, "%x", &val) != 1 ||
- val > 65535) {
- SAYF("Malformed IPv6 address (bad octet value).");
- exit(1);
- }
+ if (*str == ':') { val = 0; }
+ else if (sscanf((char*)str, "%x", &val) != 1 || val > 65535) {
+ SAYF("Malformed IPv6 address (bad octet value).");
+ exit(1);
+ }
ret[seg * 2] = val >> 8;
ret[seg * 2 + 1] = val;
}
- if (seg != 8) {
- SAYF("Malformed IPv6 address (don't abbreviate).");
- exit(1);
- }
-
+ if (seg != 6) {
+ SAYF("Malformed IPv6 address (incorrect number of segments parsed)");
+ exit(1);
+ }
-
}