Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Aug 2014 18:39:01 GMT
From:      shonali@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r272224 - in soc2014/shonali/head: contrib/bsnmp/snmpd usr.sbin/bsnmpd/tools/libbsnmptools
Message-ID:  <201408111839.s7BId1BP032404@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: shonali
Date: Mon Aug 11 18:39:00 2014
New Revision: 272224
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272224

Log:
  Added switch case SNMP_SYNTAX_IP6ADDRESS and calls to ipv6 functions in config.c & export.c
  

Modified:
  soc2014/shonali/head/contrib/bsnmp/snmpd/config.c
  soc2014/shonali/head/contrib/bsnmp/snmpd/export.c
  soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c

Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/config.c
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmpd/config.c	Mon Aug 11 17:45:41 2014	(r272223)
+++ soc2014/shonali/head/contrib/bsnmp/snmpd/config.c	Mon Aug 11 18:39:00 2014	(r272224)
@@ -801,41 +801,12 @@
                 	sain = (struct sockaddr_in *)(void *)res->ai_addr;
                 	sain->sin_addr.s_addr = ntohl(sain->sin_addr.s_addr); 
 	                inet_ntop(AF_INET, &(sain->sin_addr), *ip, INET_ADDRSTRLEN); 
-                        
-                        /*
-                        ip[0] = sain->sin_addr.s_addr >> 24;
-                	ip[1] = sain->sin_addr.s_addr >> 16;
-                        ip[2] = sain->sin_addr.s_addr >>  8;
-        		ip[3] = sain->sin_addr.s_addr >>  0;
-                        */ 
-                        
                         break;
 
                 case AF_INET6 :
                         addr_type = AF_INET6;
                 	sain6 = (struct sockaddr_in6 *)(void *)res->ai_addr;
- 
-                	/* ipv6 implementation of network to host byte order function */
-                	/*  
-                        unsigned char tmp[16];
-                	if (BYTE_ORDER == LITTLE_ENDIAN) {
-                		tmp[3] = (sain6->sin6_addr.s6_addr[0] << 24) | (sain6->sin6_addr.s6_addr[1] << 16) | (sain6->sin6_addr.s6_addr[2] << 8) | sain6->sin6_addr.s6_addr[3];
-                		tmp[2] = (sain6->sin6_addr.s6_addr[4] << 24) | (sain6->sin6_addr.s6_addr[5] << 16) | (sain6->sin6_addr.s6_addr[6] << 8) | sain6->sin6_addr.s6_addr[7];
-                		tmp[1] = (sain6->sin6_addr.s6_addr[8] << 24) | (sain6->sin6_addr.s6_addr[9] << 16) | (sain6->sin6_addr.s6_addr[10] << 8) | sain6->sin6_addr.s6_addr[11];
-                		tmp[0] = (sain6->sin6_addr.s6_addr[12] << 24) | (sain6->sin6_addr.s6_addr[13] << 16) | (sain6->sin6_addr.s6_addr[14] << 8) | sain6->sin6_addr.s6_addr[15];
-                	}
-
-                	else {
-                		tmp[0] = (sain6->sin6_addr.s6_addr[0] << 24) | (sain6->sin6_addr.s6_addr[1] << 16) | (sain6->sin6_addr.s6_addr[2] << 8) | sain6->sin6_addr.s6_addr[3];
-                		tmp[1] = (sain6->sin6_addr.s6_addr[4] << 24) | (sain6->sin6_addr.s6_addr[5] << 16) | (sain6->sin6_addr.s6_addr[6] << 8) | sain6->sin6_addr.s6_addr[7];
-                		tmp[2] = (sain6->sin6_addr.s6_addr[8] << 24) | (sain6->sin6_addr.s6_addr[9] << 16) | (sain6->sin6_addr.s6_addr[10] << 8) | sain6->sin6_addr.s6_addr[11];
-                		tmp[3] = (sain6->sin6_addr.s6_addr[12] << 24) | (sain6->sin6_addr.s6_addr[13] << 16) | (sain6->sin6_addr.s6_addr[14] << 8) | sain6->sin6_addr.s6_addr[15];
-                	}
-                	strcpy(sain6->sin6_addr.s6_addr, (unsigned char *)tmp) ; 
-                        */ 
-	
                         inet_ntop(AF_INET6, &(sain6->sin6_addr), *ip, INET6_ADDRSTRLEN);
-
         }
  
 	freeaddrinfo(res);
@@ -1025,56 +996,61 @@
 parse_syntax_ipaddress(struct snmp_value *value)
 {
 	int i;
+	u_char ip[4];
+
+	if (token == TOK_NUM) {
+		/* numerical address */
+		i = 0;
+		for (;;) {
+			if (numval >= 256)
+				report("ip address part too large");
+			value->v.ipaddress[i++] = numval;
+			if (i == 4)
+				break;
+			if (gettoken() != '.')
+				report("expecting '.' in ip address");
+		}
+		gettoken();
+
+	} else if (token == TOK_HOST) {
+		/* host name */
+		gethost(strval, ip);
+		for (i = 0; i < 4; i++)
+			value->v.ipaddress[i] = ip[i];
+		gettoken();
+
+	} else
+		report("bad ip address syntax");
+}
+
+static void
+parse_syntax_ip6address(struct snmp_value *value)
+{
+	int i;
 	u_char ip[16];
- 
+
 	if (token == TOK_NUM) {
 		/* numerical address */
 		i = 0;
 		for (;;) {
-                        if (!isxdigit(numval)) {
-				if (numval >= 256)
-					report("ip address part too large");
-				value->v.ipaddress[i++] = numval;
-	        		if (i == 4)
-					break;
-				if (gettoken() != '.')
-					report("expecting '.' in ip address");
-                       	}
-
-                       	else {
-                        	value->v.ipaddress[i++] = numval;
-                        	if (i == 16)
-                                	break;
-                        	if (gettoken() != ':')
-                                	report("expecting ':' in ip address");
- 	                }
-                        
+			value->v.ipaddress6[i++] = numval;
+			if (i == 16)
+				break;
+			if (gettoken() != ':')
+				report("expecting ':' in ip address");
 		}
 		gettoken();
-                if (i == 4) {
-                	struct in_addr dst;
-                	if (!inet_pton(AF_INET,value->v.ipaddress[i++],(void *)&dst))
-                  		report("ip address not valid");
-                }
-                else if (i == 16) {
-                	struct in6_addr dst;
-                	if (!inet_pton(AF_INET6,value->v.ipaddress[i++],(void *)&dst))
-                  		report("ipv6 address not valid"); 
-                }
+		
+		struct in6_addr dst;
+		if (!inet_pton(AF_INET6, value->v.ipaddress6[i++],(void *)&dst))
+				report("ipv6 address not valid");
 
 	} else if (token == TOK_HOST) {
 		/* host name */
 		gethost(strval, ip);
-                if (addr_type == AF_INET){
-			for (i = 0; i < 4; i++)
-				value->v.ipaddress[i] = ip[i];
-			gettoken();
-                }
-                if (addr_type == AF_INET6){
-                	for (i = 0; i < 16; i++)
-                        	value->v.ipaddress[i] = ip[i];
-                        gettoken();
-                } 
+		for (i = 0; i < 16; i++)
+			value->v.ipaddress6[i] = ip[i];
+		gettoken();
 
 	} else
 		report("bad ip address syntax");
@@ -1142,6 +1118,10 @@
 		parse_syntax_ipaddress(&value);
 		break;
 
+	  case SNMP_SYNTAX_IP6ADDRESS:
+		parse_syntax_ip6address(&value);
+		break;
+
 	  case SNMP_SYNTAX_COUNTER:
 	  case SNMP_SYNTAX_GAUGE:
 	  case SNMP_SYNTAX_TIMETICKS:

Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/export.c
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmpd/export.c	Mon Aug 11 17:45:41 2014	(r272223)
+++ soc2014/shonali/head/contrib/bsnmp/snmpd/export.c	Mon Aug 11 18:39:00 2014	(r272224)
@@ -363,34 +363,28 @@
 		    {   
 			u_int8_t *pval; 
 			u_int i;
-                        
-                     	switch (oid->len) {
-                
-                		case SNMP_IPv4_ADDR_SIZ: 
-					if (sub + SNMP_IPv4_ADDR_SIZ > oid->len)
-                               			goto err;
-                        		pval = va_arg(ap, u_int8_t *);
-					for (i = 0; i < 4; i++) {
-						if (oid->subs[sub] > 0xff)
-							goto err;
-						pval[i] = oid->subs[sub++];
-					}
-						
-				case SNMP_IPv6_ADDR_SIZ: 
-					if (sub + SNMP_IPv6_ADDR_SIZ > oid->len)
-						goto err;
-					pval = va_arg(ap, u_int8_t *);
-					for (i = 0; i < 16; i++) {
-						pval[i] = oid->subs[sub++];
-					}
-						
-				default:
-                        		return (NULL);
-        		}
-
+			if (sub + SNMP_IPv4_ADDR_SIZ > oid->len)
+				goto err;
+			pval = va_arg(ap, u_int8_t *);
+			for (i = 0; i < 4; i++) {
+				if (oid->subs[sub] > 0xff)
+					goto err;
+				pval[i] = oid->subs[sub++];
+			}
+			break;
+		    }
+                  case SNMP_SYNTAX_IP6ADDRESS:
+		    {
+			u_int8_t *pval;
+			u_int i;
+			if (sub + SNMP_IPv6_ADDR_SIZ > oid->len)
+				goto err;
+			pval = va_arg(ap, u_int8_t *);
+			for (i = 0; i < 16; i++) {
+				pval[i] = oid->subs[sub++];
+			}
 			break;
 		    }
-
 		  case SNMP_SYNTAX_COUNTER:
 		  case SNMP_SYNTAX_GAUGE:
 		  case SNMP_SYNTAX_TIMETICKS:

Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c
==============================================================================
--- soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c	Mon Aug 11 17:45:41 2014	(r272223)
+++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c	Mon Aug 11 18:39:00 2014	(r272224)
@@ -1763,8 +1763,9 @@
 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);	
-		fprintf(stdout, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
+		fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IPADDRESS].str);
+	
+	fprintf(stdout, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
         
 }
 
@@ -1772,10 +1773,11 @@
 snmp_output_ip6address(struct snmp_toolinfo *snmptoolctx, uint8_t *ip)
 {
         if (GET_OUTPUT(snmptoolctx) == OUTPUT_VERBOSE)
-                fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IP6ADDRESS].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]);
+                fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IP6ADDRESS].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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408111839.s7BId1BP032404>