|
|
#include <snmp/snmp.h> #include <snmp/snmpuser.h>void free_octetstring(os_ptr) OctetString *os_ptr;
OctetString * make_octet_from_hex(hex_string) u_char *hex_string; /* Hex to be converted to an octet string */
OctetString * make_octetstring(in_string, length) u_char *in_string; /*The octetstring's value - byte string*/ long length; /*length of the byte string*/
OctetString * make_octet_from_text(text_string) u_char *text_string; /* Text to be converted to an octet string */
short print_ascii(octet_ptr) OctetString *octet_ptr; /* pointer to octet string to display */
void print_octet_string_out(octet_ptr, wrap) OctetString *octet_ptr; /* pointer to octet string to display */ short wrap; /* number of bytes to display per line */
make_octet_from_hex converts a hex text string into a library format OctetString data structure for use by calls to make_varbind(SLIB) and make_authentication(SLIB). The format of these text strings is a hex value (1 or more hex digits, upper or lower case) followed by a space, with more hex values and spaces to complete the string. For example, to create an octet string of length two with a hex 15 in the first octet and a hex 3D in the second octet, the text string could be ``15 3d'' or ``0x15 0x3D''. The OctetString construct returned by this call can be freed by a call to free_octetstring. Usually, this is unnecessary as the construct is most often passed to another library routine for inclusion in a larger ASN.1 construct, and that library's free counterpart will perform the memory recovery. (For example, if the OctetString construct is passed to make_oid, it should be freed with free_oid.)
make_octetstring produces a library OctetString construct from an input byte string and length. This construct is usually passed to other library calls, such as make_varbind(SLIB) or make_authentication(SLIB), and linked into a larger library construct of an ASN.1 entity. free_octetstring recovers all memory malloc'ed by make_octetstring, but should not be used if the octetstring is passed to another library routine, such as make_varbind. In such a situation, the free counterpart of the routine to which the octetstring is passed, for example free_varbind_list, frees all memory that has been linked to the higher level ASN.1 structure.
make_octet_from_text is used to create a library format octet string data structure for use by calls to make_varbind(SLIB) and make_authentication(SLIB) from text strings.
If an OctetString's value contains only printable characters, print_ascii prints out the value's contents as an ASCII string. It is called with a pointer to the OctetString construct and checks if the string is printable. If it isn't printable, print_ascii returns a -1 value; otherwise, it returns a 1.
print_octet_string_out prints out the contents of an OctetString's value in hex. It is called with a pointer to the OctetString construct and the number of bytes to display on one line (the variable wrap). This call is used by the print_varbind routine to actually print out octet string values.