📄 mib.c
字号:
*out_len += strlen((char *) (*buf + *out_len)); if (units) { return (snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) " ") && snmp_strcat(buf, buf_len, out_len, allow_realloc, (const u_char *) units)); } return 1;}/** * Prints a double into a buffer. * * The variable var is encoded as a double precision floating point value. * * If allow_realloc is true the buffer will be (re)allocated to fit in the * needed size. (Note: *buf may change due to this.) * * @param buf Address of the buffer to print to. * @param buf_len Address to an integer containing the size of buf. * @param out_len Incremented by the number of characters printed. * @param allow_realloc if not zero reallocate the buffer to fit the * needed size. * @param var The variable to encode. * @param enums The enumeration ff this variable is enumerated. may be NULL. * @param hint Contents of the DISPLAY-HINT clause of the MIB. * See RFC 1903 Section 3.1 for details. may be NULL. * @param units Contents of the UNITS clause of the MIB. may be NULL. * * @return 1 on success, or 0 on failure (out of memory, or buffer to * small when not allowed to realloc.) */intsprint_realloc_double(u_char ** buf, size_t * buf_len, size_t * out_len, int allow_realloc, netsnmp_variable_list * var, struct enum_list *enums, const char *hint, const char *units){ if ((var->type != ASN_OPAQUE_DOUBLE) && (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) { const char str[] = "Wrong Type (should be Double): "; if (snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) str)) { return sprint_realloc_by_type(buf, buf_len, out_len, allow_realloc, var, NULL, NULL, NULL); } else { return 0; } } if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) { if (!snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) "Opaque: Float: ")) { return 0; } } /* * How much space needed for max. length double? 128 is overkill. */ while ((*out_len + 128 + 1) >= *buf_len) { if (!(allow_realloc && snmp_realloc(buf, buf_len))) { return 0; } } sprintf((char *) (*buf + *out_len), "%f", *var->val.doubleVal); *out_len += strlen((char *) (*buf + *out_len)); if (units) { return (snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) " ") && snmp_strcat(buf, buf_len, out_len, allow_realloc, (const u_char *) units)); } return 1;}#endif /* OPAQUE_SPECIAL_TYPES *//** * Prints a counter into a buffer. * * The variable var is encoded as a counter value. * * If allow_realloc is true the buffer will be (re)allocated to fit in the * needed size. (Note: *buf may change due to this.) * * @param buf Address of the buffer to print to. * @param buf_len Address to an integer containing the size of buf. * @param out_len Incremented by the number of characters printed. * @param allow_realloc if not zero reallocate the buffer to fit the * needed size. * @param var The variable to encode. * @param enums The enumeration ff this variable is enumerated. may be NULL. * @param hint Contents of the DISPLAY-HINT clause of the MIB. * See RFC 1903 Section 3.1 for details. may be NULL. * @param units Contents of the UNITS clause of the MIB. may be NULL. * * @return 1 on success, or 0 on failure (out of memory, or buffer to * small when not allowed to realloc.) */intsprint_realloc_counter64(u_char ** buf, size_t * buf_len, size_t * out_len, int allow_realloc, netsnmp_variable_list * var, struct enum_list *enums, const char *hint, const char *units){ char a64buf[I64CHARSZ + 1]; if ((var->type != ASN_COUNTER64#ifdef OPAQUE_SPECIAL_TYPES && var->type != ASN_OPAQUE_COUNTER64 && var->type != ASN_OPAQUE_I64 && var->type != ASN_OPAQUE_U64#endif ) && (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) { u_char str[] = "Wrong Type (should be Counter64): "; if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) { return sprint_realloc_by_type(buf, buf_len, out_len, allow_realloc, var, NULL, NULL, NULL); } else { return 0; } } if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {#ifdef OPAQUE_SPECIAL_TYPES if (var->type != ASN_COUNTER64) { if (!snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) "Opaque: ")) { return 0; } }#endif#ifdef OPAQUE_SPECIAL_TYPES switch (var->type) { case ASN_OPAQUE_U64: if (!snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) "UInt64: ")) { return 0; } break; case ASN_OPAQUE_I64: if (!snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) "Int64: ")) { return 0; } break; case ASN_COUNTER64: case ASN_OPAQUE_COUNTER64:#endif if (!snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) "Counter64: ")) { return 0; }#ifdef OPAQUE_SPECIAL_TYPES }#endif }#ifdef OPAQUE_SPECIAL_TYPES if (var->type == ASN_OPAQUE_I64) { printI64(a64buf, var->val.counter64); if (!snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) a64buf)) { return 0; } } else {#endif printU64(a64buf, var->val.counter64); if (!snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) a64buf)) { return 0; }#ifdef OPAQUE_SPECIAL_TYPES }#endif if (units) { return (snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) " ") && snmp_strcat(buf, buf_len, out_len, allow_realloc, (const u_char *) units)); } return 1;}/** * Prints an object identifier into a buffer. * * If allow_realloc is true the buffer will be (re)allocated to fit in the * needed size. (Note: *buf may change due to this.) * * @param buf Address of the buffer to print to. * @param buf_len Address to an integer containing the size of buf. * @param out_len Incremented by the number of characters printed. * @param allow_realloc if not zero reallocate the buffer to fit the * needed size. * @param var The variable to encode. * @param enums The enumeration ff this variable is enumerated. may be NULL. * @param hint Contents of the DISPLAY-HINT clause of the MIB. * See RFC 1903 Section 3.1 for details. may be NULL. * @param units Contents of the UNITS clause of the MIB. may be NULL. * * @return 1 on success, or 0 on failure (out of memory, or buffer to * small when not allowed to realloc.) */intsprint_realloc_opaque(u_char ** buf, size_t * buf_len, size_t * out_len, int allow_realloc, netsnmp_variable_list * var, struct enum_list *enums, const char *hint, const char *units){ if ((var->type != ASN_OPAQUE#ifdef OPAQUE_SPECIAL_TYPES && var->type != ASN_OPAQUE_COUNTER64 && var->type != ASN_OPAQUE_U64 && var->type != ASN_OPAQUE_I64 && var->type != ASN_OPAQUE_FLOAT && var->type != ASN_OPAQUE_DOUBLE#endif /* OPAQUE_SPECIAL_TYPES */ ) && (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) { u_char str[] = "Wrong Type (should be Opaque): "; if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) { return sprint_realloc_by_type(buf, buf_len, out_len, allow_realloc, var, NULL, NULL, NULL); } else { return 0; } }#ifdef OPAQUE_SPECIAL_TYPES switch (var->type) { case ASN_OPAQUE_COUNTER64: case ASN_OPAQUE_U64: case ASN_OPAQUE_I64: return sprint_realloc_counter64(buf, buf_len, out_len, allow_realloc, var, enums, hint, units); break; case ASN_OPAQUE_FLOAT: return sprint_realloc_float(buf, buf_len, out_len, allow_realloc, var, enums, hint, units); break; case ASN_OPAQUE_DOUBLE: return sprint_realloc_double(buf, buf_len, out_len, allow_realloc, var, enums, hint, units); break; case ASN_OPAQUE:#endif if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) { u_char str[] = "OPAQUE: "; if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) { return 0; } } if (!sprint_realloc_hexstring(buf, buf_len, out_len, allow_realloc, var->val.string, var->val_len)) { return 0; }#ifdef OPAQUE_SPECIAL_TYPES }#endif if (units) { return (snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) " ") && snmp_strcat(buf, buf_len, out_len, allow_realloc, (const u_char *) units)); } return 1;}/** * Prints an object identifier into a buffer. * * If allow_realloc is true the buffer will be (re)allocated to fit in the * needed size. (Note: *buf may change due to this.) * * @param buf Address of the buffer to print to. * @param buf_len Address to an integer containing the size of buf. * @param out_len Incremented by the number of characters printed. * @param allow_realloc if not zero reallocate the buffer to fit the * needed size. * @param var The variable to encode. * @param enums The enumeration ff this variable is enumerated. may be NULL. * @param hint Contents of the DISPLAY-HINT clause of the MIB. * See RFC 1903 Section 3.1 for details. may be NULL. * @param units Contents of the UNITS clause of the MIB. may be NULL. * * @return 1 on success, or 0 on failure (out of memory, or buffer to * small when not allowed to realloc.) */intsprint_realloc_object_identifier(u_char ** buf, size_t * buf_len, size_t * out_len, int allow_realloc, netsnmp_variable_list * var, struct enum_list *enums, const char *hint, const char *units){ int buf_overflow = 0; if ((var->type != ASN_OBJECT_ID) && (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) { u_char str[] = "Wrong Type (should be OBJECT IDENTIFIER): "; if (snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) { return sprint_realloc_by_type(buf, buf_len, out_len, allow_realloc, var, NULL, NULL, NULL); } else { return 0; } } if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) { u_char str[] = "OID: "; if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) { return 0; } } netsnmp_sprint_realloc_objid_tree(buf, buf_len, out_len, allow_realloc, &buf_overflow, (oid *) (var->val.objid), var->val_len / sizeof(oid)); if (buf_overflow) { return 0; } if (units) { return (snmp_strcat (buf, buf_len, out_len, allow_realloc, (const u_char *) " ") && snmp_strcat(buf, buf_len, out_len, allow_realloc, (const u_char *) units)); } return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -