📄 v3_comm.c
字号:
/* v3_comm.c - v3_comm.c routines *//* * Copyright 2001-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//* * $Log: v3_comm.c,v $ * Revision 1.2 2001/11/06 21:20:30 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:44 tneale * Tornado shuffle * * Revision 1.1.2.2 2001/08/24 14:33:34 josh * use the envoy_err_t error codes where applicable * * Revision 1.1.2.1 2001/07/16 18:02:14 josh * a first-round commit adding infrastructure support * for the SNMPv3 Coexistence RFC (2576) * * *//* [clearcase]modification history-------------------01e,12may05,job fix apigen comments01d,18apr05,job update copyright notices01c,04mar05,job apigen update01b,16feb05,job apigen for documented APIs01a,24nov03,job update copyright information*//*DESCRIPTIONThis library contains v3_comm.c routines.INCLUDE FILES: snmp.h, v3_comm.h*/#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/v3_eng.h>#include <wrn/wm/snmp/engine/v3_comm.h>#include <wrn/wm/snmp/engine/snmpdefs.h>/****************************************************************************\NOMANUALNAME: community listPURPOSE: This is the list of community objects that we know about. It is ordered by community index, the same as the indexing for the mib.****************************************************************************//****************************************************************************NAME: community_find_beforePURPOSE: Search through the list until we find the community structure we are looking for. We return a pointer to the pointer that would point to the requested community if it were to exist. The calling routine is responsible for determining if the requested community exists. This construction allows us to reuse this code for all of the find routines (lookup and install).PARAMETERS: bits8_t * pointer to index name buffer ALENGTH_T number of bytes in index nameRETURNS: SNMP_COMMUNITY_T ** pointer to pointer that would point to the community if it were to exist.****************************************************************************/static SNMP_COMMUNITY_T ** community_find_before(bits8_t *comm_index, ALENGTH_T comm_index_len){SNMP_COMMUNITY_T **community;ALENGTH_T min_index_len;int compare;for(community = &root_community; *community; community = &(*community)->next) { min_index_len = min(comm_index_len, EBufferUsed(&((*community)->comm_index))); if ((compare = MEMCMP(EBufferStart(&((*community)->comm_index)), comm_index, min_index_len)) >= 0) if (compare || (min_index_len == comm_index_len)) break; }return(community);}/********************************************************************************* SNMP_Community_Lookup - find a community matching the specified index.* SYNOPSIS** \cs* SNMP_COMMUNITY_T * SNMP_Community_Lookup * (* bits8_t * comm_index,* ALENGTH_T comm_index_len* )* \ce** DESCRIPTION** This routine finds the community object entry that matches the specified * <comm_index>.** PARAMETERS* \is* \i <*comm_index>* Point to the community index, which corresponds to the MIB object * <snmpCommunityIndex>.* \i <comm_index_len>* Specify the length in bytes of the allocated <comm_index> buffer.* \ie** RETURNS: If successful, this routine returns a pointer to the community * object with the specified name. Otherwise, the object doesn\抰 exist and this * routine returns NULL.** ERRNO: N/A** SEE ALSO: SNMP_Community_Create(), SNMP_Community_Deinstall(), * SNMP_Community_Destroy(), SNMP_Community_Index(), SNMP_Community_Install(), * SNMP_Community_Next_Community()*/SNMP_COMMUNITY_T * SNMP_Community_Lookup(bits8_t *comm_index, ALENGTH_T comm_index_len){SNMP_COMMUNITY_T **community;community = community_find_before(comm_index, comm_index_len);if (*community && (comm_index_len == EBufferUsed(&((*community)->comm_index))) && (MEMCMP(EBufferStart(&((*community)->comm_index)), comm_index, comm_index_len) == 0)) return(*community);return(0);}/****************************************************************************\NOMANUALNAME: SNMP_Community_NextPURPOSE: Find the next community after the named one. the indexing information is of the form: <comm_index> but as this is a next we might not have all of it...PARAMETERS: int tcount number of subids OIDC_T *tlist list of subids RETURNS: SNMP_COMMUNITY_T * pointer to community or 0 if none found****************************************************************************/SNMP_COMMUNITY_T * SNMP_Community_Next(int tcount, OIDC_T *tlist){SNMP_COMMUNITY_T *community;bits8_t *comm_index;OIDC_T *temp_oid;ALENGTH_T min_index_len = 0, len;if (tcount == 0) return(root_community);for (community = root_community; community; community = community->next) { comm_index = EBufferStart(&(community)->comm_index); min_index_len = min(tcount, EBufferUsed(&(community->comm_index))); temp_oid = tlist; for (len = min_index_len; len && (*comm_index == *temp_oid); len--, comm_index++, temp_oid++) ; if (len) { if (*comm_index > *temp_oid) return(community); } else { if (EBufferUsed(&(community->comm_index)) > tcount) return(community); } }return(0);}/********************************************************************************* SNMP_Community_Next_Community - find the next community object* SYNOPSIS** \cs* SNMP_COMMUNITY_T * SNMP_Community_Next_Community * (* SNMP_COMMUNITY_T * community* )* \ce** DESCRIPTION** This routine finds the next community object entry in the community table * after the specified community object. Use this routine to step through the * community table to find all installed community objects.** PARAMETERS* \is* \i <*community>* Point to a community object in the community table. To return a pointer to * the first community object in the table, specify this parameter as NULL.* \ie** RETURNS: If successful, this routine returns a pointer to the community * object that comes next in the list after the specified community object. If * there is no successor, or the specified community object is not installed, * this routine returns NULL.** ERRNO: N/A** SEE ALSO: SNMP_Community_Create(), SNMP_Community_Deinstall(), * SNMP_Community_Destroy(), SNMP_Community_Index(), SNMP_Community_Install(), * SNMP_Community_Lookup()*/SNMP_COMMUNITY_T * SNMP_Community_Next_Community (SNMP_COMMUNITY_T *community){if (community) return(community->next);return(root_community);}/********************************************************************************* SNMP_Community_Destroy - destroy the community object and free any associated resources* SYNOPSIS** \cs* void SNMP_Community_Destroy* (* SNMP_COMMUNITY_T *community* )* \ce** DESCRIPTION** This routine deallocates all memory associated with the specified community * object, and then deallocates the object itself.** \&NOTE: If the specified object has been installed, call * SNMP_Community_Deinstall() before calling this routine.** PARAMETERS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -