Vendor patch: string_get_max() function to return strings with a maximum

SNMP string length.
This commit is contained in:
harti 2006-02-07 15:48:37 +00:00
parent 8981065828
commit d548c36029
2 changed files with 25 additions and 0 deletions

View File

@ -120,6 +120,30 @@ string_get(struct snmp_value *value, const u_char *ptr, ssize_t len)
return (SNMP_ERR_NOERROR);
}
/*
* 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
*

View File

@ -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 *);