Date: Tue, 29 Jul 2014 17:17:58 GMT From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271540 - soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools Message-ID: <201407291717.s6THHwB8078521@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: shonali Date: Tue Jul 29 17:17:58 2014 New Revision: 271540 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271540 Log: Added code to support ipv6 in bsnmpget.c. Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c Tue Jul 29 17:14:13 2014 (r271539) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c Tue Jul 29 17:17:58 2014 (r271540) @@ -608,16 +608,33 @@ char *endptr, *str; str = val; - for (i = 0; i < 4; i++) { - v = strtoul(str, &endptr, 10); - if (v > 0xff) - return (-1); - if (*endptr != '.' && *endptr != '\0' && i != 3) - break; - str = endptr + 1; - value->v.ipaddress[i] = (uint8_t) v; - } + + switch (sizeof(*addrs)) { + case 4: + for (i = 0; i < 4; i++) { + v = strtoul(str, &endptr, 10); + if (v > 0xff) + return (-1); + if (*endptr != '.' && *endptr != '\0' && i != 3) + break; + str = endptr + 1; + value->v.ipaddress[i] = (uint8_t) v; + } + case 16: + for (i = 0; i < 16; i++) { + v = strtoul(str, &endptr, 16); + if (v > 0xff) + return (-1); + if (*endptr != ':' && *endptr != '\0' && i != 15) + break; + str = endptr + 1; + value->v.ipaddress[i] = (uint8_t) v; + } + + default: + return (NULL); + } value->syntax = SNMP_SYNTAX_IPADDRESS; return (0); } @@ -946,9 +963,18 @@ int8_t i; dst->syntax = SNMP_SYNTAX_IPADDRESS; - for (i = 0; i < 4; i++) - dst->v.ipaddress[i] = src->v.ipaddress[i]; + + switch (sizeof(src->v.ipaddress)) { + case 4: + for (i = 0; i < 4; i++) + dst->v.ipaddress[i] = src->v.ipaddress[i]; + case 16: + for (i = 0; i < 16; i++) + dst->v.ipaddress[i] = src->v.ipaddress[i]; + default: + return (NULL); + } return (1); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407291717.s6THHwB8078521>