diff options
author | harti <harti@FreeBSD.org> | 2006-02-07 15:48:37 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2006-02-07 15:48:37 +0000 |
commit | d548c36029e34bef752ca1dee9ebf934815ff4c7 (patch) | |
tree | 3c4c21b7d9794b32fd1c3ca739efd76df2d9dbac /contrib/bsnmp/snmpd | |
parent | 89810658282acddb82032a6f1f3cfde2b7f5e036 (diff) | |
download | FreeBSD-src-d548c36029e34bef752ca1dee9ebf934815ff4c7.zip FreeBSD-src-d548c36029e34bef752ca1dee9ebf934815ff4c7.tar.gz |
Vendor patch: string_get_max() function to return strings with a maximum
SNMP string length.
Diffstat (limited to 'contrib/bsnmp/snmpd')
-rw-r--r-- | contrib/bsnmp/snmpd/export.c | 24 | ||||
-rw-r--r-- | contrib/bsnmp/snmpd/snmpmod.h | 1 |
2 files changed, 25 insertions, 0 deletions
diff --git a/contrib/bsnmp/snmpd/export.c b/contrib/bsnmp/snmpd/export.c index b4cb9a8..52205e7 100644 --- a/contrib/bsnmp/snmpd/export.c +++ b/contrib/bsnmp/snmpd/export.c @@ -121,6 +121,30 @@ string_get(struct snmp_value *value, const u_char *ptr, ssize_t len) } /* + * Get a string value for a response packet but cut it if it is too long. + */ +int +string_get_max(struct snmp_value *value, const u_char *ptr, ssize_t len, + size_t maxlen) +{ + + if (ptr == NULL) { + value->v.octetstring.len = 0; + value->v.octetstring.octets = NULL; + return (SNMP_ERR_NOERROR); + } + if (len == -1) + len = strlen(ptr); + if ((size_t)len > maxlen) + len = maxlen; + value->v.octetstring.len = (u_long)len; + if ((value->v.octetstring.octets = malloc((size_t)len)) == NULL) + return (SNMP_ERR_RES_UNAVAIL); + memcpy(value->v.octetstring.octets, ptr, (size_t)len); + return (SNMP_ERR_NOERROR); +} + +/* * Support for IPADDRESS * * Save the old IP address in scratch->int1 and set the new one. diff --git a/contrib/bsnmp/snmpd/snmpmod.h b/contrib/bsnmp/snmpd/snmpmod.h index 4ce502c..18457bf 100644 --- a/contrib/bsnmp/snmpd/snmpmod.h +++ b/contrib/bsnmp/snmpd/snmpmod.h @@ -400,6 +400,7 @@ int string_save(struct snmp_value *, struct snmp_context *, ssize_t, u_char **); void string_commit(struct snmp_context *); void string_rollback(struct snmp_context *, u_char **); int string_get(struct snmp_value *, const u_char *, ssize_t); +int string_get_max(struct snmp_value *, const u_char *, ssize_t, size_t); void string_free(struct snmp_context *); int ip_save(struct snmp_value *, struct snmp_context *, u_char *); |