arp_common.c
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:3k
源码类别:

SNMP编程

开发平台:

Unix_Linux

  1. /*
  2.  *  Arp MIB architecture support
  3.  *
  4.  * $Id: arp_common.c,v 1.1 2004/04/13 19:32:48 rstory Exp $
  5.  */
  6. #include <net-snmp/net-snmp-config.h>
  7. #include <net-snmp/net-snmp-includes.h>
  8. #include <net-snmp/agent/net-snmp-agent-includes.h>
  9. #include <net-snmp/data_access/arp.h>
  10. /**---------------------------------------------------------------------*/
  11. /*
  12.  * local static prototypes
  13.  */
  14. static void _access_arp_entry_release(netsnmp_arp_entry * entry,
  15.                                       void *unused);
  16. /**---------------------------------------------------------------------*/
  17. /*
  18.  * external per-architecture functions prototypes
  19.  *
  20.  * These shouldn't be called by the general public, so they aren't in
  21.  * the header file.
  22.  */
  23. extern int
  24. netsnmp_access_arp_container_arch_load(netsnmp_container* container,
  25.                                        u_int load_flags);
  26. /**---------------------------------------------------------------------*/
  27. /*
  28.  * container functions
  29.  */
  30. /**
  31.  */
  32. netsnmp_container *
  33. netsnmp_access_arp_container_init(u_int flags)
  34. {
  35.     netsnmp_container *container1;
  36.     DEBUGMSGTL(("access:arp:container", "initn"));
  37.     /*
  38.      * create the containers. one indexed by ifIndex, the other
  39.      * indexed by ifName.
  40.      */
  41.     container1 = netsnmp_container_find("access_arp:table_container");
  42.     if (NULL == container1)
  43.         return NULL;
  44.     return container1;
  45. }
  46. /**
  47.  * @retval NULL  error
  48.  * @retval !NULL pointer to container
  49.  */
  50. netsnmp_container*
  51. netsnmp_access_arp_container_load(netsnmp_container* container, u_int load_flags)
  52. {
  53.     int rc;
  54.     DEBUGMSGTL(("access:arp:container", "loadn"));
  55.     if (NULL == container)
  56.         container = netsnmp_container_find("access:arp:table_container");
  57.     if (NULL == container) {
  58.         snmp_log(LOG_ERR, "no container specified/found for access_arpn");
  59.         return NULL;
  60.     }
  61.     rc =  netsnmp_access_arp_container_arch_load(container, load_flags);
  62.     if (0 != rc) {
  63.         netsnmp_access_arp_container_free(container,
  64.                                           NETSNMP_ACCESS_ARP_FREE_NOFLAGS);
  65.         container = NULL;
  66.     }
  67.     return container;
  68. }
  69. void
  70. netsnmp_access_arp_container_free(netsnmp_container *container, u_int free_flags)
  71. {
  72.     DEBUGMSGTL(("access:arp:container", "freen"));
  73.     if (NULL == container) {
  74.         snmp_log(LOG_ERR, "invalid container for netsnmp_access_arp_freen");
  75.         return;
  76.     }
  77.     if(! (free_flags & NETSNMP_ACCESS_ARP_FREE_DONT_CLEAR)) {
  78.         /*
  79.          * free all items.
  80.          */
  81.         CONTAINER_CLEAR(container,
  82.                         (netsnmp_container_obj_func*)_access_arp_entry_release,
  83.                         NULL);
  84.     }
  85.     CONTAINER_FREE(container);
  86. }
  87. /**---------------------------------------------------------------------*/
  88. /*
  89.  * arp_entry functions
  90.  */
  91. /**
  92.  */
  93. netsnmp_arp_entry *
  94. netsnmp_access_arp_entry_create(void)
  95. {
  96.     netsnmp_arp_entry *entry =
  97.         SNMP_MALLOC_TYPEDEF(netsnmp_arp_entry);
  98.     entry->oid_index.len = 1;
  99.     entry->oid_index.oids = &entry->ns_arp_index;
  100.     return entry;
  101. }
  102. /**
  103.  */
  104. void
  105. netsnmp_access_arp_entry_free(netsnmp_arp_entry * entry)
  106. {
  107.     free(entry);
  108. }
  109. /**---------------------------------------------------------------------*/
  110. /*
  111.  * Utility routines
  112.  */
  113. /**
  114.  */
  115. void
  116. _access_arp_entry_release(netsnmp_arp_entry * entry, void *context)
  117. {
  118.     netsnmp_access_arp_entry_free(entry);
  119. }