⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mib.c

📁 snmp up 2
💻 C
📖 第 1 页 / 共 5 页
字号:
/** * Prints a timetick variable 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_timeticks(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            timebuf[32];    if ((var->type != ASN_TIMETICKS) &&         (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        u_char          str[] = "Wrong Type (should be Timeticks): ";        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_NUMERIC_TIMETICKS)) {        char            str[16];        sprintf(str, "%lu", *(u_long *) var->val.integer);        if (!snmp_strcat            (buf, buf_len, out_len, allow_realloc, (const u_char *) str)) {            return 0;        }        return 1;    }    if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {        char            str[32];        sprintf(str, "Timeticks: (%lu) ", *(u_long *) var->val.integer);        if (!snmp_strcat            (buf, buf_len, out_len, allow_realloc, (const u_char *) str)) {            return 0;        }    }    uptimeString(*(u_long *) (var->val.integer), timebuf);    if (!snmp_strcat        (buf, buf_len, out_len, allow_realloc, (const u_char *) timebuf)) {        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;}/** * Prints an integer according to the hint 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 _NOT_ 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_hinted_integer(u_char ** buf, size_t * buf_len,                              size_t * out_len, int allow_realloc,                              long val, const char decimaltype,                              const char *hint, const char *units){    char            fmt[10] = "%l@", tmp[256];    int             shift, len;    if (hint[1] == '-') {        shift = atoi(hint + 2);    } else {        shift = 0;    }    if (hint[0] == 'd') {        /*         * We might *actually* want a 'u' here.           */        fmt[2] = decimaltype;    } else {        /*         * DISPLAY-HINT character is 'b', 'o', or 'x'.           */        fmt[2] = hint[0];    }    sprintf(tmp, fmt, val);    if (shift != 0) {        len = strlen(tmp);        if (shift <= len) {            tmp[len + 1] = 0;            while (shift--) {                tmp[len] = tmp[len - 1];                len--;            }            tmp[len] = '.';        } else {            tmp[shift + 1] = 0;            while (shift) {                if (len-- > 0) {                    tmp[shift] = tmp[len];                } else {                    tmp[shift] = '0';                }                shift--;            }            tmp[0] = '.';        }    }    return snmp_strcat(buf, buf_len, out_len, allow_realloc, tmp);}/** * Prints an integer 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_integer(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           *enum_string = NULL;    if ((var->type != ASN_INTEGER) &&         (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        u_char          str[] = "Wrong Type (should be INTEGER): ";        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;        }    }    for (; enums; enums = enums->next) {        if (enums->value == *var->val.integer) {            enum_string = enums->label;            break;        }    }    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 *) "INTEGER: ")) {            return 0;        }    }    if (enum_string == NULL ||        netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM)) {        if (hint) {            if (!(sprint_realloc_hinted_integer(buf, buf_len, out_len,                                                allow_realloc,                                                *var->val.integer, 'd',                                                hint, units))) {                return 0;            }        } else {            char            str[16];            sprintf(str, "%ld", *var->val.integer);            if (!snmp_strcat                (buf, buf_len, out_len, allow_realloc,                 (const u_char *) str)) {                return 0;            }        }    } else 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 *) enum_string)) {            return 0;        }    } else {        char            str[16];        sprintf(str, "(%ld)", *var->val.integer);        if (!snmp_strcat            (buf, buf_len, out_len, allow_realloc,             (const u_char *) enum_string)) {            return 0;        }        if (!snmp_strcat            (buf, buf_len, out_len, allow_realloc, (const u_char *) str)) {            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;}/** * Prints an unsigned integer 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_uinteger(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           *enum_string = NULL;    if ((var->type != ASN_UINTEGER) &&         (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        u_char          str[] = "Wrong Type (should be UInteger32): ";        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;        }    }    for (; enums; enums = enums->next) {        if (enums->value == *var->val.integer) {            enum_string = enums->label;            break;        }    }    if (enum_string == NULL ||        netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM)) {        if (hint) {            if (!(sprint_realloc_hinted_integer(buf, buf_len, out_len,                                                allow_realloc,                                                *var->val.integer, 'u',                                                hint, units))) {                return 0;            }        } else {            char            str[16];            sprintf(str, "%lu", *var->val.integer);            if (!snmp_strcat                (buf, buf_len, out_len, allow_realloc,                 (const u_char *) str)) {                return 0;            }        }    } else 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 *) enum_string)) {            return 0;        }    } else {        char            str[16];        sprintf(str, "(%lu)", *var->val.integer);        if (!snmp_strcat            (buf, buf_len, out_len, allow_realloc,             (const u_char *) enum_string)) {            return 0;        }        if (!snmp_strcat            (buf, buf_len, out_len, allow_realloc, (const u_char *) str)) {            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;}/** * Prints a gauge value 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.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -