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

📄 mib.c

📁 snmp up 2
💻 C
📖 第 1 页 / 共 5 页
字号:
 * @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_gauge(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            tmp[32];    if ((var->type != ASN_GAUGE) &&         (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        u_char          str[] =            "Wrong Type (should be Gauge32 or Unsigned32): ";        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[] = "Gauge32: ";        if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {            return 0;        }    }    if (hint) {        if (!sprint_realloc_hinted_integer(buf, buf_len, out_len,                                           allow_realloc,                                           *var->val.integer, 'u', hint,                                           units)) {            return 0;        }    } else {        sprintf(tmp, "%lu", *var->val.integer);        if (!snmp_strcat            (buf, buf_len, out_len, allow_realloc, (const u_char *) tmp)) {            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 counter 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. * @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_counter(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            tmp[32];    if ((var->type != ASN_COUNTER) &&         (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        u_char          str[] = "Wrong Type (should be Counter32): ";        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[] = "Counter32: ";        if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {            return 0;        }    }    sprintf(tmp, "%lu", *var->val.integer);    if (!snmp_strcat        (buf, buf_len, out_len, allow_realloc, (const u_char *) tmp)) {        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 network address 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_networkaddress(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          i;    if ((var->type != ASN_IPADDRESS) &&         (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        u_char          str[] = "Wrong Type (should be NetworkAddress): ";        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[] = "Network Address: ";        if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {            return 0;        }    }    while ((*out_len + (var->val_len * 3) + 2) >= *buf_len) {        if (!(allow_realloc && snmp_realloc(buf, buf_len))) {            return 0;        }    }    for (i = 0; i < var->val_len; i++) {        sprintf((char *) (*buf + *out_len), "%02X", var->val.string[i]);        *out_len += 2;        if (i < var->val_len - 1) {            *(*buf + *out_len) = ':';            (*out_len)++;        }    }    return 1;}/** * Prints an ip-address 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_ipaddress(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){    u_char         *ip = var->val.string;    if ((var->type != ASN_IPADDRESS) &&         (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        u_char          str[] = "Wrong Type (should be IpAddress): ";        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[] = "IpAddress: ";        if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {            return 0;        }    }    while ((*out_len + 17) >= *buf_len) {        if (!(allow_realloc && snmp_realloc(buf, buf_len))) {            return 0;        }    }    sprintf((char *) (*buf + *out_len), "%d.%d.%d.%d", ip[0], ip[1], ip[2],            ip[3]);    *out_len += strlen((char *) (*buf + *out_len));    return 1;}/** * Prints a null 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. * @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_null(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_NULL) &&         (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        u_char          str[] = "Wrong Type (should be NULL): ";        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;        }    } else {        u_char          str[] = "NULL";        return snmp_strcat(buf, buf_len, out_len, allow_realloc, str);    }}/** * Prints a bit string 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_bitstring(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             len, bit;    u_char         *cp;    char           *enum_string;    if ((var->type != ASN_BIT_STR && var->type != ASN_OCTET_STR) &&        (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT))) {        u_char          str[] = "Wrong Type (should be BITS): ";        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[] = "\"";        if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {            return 0;        }    } else {        u_char          str[] = "BITS: ";        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.bitstring, var->val_len)) {        return 0;    }    if (netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT)) {        u_char          str[] = "\"";        if (!snmp_strcat(buf, buf_len, out_len, allow_realloc, str)) {            return 0;        }    } else {        cp = var->val.bitstring;        for (len = 0; len < (int) var->val_len; len++) {            for (bit = 0; bit < 8; bit++) {                if (*cp & (0x80 >> bit)) {                    enum_string = NULL;                    for (; enums; enums = enums->next) {                        if (enums->value == (len * 8) + bit) {                            enum_string = enums->label;           

⌨️ 快捷键说明

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