From owner-svn-soc-all@FreeBSD.ORG Tue Jul 29 17:18:47 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E471CB6C for ; Tue, 29 Jul 2014 17:18:46 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D04892A43 for ; Tue, 29 Jul 2014 17:18:46 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s6THIkQk078823 for ; Tue, 29 Jul 2014 17:18:46 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s6THIkpM078820 for svn-soc-all@FreeBSD.org; Tue, 29 Jul 2014 17:18:46 GMT (envelope-from shonali@FreeBSD.org) Date: Tue, 29 Jul 2014 17:18:46 GMT Message-Id: <201407291718.s6THIkpM078820@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271541 - soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jul 2014 17:18:47 -0000 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: