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

📄 mib.c

📁 snmp up 2
💻 C
📖 第 1 页 / 共 5 页
字号:
                !(allow_realloc && snmp_realloc(buf, buf_len))) {                return 0;            }            *(*buf + (*out_len)++) = '.';            cp++;        }    }    if ((*out_len >= *buf_len) &&        !(allow_realloc && snmp_realloc(buf, buf_len))) {        return 0;    }    *(*buf + *out_len) = '\0';    return 1;}/** * Prints an octet string into a buffer. * * The variable var is encoded as octet string. *  * 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_octet_string(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){    size_t          saved_out_len = *out_len;    const char     *saved_hint = hint;    int             hex = 0, x = 0;    u_char         *cp;    int             output_format;    if ((var->type != ASN_OCTET_STR) &&         (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        const char      str[] = "Wrong Type (should be OCTET STRING): ";        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 (hint) {        int             repeat, width = 1;        long            value;        char            code = 'd', separ = 0, term = 0, ch, intbuf[16];        u_char         *ecp;        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 *) "STRING: ")) {                return 0;            }        }        cp = var->val.string;        ecp = cp + var->val_len;        while (cp < ecp) {            repeat = 1;            if (*hint) {                if (*hint == '*') {                    repeat = *cp++;                    hint++;                }                width = 0;                while ('0' <= *hint && *hint <= '9')                    width = (width * 10) + (*hint++ - '0');                code = *hint++;                if ((ch = *hint) && ch != '*' && (ch < '0' || ch > '9')                    && (width != 0                        || (ch != 'x' && ch != 'd' && ch != 'o')))                    separ = *hint++;                else                    separ = 0;                if ((ch = *hint) && ch != '*' && (ch < '0' || ch > '9')                    && (width != 0                        || (ch != 'x' && ch != 'd' && ch != 'o')))                    term = *hint++;                else                    term = 0;                if (width == 0)                    width = 1;            }            while (repeat && cp < ecp) {                value = 0;                if (code != 'a') {                    for (x = 0; x < width; x++) {                        value = value * 256 + *cp++;                    }                }                switch (code) {                case 'x':                    sprintf(intbuf, "%lx", value);                    if (!snmp_strcat                        (buf, buf_len, out_len, allow_realloc,                         (u_char *) intbuf)) {                        return 0;                    }                    break;                case 'd':                    sprintf(intbuf, "%ld", value);                    if (!snmp_strcat                        (buf, buf_len, out_len, allow_realloc,                         (u_char *) intbuf)) {                        return 0;                    }                    break;                case 'o':                    sprintf(intbuf, "%lo", value);                    if (!snmp_strcat                        (buf, buf_len, out_len, allow_realloc,                         (u_char *) intbuf)) {                        return 0;                    }                    break;                case 't': /* new in rfc 3411 */                case 'a':                    while ((*out_len + width + 1) >= *buf_len) {                        if (!(allow_realloc && snmp_realloc(buf, buf_len))) {                            return 0;                        }                    }                    for (x = 0; x < width && cp < ecp; x++) {                        *(*buf + *out_len) = *cp++;                        (*out_len)++;                    }                    *(*buf + *out_len) = '\0';                    break;                default:                    *out_len = saved_out_len;                    if (snmp_strcat(buf, buf_len, out_len, allow_realloc,                                    (const u_char *) "(Bad hint ignored: ")                        && snmp_strcat(buf, buf_len, out_len,                                       allow_realloc,                                       (const u_char *) saved_hint)                        && snmp_strcat(buf, buf_len, out_len,                                       allow_realloc,                                       (const u_char *) ") ")) {                        return sprint_realloc_octet_string(buf, buf_len,                                                           out_len,                                                           allow_realloc,                                                           var, enums,                                                           NULL, NULL);                    } else {                        return 0;                    }                }                if (cp < ecp && separ) {                    while ((*out_len + 1) >= *buf_len) {                        if (!(allow_realloc && snmp_realloc(buf, buf_len))) {                            return 0;                        }                    }                    *(*buf + *out_len) = separ;                    (*out_len)++;                    *(*buf + *out_len) = '\0';                }                repeat--;            }            if (term && cp < ecp) {                while ((*out_len + 1) >= *buf_len) {                    if (!(allow_realloc && snmp_realloc(buf, buf_len))) {                        return 0;                    }                }                *(*buf + *out_len) = term;                (*out_len)++;                *(*buf + *out_len) = '\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));        }        if ((*out_len >= *buf_len) &&            !(allow_realloc && snmp_realloc(buf, buf_len))) {            return 0;        }        *(*buf + *out_len) = '\0';        return 1;    }    output_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_STRING_OUTPUT_FORMAT);    if (0 == output_format) {        output_format = NETSNMP_STRING_OUTPUT_GUESS;    }    switch (output_format) {    case NETSNMP_STRING_OUTPUT_GUESS:        hex = 0;        for (cp = var->val.string, x = 0; x < (int) var->val_len; x++, cp++) {            if (!(isprint(*cp) || isspace(*cp))) {                hex = 1;            }        }        break;    case NETSNMP_STRING_OUTPUT_ASCII:        hex = 0;        break;    case NETSNMP_STRING_OUTPUT_HEX:        hex = 1;        break;    }    if (var->val_len == 0) {        return snmp_strcat(buf, buf_len, out_len, allow_realloc,                           (const u_char *) "\"\"");    }    if (hex) {        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 *) "\"")) {                return 0;            }        } else {            if (!snmp_strcat                (buf, buf_len, out_len, allow_realloc,                 (const u_char *) "Hex-STRING: ")) {                return 0;            }        }        if (!sprint_realloc_hexstring(buf, buf_len, out_len, allow_realloc,                                      var->val.string, var->val_len)) {            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 *) "\"")) {                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 *) "STRING: ")) {                return 0;            }        }        if (!snmp_strcat            (buf, buf_len, out_len, allow_realloc,             (const u_char *) "\"")) {            return 0;        }        if (!sprint_realloc_asciistring            (buf, buf_len, out_len, allow_realloc, var->val.string,             var->val_len)) {            return 0;        }        if (!snmp_strcat            (buf, buf_len, out_len, allow_realloc,             (const u_char *) "\"")) {            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;}#ifdef OPAQUE_SPECIAL_TYPES/** * Prints a float into a buffer. * * The variable var is encoded as a 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_float(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_FLOAT) &&        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        u_char          str[] = "Wrong Type (should be Float): ";        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)) {        if (!snmp_strcat            (buf, buf_len, out_len, allow_realloc,             (const u_char *) "Opaque: Float: ")) {            return 0;        }    }    /*     * How much space needed for max. length float?  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.floatVal);

⌨️ 快捷键说明

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