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

📄 interface_common.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  Interface MIB architecture support * * $Id: interface_common.c,v 1.20.2.1 2004/12/10 13:49:17 rstory Exp $ */#include <net-snmp/net-snmp-config.h>#include <net-snmp/net-snmp-includes.h>#include "mibII/mibII_common.h"#include "if-mib/ifTable/ifTable_constants.h"#include <net-snmp/agent/net-snmp-agent-includes.h>#include <net-snmp/library/snmp_enum.h>#include "interface.h"/**---------------------------------------------------------------------*//* * local static vars */static netsnmp_conf_if_list *conf_list = NULL;static int need_wrap_check = -1;static int _access_interface_init = 0;/* * local static prototypes */static int _access_interface_entry_compare_name(const void *lhs,                                                const void *rhs);static void _access_interface_entry_release(netsnmp_interface_entry * entry,                                            void *unused);static void _access_interface_entry_save_name(const char *name, oid index);static void _parse_interface_config(const char *token, char *cptr);static void _free_interface_config(void);/**---------------------------------------------------------------------*//* * external per-architecture functions prototypes * * These shouldn't be called by the general public, so they aren't in * the header file. */#ifdef NETSNMP_ACCESS_INTERFACE_NOARCHextern void netsnmp_arch_interface_init(void);extern intnetsnmp_arch_interface_container_load(netsnmp_container* container,                                      u_int load_flags);extern intnetsnmp_arch_set_admin_status(netsnmp_interface_entry * entry,                              int ifAdminStatus);extern int netsnmp_arch_interface_index_find(const char*name);#endif/**---------------------------------------------------------------------*//* * initialization */voidinit_interface_common(void){    snmpd_register_config_handler("interface", _parse_interface_config,                                  _free_interface_config,                                  "name type speed");}voidnetsnmp_access_interface_init(void){    netsnmp_assert(0 == _access_interface_init); /* who is calling twice? */    if (1 == _access_interface_init)        return;    _access_interface_init = 1;#ifndef NETSNMP_ACCESS_INTERFACE_NOARCH    {        netsnmp_container * ifcontainer;        netsnmp_arch_interface_init();                /*         * load once to set up ifIndexes         */        ifcontainer = netsnmp_access_interface_container_load(NULL, 0);        if(NULL != ifcontainer)            netsnmp_access_interface_container_free(ifcontainer, 0);    }#endif}/**---------------------------------------------------------------------*//* * container functions *//** * initialize interface container */netsnmp_container *netsnmp_access_interface_container_init(u_int flags){    netsnmp_container *container1;    DEBUGMSGTL(("access:interface:container", "init\n"));    /*     * create the containers. one indexed by ifIndex, the other     * indexed by ifName.     */    container1 = netsnmp_container_find("access_interface:table_container");    if (NULL == container1)        return NULL;    if (flags & NETSNMP_ACCESS_INTERFACE_INIT_ADDL_IDX_BY_NAME) {        netsnmp_container *container2 =            netsnmp_container_find("access_interface_by_name:access_interface:table_container");        if (NULL == container2)            return NULL;        container2->compare = _access_interface_entry_compare_name;                netsnmp_container_add_index(container1, container2);    }    return container1;}/** * load interface information in specified container * * @param container empty container, or NULL to have one created for you * @param load_flags flags to modify behaviour. Examples: *                   NETSNMP_ACCESS_INTERFACE_INIT_ADDL_IDX_BY_NAME * * @retval NULL  error * @retval !NULL pointer to container */#ifndef NETSNMP_ACCESS_INTERFACE_NOARCHnetsnmp_container*netsnmp_access_interface_container_load(netsnmp_container* container, u_int load_flags){    int rc;    DEBUGMSGTL(("access:interface:container", "load\n"));    netsnmp_assert(1 == _access_interface_init);    if (NULL == container)        container = netsnmp_access_interface_container_init(load_flags);    if (NULL == container) {        snmp_log(LOG_ERR, "no container specified/found for access_interface\n");        return NULL;    }    rc =  netsnmp_arch_interface_container_load(container, load_flags);    if (0 != rc) {        netsnmp_access_interface_container_free(container,                                                NETSNMP_ACCESS_INTERFACE_FREE_NOFLAGS);        container = NULL;    }    return container;}voidnetsnmp_access_interface_container_free(netsnmp_container *container, u_int free_flags){    DEBUGMSGTL(("access:interface:container", "free\n"));    if (NULL == container) {        snmp_log(LOG_ERR, "invalid container for netsnmp_access_interface_free\n");        return;    }    if(! (free_flags & NETSNMP_ACCESS_INTERFACE_FREE_DONT_CLEAR)) {        /*         * free all items.         */        CONTAINER_CLEAR(container,                        (netsnmp_container_obj_func*)_access_interface_entry_release,                        NULL);    }    CONTAINER_FREE(container);}/** * @retval 0  interface not found */oidnetsnmp_access_interface_index_find(const char *name){    DEBUGMSGTL(("access:interface:find", "index\n"));    netsnmp_assert(1 == _access_interface_init);    return netsnmp_arch_interface_index_find(name);}#endif/**---------------------------------------------------------------------*//* * ifentry functions *//** */netsnmp_interface_entry *netsnmp_access_interface_entry_get_by_index(netsnmp_container *container, oid index){    netsnmp_index   tmp;    DEBUGMSGTL(("access:interface:entry", "by_index\n"));    netsnmp_assert(1 == _access_interface_init);    if (NULL == container) {        snmp_log(LOG_ERR,                 "invalid container for netsnmp_access_interface_entry_get_by_index\n");        return NULL;    }    tmp.len = 1;    tmp.oids = &index;    return (netsnmp_interface_entry *) CONTAINER_FIND(container, &tmp);}/** */netsnmp_interface_entry *netsnmp_access_interface_entry_get_by_name(netsnmp_container *container,                                const char *name){    netsnmp_interface_entry tmp;    DEBUGMSGTL(("access:interface:entry", "by_name\n"));    netsnmp_assert(1 == _access_interface_init);    if (NULL == container) {        snmp_log(LOG_ERR,                 "invalid container for netsnmp_access_interface_entry_get_by_name\n");        return NULL;    }    if (NULL == container->next) {        snmp_log(LOG_ERR,                 "secondary index missing for netsnmp_access_interface_entry_get_by_name\n");        return NULL;    }    tmp.name = name;    return CONTAINER_FIND(container->next, &tmp);}/** * @retval NULL  index not found */const char *netsnmp_access_interface_name_find(oid index){    DEBUGMSGTL(("access:interface:find", "name\n"));    netsnmp_assert(1 == _access_interface_init);    return se_find_label_in_slist("interfaces", index);}/** */netsnmp_interface_entry *netsnmp_access_interface_entry_create(const char *name, oid if_index){    netsnmp_interface_entry *entry =        SNMP_MALLOC_TYPEDEF(netsnmp_interface_entry);    DEBUGMSGTL(("access:interface:entry", "create\n"));    netsnmp_assert(1 == _access_interface_init);    if(NULL == entry)        return NULL;    if(NULL != name)        entry->name = strdup(name);    /*     * get if index, and save name for reverse lookup     */#ifndef NETSNMP_ACCESS_INTERFACE_NOARCH    if (0 == if_index)        entry->index = netsnmp_access_interface_index_find(name);    else#endif        entry->index = if_index;    _access_interface_entry_save_name(name, entry->index);    /*     * until we can get actual description, leave descr NULL.     * The end user can decide what to do with it.     */    /* entry->descr = strdup("unknown"); */    /*     * make some assumptions     */    entry->connector_present = 1;    entry->oid_index.len = 1;    entry->oid_index.oids = (oid *) & entry->index;    return entry;}/** */voidnetsnmp_access_interface_entry_free(netsnmp_interface_entry * entry){    DEBUGMSGTL(("access:interface:entry", "free\n"));    if (NULL == entry)        return;    /*     * SNMP_FREE not needed, for any of these,      * since the whole entry is about to be freed     */    if (NULL != entry->old_stats)        free(entry->old_stats);    if (NULL != entry->name)        free(entry->name);    if (NULL != entry->descr)        free(entry->descr);    if (NULL != entry->paddr)        free(entry->paddr);    free(entry);}/** * * @retval 0   : success * @retval < 0 : error */#ifndef NETSNMP_ACCESS_INTERFACE_NOARCHintnetsnmp_access_interface_entry_set_admin_status(netsnmp_interface_entry * entry,

⌨️ 快捷键说明

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