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

📄 v3_trgt.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* v3_trgt.c - v3_trgt.c routines *//* *  Copyright 2000-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. *//* *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. *//* * $Log: v3_trgt.c,v $ * Revision 1.2  2001/11/06 21:20:32  josh * revised new path hacking * * Revision 1.1.1.1  2001/11/05 17:47:44  tneale * Tornado shuffle * * Revision 9.7  2001/01/19 22:22:30  paul * Update copyright. * * Revision 9.6  2000/03/17 00:19:32  meister * Update copyright message * * Revision 9.5  2000/01/02 22:56:01  josh * patching up a memory leak here, a broken compare there...per * sar's comments * * Revision 9.4  1999/10/15 17:52:02  josh * added v3_snmpTargetSpinLock variable and made sure we clean up * the tdomain field when we destroy a target_addr object * * Revision 9.3  1999/09/15 16:21:26  josh * fixing a typo * * Revision 9.2  1999/09/11 02:09:19  josh * updating target code a bit * * Revision 9.1  1999/06/16 17:04:23  josh * First step of adding RFC2573 Notify support. * * *//* [clearcase]modification history-------------------01d,12may05,job  fix apigen comments01c,18apr05,job  update copyright notices01b,22feb05,job  apigen for documented APIs01a,24nov03,job  update copyright information*//*DESCRIPTIONThis library contains v3_trgt.c routines.INCLUDE FILES: snmp.h, v3_trgt.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_trgt.h>#include <wrn/wm/snmp/engine/snmpdefs.h>sbits32_t       v3_snmpTargetSpinLock = 0;/****************************************************************************\NOMANUALNAME:    target_addr listPURPOSE: This is the list of target address objects that we know         about.  It is ordered by target address name, the same as the         indexing for the mib.****************************************************************************//****************************************************************************NAME: target_addr_find_beforePURPOSE: Search through the list until we find the target_addr         structure we are looking for.  We return a pointer to the         pointer that would point to the requested target_addr if it         were to exist.  The calling routine is responsible for         determining if the requested target_addr exists.  This         construction allows us to reuse this code for all of the find         routines (lookup and install).PARAMETERS: bits8_t   * pointer to name buffer	    ALENGTH_T   number of bytes in nameRETURNS: SNMP_TARGET_ADDR_T ** pointer to pointer that would point to the 			       target_addr if it were to exist.****************************************************************************/static SNMP_TARGET_ADDR_T **  target_addr_find_before(bits8_t   *addr_name,			  ALENGTH_T  addr_name_len){SNMP_TARGET_ADDR_T **target_addr;ALENGTH_T            min_name_len;int                  compare;for(target_addr = &root_target_addr;     *target_addr;     target_addr = &(*target_addr)->next) {    min_name_len = min(addr_name_len, 		       EBufferUsed(&((*target_addr)->target_name)));    if ((compare = MEMCMP(EBufferStart(&((*target_addr)->target_name)), 			  addr_name,			  min_name_len)) >= 0)         if (compare || (min_name_len == addr_name_len))	    break;    }return(target_addr);}/********************************************************************************* SNMP_Target_Addr_Lookup - find a 'Target_Addr' entry matching the specified indices* SYNOPSIS** \cs* SNMP_TARGET_ADDR_T * SNMP_Target_Addr_Lookup *     (*     bits8_t   *  addr_name,*     ALENGTH_T    addr_name_len*     )* \ce** DESCRIPTION** This routine finds a 'Target_Addr' entry matching the specified indices.** Parameters:* \is* \i <*addr_name>* Specify the name of the 'Target_Addr', which corresponds to the MIB object * <snmpNotifyName>.* \i <addr_name_len>* Specify the length in bytes of the 'Target_Addr' name.* \ie** RETURNS: If successful, this routine returns a pointer to the entry. * Otherwise, it returns 0.** ERRNO: N/A** SEE ALSO: SNMP_Target_Addr_Create(), SNMP_Target_Addr_Deinstall(), * SNMP_Target_Addr_Destroy(), SNMP_Target_Addr_Install(), * SNMP_Target_Addr_Name(), SNMP_Target_Addr_Next_Addr(), SNMP Target_Addr Table * Field Routines*/SNMP_TARGET_ADDR_T *  SNMP_Target_Addr_Lookup(bits8_t   *addr_name,			  ALENGTH_T  addr_name_len){SNMP_TARGET_ADDR_T **target_addr;target_addr = target_addr_find_before(addr_name, addr_name_len);if (*target_addr &&     (addr_name_len == EBufferUsed(&((*target_addr)->target_name))) &&    (MEMCMP(EBufferStart(&((*target_addr)->target_name)), 	    addr_name,	    addr_name_len) == 0))    return(*target_addr);return(0);}/****************************************************************************\NOMANUALNAME: SNMP_Target_Addr_NextPURPOSE: Find the next target_addr after the named one.	the indexing information is of the form:	<addr_name>	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_TARGET_ADDR_T * pointer to target_addr or 0 if none found****************************************************************************/SNMP_TARGET_ADDR_T *  SNMP_Target_Addr_Next(int     tcount,			OIDC_T *tlist){SNMP_TARGET_ADDR_T *target_addr;bits8_t *addr_name;OIDC_T min_name_len = 0, *temp_oid, len;if (tcount == 0)    return(root_target_addr);for (target_addr = root_target_addr;     target_addr;     target_addr = target_addr->next) {     addr_name = EBufferStart(&(target_addr)->target_name);     min_name_len = min(tcount, EBufferUsed(&(target_addr->target_name)));     temp_oid = tlist;     for (len = min_name_len; 	  len && (*addr_name == *temp_oid);	  len--, addr_name++, temp_oid++)         ;     if (len) {         if (*addr_name > *temp_oid)	     return(target_addr);         }     else {         if (EBufferUsed(&(target_addr->target_name)) > tcount)	     return(target_addr);         }     }return(0);}/********************************************************************************* SNMP_Target_Addr_Next_Addr - find the next 'Target_Addr' in the 'Target_Addr' table* SYNOPSIS** \cs* SNMP_TARGET_ADDR_T  *  SNMP_Target_Addr_Next_Addr *     (*     SNMP_TARGET_ADDR_T  *  target_addr*     )* \ce** DESCRIPTION** This routine finds the 'Target_Addr' entry in the 'Target_Addr' table after * the specified 'Target_Addr' entry. Use this routine to step through the * 'Target_Addr' table to find all installed 'Target_Addr' entries.** Parameters:* \is* \i <*target_addr>* Specify the 'Target_Addr' entry.* \ie** RETURNS: If successful, this routine returns a pointer to the 'Target_Addr'. * If there is no successor or the specified 'Target_Addr' is not installed, it * returns 0. If the 'Target_Addr' is specified as 0, then it returns a pointer * to the first 'Target_Addr' entry in the table.** ERRNO: N/A** SEE ALSO: SNMP_Target_Addr_Create(), SNMP_Target_Addr_Deinstall(), * SNMP_Target_Addr_Destroy(), SNMP_Target_Addr_Install(), * SNMP_Target_Addr_Lookup(), SNMP_Target_Addr_Name(), SNMP Target_Addr Table * Field Routines*/SNMP_TARGET_ADDR_T *  SNMP_Target_Addr_Next_Addr (SNMP_TARGET_ADDR_T *target_addr){if (target_addr)    return(target_addr->next);return(root_target_addr);}/********************************************************************************* SNMP_Target_Addr_Destroy - destroy a 'Target_Addr' and frees associated resources* SYNOPSIS** \cs* void SNMP_Target_Addr_Destroy*     (*     SNMP_TARGET_ADDR_T *  target_addr *     )* \ce** DESCRIPTION** This routine destroys the specified 'Target_Addr' entry, frees the space for * the entry, and frees the space for any resources the entry might contain.** \&NOTE: If the specified 'Target_Addr' entry has been installed, call * SNMP_Target_Addr_Deinstall() before calling this routine.** Parameters:* \is* \i <*target_addr>* Specify the 'Target_Addr' entry to remove from the 'Target_Addr' table.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_Target_Addr_Create(), SNMP_Target_Addr_Deinstall(), * SNMP_Target_Addr_Install(), SNMP_Target_Addr_Lookup(), * SNMP_Target_Addr_Name(), SNMP_Target_Addr_Next_Addr(), SNMP Target_Addr Table * Field Routines*/void  SNMP_Target_Addr_Destroy(SNMP_TARGET_ADDR_T *target_addr){Clean_Obj_ID(&target_addr->tdomain);EBufferClean(&target_addr->taddress);EBufferClean(&target_addr->tmask);EBufferClean(&target_addr->tag_list);EBufferClean(&target_addr->params);SNMP_memory_free_lt(target_addr);}/********************************************************************************* SNMP_Target_Addr_Create - create a 'Target_Addr' structure* SYNOPSIS** \cs* SNMP_TARGET_ADDR_T * SNMP_Target_Addr_Create*     (*      void *     )* \ce** DESCRIPTION** This routine creates a 'Target_Addr' structure initialized to the default * values specified in RFC 2573. It attempts to allocate space for the entry. To * make an entry visible to the engine, use SNMP_Target_Addr_Install().** Parameters:* None.** RETURNS: If successful, this routine sets the entry to a default state and * returns a pointer to the entry. Otherwise, it returns 0.** ERRNO: N/A** SEE ALSO: SNMP_Target_Addr_Deinstall(), SNMP_Target_Addr_Destroy(), * SNMP_Target_Addr_Install(), SNMP_Target_Addr_Lookup(), * SNMP_Target_Addr_Name(), SNMP_Target_Addr_Next_Addr(), SNMP Target_Addr Table * Field Routines*/SNMP_TARGET_ADDR_T *  SNMP_Target_Addr_Create(void){SNMP_TARGET_ADDR_T *target_addr;target_addr = (SNMP_TARGET_ADDR_T *)    SNMP_memory_alloc_lt(sizeof(SNMP_TARGET_ADDR_T));if (target_addr == 0)    return(0);SNMP_Target_Addr_Set_Defaults(target_addr);return(target_addr);}/********************************************************************************* SNMP_Target_Addr_Install - install a 'Target_Addr' entry in the 'Target_Addr' table* SYNOPSIS** \cs* int SNMP_Target_Addr_Install*     (*     SNMP_TARGET_ADDR_T *  target_addr,*     bits8_t            *  addr_name,*     ALENGTH_T             addr_name_len*     )* \ce** DESCRIPTION** This routine installs the specified 'Target_Addr' entry in the 'Target_Addr' * table using <addr_name> as an index.** \&NOTE: Once a 'Target_Addr' entry has been installed, you must call * SNMP_Target_Addr_Deinstall() before calling SNMP_Target_Addr_Destroy() to * remove it.** Parameters:* \is* \i <*target_addr>* Specify the 'Target_Addr' entry to add to the 'Target_Addr' table.* \i <*addr_name>* Specify the name of the 'Target_Addr', which corresponds to the MIB object * <snmpNotifyName>.* \i <addr_name_len>* Specify the length in bytes of the 'Target_Addr' name.* \ie** RETURNS: If successful, this routine returns a value of 0. If an entry * already exists with the same indices or another error occurs, it returns -1.** ERRNO: N/A** SEE ALSO: SNMP_Target_Addr_Create(), SNMP_Target_Addr_Deinstall(), * SNMP_Target_Addr_Destroy(), SNMP_Target_Addr_Lookup(), * SNMP_Target_Addr_Name(), SNMP_Target_Addr_Next_Addr(), SNMP Target_Addr Table * Field Routines*/int  SNMP_Target_Addr_Install(SNMP_TARGET_ADDR_T *in_target_addr,			   bits8_t            *addr_name,			   ALENGTH_T           addr_name_len){SNMP_TARGET_ADDR_T **target_addr;/* see if the naming information is reasonable */if ((addr_name_len == 0) || (addr_name_len > ETC_TARGET_ADDR_MAX))    return(-1);/* see if the target_addr already exists */target_addr = target_addr_find_before(addr_name, addr_name_len);if (*target_addr &&    (EBufferUsed(&((*target_addr)->target_name)) == addr_name_len) &&    (MEMCMP(EBufferStart(&((*target_addr)->target_name)), 	    addr_name, 	    addr_name_len) == 0))    return(-1);/* allocate space for the name */EBufferAllocateLoad(BFL_IS_ALLOC, 		    &(in_target_addr->target_name), 		    addr_name, 		    addr_name_len);if (EBufferUsed(&(in_target_addr->target_name)) == 0)    return(-1);/* insert the target_addr into the list */in_target_addr->next = *target_addr;*target_addr = in_target_addr;return(0);}/********************************************************************************* SNMP_Target_Addr_Deinstall - remove a 'Target_Addr' from the 'Target_Addr' table* SYNOPSIS** \cs* void SNMP_Target_Addr_Deinstall*     (*     SNMP_TARGET_ADDR_T *  target_addr *     )* \ce** DESCRIPTION** This routine removes the specified 'Target_Addr' entry from the 'Target_Addr' * table and cleans up any resources that might have been used for indexing * purposes.** Parameters:* \is* \i <*target_addr>* Specify the 'Target_Addr' entry to remove from the 'Target_Addr' table.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_Target_Addr_Create(), SNMP_Target_Addr_Destroy(), * SNMP_Target_Addr_Install(), SNMP_Target_Addr_Lookup(), * SNMP_Target_Addr_Name(), SNMP_Target_Addr_Next_Addr(), SNMP Target_Addr Table * Field Routines*/void    SNMP_Target_Addr_Deinstall(SNMP_TARGET_ADDR_T *in_target_addr){SNMP_TARGET_ADDR_T **target_addr;for(target_addr = &root_target_addr;     *target_addr;     target_addr = &(*target_addr)->next)    if (*target_addr == in_target_addr) {        *target_addr = in_target_addr->next;	EBufferClean(&(in_target_addr)->target_name);	in_target_addr->next = 0;	return;        }return;}/********************************************************************************* SNMP_Target_Addr_Name - extract the indexing information for a 'Target_Addr' entry* SYNOPSIS** \cs* void SNMP_Target_Addr_Name *     (*     SNMP_TARGET_ADDR_T *  target_addr,*     bits8_t            *  addr_name,*     ALENGTH_T          *  addr_name_len*     ) * \ce** DESCRIPTION** This routine extracts the indexing information for the specified * 'Target_Addr' entry. After this routine completes, check the values in the * <addr_name> and <addr_name_len> fields.

⌨️ 快捷键说明

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