From owner-svn-soc-all@FreeBSD.ORG Sun Aug 3 13:50:06 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 230389C1 for ; Sun, 3 Aug 2014 13:50:06 +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 0F971206C for ; Sun, 3 Aug 2014 13:50:06 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s73Do5fB060763 for ; Sun, 3 Aug 2014 13:50:05 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s73Do5LR060761 for svn-soc-all@FreeBSD.org; Sun, 3 Aug 2014 13:50:05 GMT (envelope-from shonali@FreeBSD.org) Date: Sun, 3 Aug 2014 13:50:05 GMT Message-Id: <201408031350.s73Do5LR060761@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: r271793 - 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: Sun, 03 Aug 2014 13:50:06 -0000 Author: shonali Date: Sun Aug 3 13:50:05 2014 New Revision: 271793 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271793 Log: Added separate calls for ipv6 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 Sun Aug 3 12:19:45 2014 (r271792) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sun Aug 3 13:50:05 2014 (r271793) @@ -1092,43 +1092,46 @@ static char * snmp_ip2asn_oid(char *str, struct asn_oid *oid) { - uint32_t v; - int32_t i; - char *endptr, *ptr; + uint32_t v; + int32_t i; + 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; + } + return (endptr); +} - ptr = str; - - switch (sizeof(*str)) { +static char * +snmp_ipv62asn_oid(char *str, struct asn_oid *oid) +{ + uint32_t v; + int32_t i; + char *endptr, *ptr; - 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); + ptr = str; + + for (i = 0; i < 16; i++) { + v = strtoul(ptr, &endptr, 16); + 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; + } + return (endptr); } + /* 32-bit counter, gauge, timeticks. */ static char * snmp_uint2asn_oid(char *str, struct asn_oid *oid) @@ -1756,18 +1759,18 @@ static void snmp_output_ipaddress(struct snmp_toolinfo *snmptoolctx, uint8_t *ip) { - if (GET_OUTPUT(snmptoolctx) == OUTPUT_VERBOSE) - fprintf(stdout, "%s : ", - syntax_strings[SNMP_SYNTAX_IPADDRESS].str); + 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 +snmp_output_ip6address(struct snmp_toolinfo *snmptoolctx, uint8_t *ip) +{ + if (GET_OUTPUT(snmptoolctx) == OUTPUT_VERBOSE) + fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IPADDRESS].str); + 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]); } static void @@ -1958,16 +1961,16 @@ case SNMP_SYNTAX_IPADDRESS: if (temp.len < 4) return (-1); - - switch (sizeof(temp.len)) { + uint8_t *ip; + switch (temp.len) { case 4: - uint8_t ip[4]; - for (bytes = 0; bytes < 4; bytes++) + ip = malloc(sizeof(u_int8_t)*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]; + ip = malloc(sizeof(u_int8_t)*16); for (bytes = 0; bytes < 16; bytes++) ip[bytes] = temp.subs[bytes]; snmp_output_ipaddress(snmptoolctx, ip);