socsvn commit: r271776 - soc2014/shonali/head/contrib/bsnmp/snmpd
shonali at FreeBSD.org
shonali at FreeBSD.org
Sun Aug 3 07:18:46 UTC 2014
Author: shonali
Date: Sun Aug 3 07:18:45 2014
New Revision: 271776
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271776
Log:
Added separate calls for ipv4 and ipv6 for ip_XXX functions.
Modified:
soc2014/shonali/head/contrib/bsnmp/snmpd/export.c
Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/export.c
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Sun Aug 3 05:53:53 2014 (r271775)
+++ soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Sun Aug 3 07:18:45 2014 (r271776)
@@ -148,84 +148,59 @@
/*
* Support for IPADDRESS
*
- * Save the old IP address in scratch->int1 and set the new one.
+ * Save the old IPv4 address in scratch->int1 and set the new one.
*/
int
ip_save(struct snmp_value *value, struct snmp_context *ctx, u_char *valp)
-{
- /* XX - sizeof of a pointer to an array doesn't give you size of array
- Need to find a fix to this or a new way of finding address type */
-
- if (sizeof(*valp)== 4) {
- ctx->scratch->int1 = (valp[0] << 24) | (valp[1] << 16) | (valp[2] << 8)
- | valp[3];
-
- valp[0] = value->v.ipaddress[0];
- valp[1] = value->v.ipaddress[1];
- valp[2] = value->v.ipaddress[2];
- valp[3] = value->v.ipaddress[3];
- }
-
- if (sizeof(*valp)== 16) {
- ctx->scratch->int1 = (valp[0] << 120) | (valp[1] << 112) | (valp[2] << 104) | (valp[3] << 96) | (valp[4] << 88) |
- (valp[5] << 80) | (valp[6] << 72) | (valp[7] << 64) | (valp[8] << 56) | (valp[9] << 48) | (valp[10] << 40) |
- (valp[11] << 32) | (valp[12] << 24) | (valp[13] << 16) | (valp[14] << 8) | valp[15];
-
- valp[0] = value->v.ipaddress6[0];
- valp[1] = value->v.ipaddress6[1];
- valp[2] = value->v.ipaddress6[2];
- valp[3] = value->v.ipaddress6[3];
- valp[4] = value->v.ipaddress6[4];
- valp[5] = value->v.ipaddress6[5];
- valp[6] = value->v.ipaddress6[6];
- valp[7] = value->v.ipaddress6[7];
- valp[8] = value->v.ipaddress6[8];
- valp[9] = value->v.ipaddress6[9];
- valp[10] = value->v.ipaddress6[10];
- valp[11] = value->v.ipaddress6[11];
- valp[12] = value->v.ipaddress6[12];
- valp[13] = value->v.ipaddress6[13];
- valp[14] = value->v.ipaddress6[14];
- valp[15] = value->v.ipaddress6[15];
+{
+ ctx->scratch->int1 = (valp[0] << 24) | (valp[1] << 16) | (valp[2] << 8)
+ | valp[3];
- }
+ valp[0] = value->v.ipaddress[0];
+ valp[1] = value->v.ipaddress[1];
+ valp[2] = value->v.ipaddress[2];
+ valp[3] = value->v.ipaddress[3];
+
- return (0);
+ return (0);
+}
+
+/*
+ * Support for IPADDRESS
+ *
+ * Save the old IPv6 address in scratch->int1 and set the new one.
+ */
+int
+ip6_save(struct snmp_value *value, struct snmp_context *ctx, u_char *valp)
+{
+ if ((ctx->scratch->ptr1 = malloc(sizeof(u_int8_t)*16)) == NULL)
+ return (SNMP_ERR_RES_UNAVAIL);
+ ctx->scratch->ptr1 = *valp;
+ for (int i = 0; i < 16; i++)
+ valp[i] = value->v.ipaddress6[i];
+ return (0);
}
/*
- * Rollback the address by copying back the old one
+ * Rollback the IPv4 address by copying back the old one
*/
void
ip_rollback(struct snmp_context *ctx, u_char *valp)
-{
- /* XX - sizeof of a pointer to an array doesn't give you size of array
- Need to find a fix to this or a new way of finding address type */
-
- if (sizeof(*valp)== 4) {
- valp[0] = ctx->scratch->int1 >> 24;
- valp[1] = ctx->scratch->int1 >> 16;
- valp[2] = ctx->scratch->int1 >> 8;
- valp[3] = ctx->scratch->int1;
- }
- if (sizeof(*valp)== 16) {
- valp[0] = ctx->scratch->int1 >> 120;
- valp[1] = ctx->scratch->int1 >> 112;
- valp[2] = ctx->scratch->int1 >> 104;
- valp[3] = ctx->scratch->int1 >> 96;
- valp[4] = ctx->scratch->int1 >> 88;
- valp[5] = ctx->scratch->int1 >> 80;
- valp[6] = ctx->scratch->int1 >> 72;
- valp[7] = ctx->scratch->int1 >> 64;
- valp[8] = ctx->scratch->int1 >> 56;
- valp[9] = ctx->scratch->int1 >> 48;
- valp[10] = ctx->scratch->int1 >> 40;
- valp[11] = ctx->scratch->int1 >> 32;
- valp[12] = ctx->scratch->int1 >> 24;
- valp[13] = ctx->scratch->int1 >> 16;
- valp[14] = ctx->scratch->int1 >> 8;
- valp[15] = ctx->scratch->int1 >> 0;
- }
+{
+
+ valp[0] = ctx->scratch->int1 >> 24;
+ valp[1] = ctx->scratch->int1 >> 16;
+ valp[2] = ctx->scratch->int1 >> 8;
+ valp[3] = ctx->scratch->int1;
+}
+
+/*
+ * Rollback the IPv6 address by copying back the old one
+ */
+void
+ip6_rollback(struct snmp_context *ctx, u_char *valp)
+{
+ *valp = (u_char)ctx->scratch->ptr1;
}
/*
@@ -237,43 +212,33 @@
}
/*
- * Retrieve an IP address
+ * Retrieve an IPv4 address
*/
int
ip_get(struct snmp_value *value, u_char *valp)
{
- /* XX - sizeof of a pointer to an array doesn't give you size of array
- Need to find a fix to this or a new way of finding address type */
+ value->v.ipaddress[0] = valp[0];
+ value->v.ipaddress[1] = valp[1];
+ value->v.ipaddress[2] = valp[2];
+ value->v.ipaddress[3] = valp[3];
+
- if (sizeof(*valp)== 4) {
- value->v.ipaddress[0] = valp[0];
- value->v.ipaddress[1] = valp[1];
- value->v.ipaddress[2] = valp[2];
- value->v.ipaddress[3] = valp[3];
- }
-
- if (sizeof(*valp)== 16) {
- value->v.ipaddress6[0] = valp[0];
- value->v.ipaddress6[1] = valp[1];
- value->v.ipaddress6[2] = valp[2];
- value->v.ipaddress6[3] = valp[3];
- value->v.ipaddress6[4] = valp[4];
- value->v.ipaddress6[5] = valp[5];
- value->v.ipaddress6[6] = valp[6];
- value->v.ipaddress6[7] = valp[7];
- value->v.ipaddress6[8] = valp[8];
- value->v.ipaddress6[9] = valp[9];
- value->v.ipaddress6[10] = valp[10];
- value->v.ipaddress6[11] = valp[11];
- value->v.ipaddress6[12] = valp[12];
- value->v.ipaddress6[13] = valp[13];
- value->v.ipaddress6[14] = valp[14];
- value->v.ipaddress6[15] = valp[15];
+ return (SNMP_ERR_NOERROR);
+}
- }
- return (SNMP_ERR_NOERROR);
+/*
+ * Retrieve an IPv6 address
+ */
+int
+ip6_get(struct snmp_value *value, u_char *valp)
+{
+ for (int i = 0; i < 16; i++){
+ value->v.ipaddress6[i] = valp[i];
+ }
+ return (SNMP_ERR_NOERROR);
}
+
/*
* Object ID support
*
@@ -389,8 +354,7 @@
}
case SNMP_SYNTAX_IPADDRESS:
- {
- u_int8_t *pval;
+ { u_int8_t *pval;
u_int i;
switch (oid->len) {
@@ -398,7 +362,7 @@
case 4: if (sub + 4 > oid->len)
goto err;
//pval = va_arg(ap, u_int8_t *);
- u_int8_t pval[4];
+ pval = malloc(sizeof(u_int8_t)*4);
for (i = 0; i < 4; i++) {
if (oid->subs[sub] > 0xff)
goto err;
@@ -408,7 +372,7 @@
case 16: if (sub + 16 > oid->len)
goto err;
//pval = va_arg(ap, u_int8_t *);
- u_int8_t pval[16];
+ pval = malloc(sizeof(u_int8_t)*16);
for (i = 0; i < 16; i++) {
pval[i] = oid->subs[sub++];
}
More information about the svn-soc-all
mailing list