Date: Tue, 29 Jul 2014 17:18:46 GMT From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271541 - soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools Message-ID: <201407291718.s6THIkpM078820@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: shonali Date: Tue Jul 29 17:18:46 2014 New Revision: 271541 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271541 Log: Added code to support ipv6 code in bsnmptools.c Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Tue Jul 29 17:17:58 2014 (r271540) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Tue Jul 29 17:18:46 2014 (r271541) @@ -1097,17 +1097,35 @@ char *endptr, *ptr; ptr = str; - for (i = 0; i < 4; i++) { - v = strtoul(ptr, &endptr, 10); - if (v > 0xff) - return (NULL); - if (*endptr != '.' && strchr("],\0", *endptr) == NULL && i != 3) - return (NULL); - if (snmp_suboid_append(oid, (asn_subid_t) v) < 0) - return (NULL); - ptr = endptr + 1; - } + + switch (sizeof(*str)) { + case 4: + for (i = 0; i < 4; i++) { + v = strtoul(ptr, &endptr, 10); + if (v > 0xff) + return (NULL); + if (*endptr != '.' && strchr("],\0", *endptr) == NULL && i != 3) + return (NULL); + if (snmp_suboid_append(oid, (asn_subid_t) v) < 0) + return (NULL); + ptr = endptr + 1; + } + case 16: + for (i = 0; i < 16; i++) { + v = strtoul(ptr, &endptr, 16); + if (v > 0xff) + return (NULL); + if (*endptr != ':' && strchr("],\0", *endptr) == NULL && i != 15) + return (NULL); + if (snmp_suboid_append(oid, (asn_subid_t) v) < 0) + return (NULL); + ptr = endptr + 1; + } + + default: + return (NULL); + } return (endptr); } @@ -1741,8 +1759,15 @@ if (GET_OUTPUT(snmptoolctx) == OUTPUT_VERBOSE) fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IPADDRESS].str); - - fprintf(stdout, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); + + switch (sizeof(*ip)) { + case 4: + fprintf(stdout, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); + case 16: + fprintf(stdout, "%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip[8], ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15]); + default: + return (NULL); + } } static void @@ -1896,7 +1921,6 @@ snmp_output_index(struct snmp_toolinfo *snmptoolctx, struct index *stx, struct asn_oid *oid) { - uint8_t ip[4]; uint32_t bytes = 1; uint64_t cnt64; struct asn_oid temp, out; @@ -1934,11 +1958,24 @@ case SNMP_SYNTAX_IPADDRESS: if (temp.len < 4) return (-1); - for (bytes = 0; bytes < 4; bytes++) - ip[bytes] = temp.subs[bytes]; - - snmp_output_ipaddress(snmptoolctx, ip); - bytes = 4; + + switch (sizeof(temp.len)) { + case 4: + uint8_t ip[4]; + for (bytes = 0; bytes < 4; bytes++) + ip[bytes] = temp.subs[bytes]; + snmp_output_ipaddress(snmptoolctx, ip); + bytes = 4; + case 16: + uint8_t ip[16]; + for (bytes = 0; bytes < 16; bytes++) + ip[bytes] = temp.subs[bytes]; + snmp_output_ipaddress(snmptoolctx, ip); + bytes = 16; + + default: + return (NULL); + } break; case SNMP_SYNTAX_COUNTER:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407291718.s6THIkpM078820>