📄 v3_trgt.c
字号:
** 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>. If the address name argument is long enough to hold the * name, the name is copied and returned.* \i <addr_name_len>* Specify the length in bytes of the 'Target_Addr' name.* \ie** RETURNS: None.** 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_Next_Addr(), SNMP Target_Addr * Table Field Routines*/void SNMP_Target_Addr_Name(SNMP_TARGET_ADDR_T *target_addr, bits8_t *addr_name, ALENGTH_T *addr_name_len){if (EBufferUsed(&(target_addr->target_name)) && (*addr_name_len >= EBufferUsed(&(target_addr->target_name)))) { MEMCPY(addr_name, EBufferStart(&(target_addr->target_name)), EBufferUsed(&(target_addr->target_name))); }*addr_name_len = EBufferUsed(&(target_addr->target_name));return;}/****************************************************************************\NOMANUALName: target_params 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_params_find_beforePURPOSE: Search through the list until we find the target_params structure we are looking for. We return a pointer to the pointer that would point to the requested target_params if it were to exist. The calling routine is responsible for determining if the requested target_params 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_PARAMS_T ** pointer to pointer that would point to the target_params if it were to exist.****************************************************************************/static SNMP_TARGET_PARAMS_T ** target_params_find_before(bits8_t *params_name, ALENGTH_T params_name_len){SNMP_TARGET_PARAMS_T **target_params;ALENGTH_T min_name_len;int compare;for(target_params = &root_target_params; *target_params; target_params = &(*target_params)->next) { min_name_len = min(params_name_len, EBufferUsed(&((*target_params)->params_name))); if ((compare = MEMCMP(EBufferStart(&((*target_params)->params_name)), params_name, min_name_len)) >= 0) if (compare || (min_name_len == params_name_len)) break; }return(target_params);}/********************************************************************************* SNMP_Target_Params_Lookup - find a target params entry matching the specified indices* SYNOPSIS** \cs* SNMP_TARGET_PARAMS_T * SNMP_Target_Params_Lookup * (* bits8_t * params_name,* ALENGTH_T * params_name_len* )* \ce** DESCRIPTION** This routine finds a target params entry matching the specified indices.** Parameters:* \is* \i <*params_name>* Specify the name of the target params entry, which corresponds to the MIB * object <snmpParamsName>.* \i <*params_name_len>* Specify the length in bytes of the <target params> name.* \ie** RETURNS: If successful, this routine returns a pointer to the entry. * Otherwise, it returns 0.** ERRNO: N/A** SEE ALSO: SNMP_Target_Params_Create(), SNMP_Target_Params_Deinstall(), * SNMP_Target_Params_Destroy(), SNMP_Target_Params_Install(), * SNMP_Target_Params_Name(), SNMP_Target_Params_Next_Params(), SNMP Target * Params Table Field Routines*/SNMP_TARGET_PARAMS_T * SNMP_Target_Params_Lookup(bits8_t *params_name, ALENGTH_T params_name_len){SNMP_TARGET_PARAMS_T **target_params;target_params = target_params_find_before(params_name, params_name_len);if (*target_params && (params_name_len == EBufferUsed(&((*target_params)->params_name))) && (MEMCMP(EBufferStart(&((*target_params)->params_name)), params_name, params_name_len) == 0)) return(*target_params);return(0);}/****************************************************************************\NOMANUALNAME: SNMP_Target_Params_NextPURPOSE: Find the next target_params 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_PARAMS_T * pointer to target_addr or 0 if none found****************************************************************************/SNMP_TARGET_PARAMS_T * SNMP_Target_Params_Next(int tcount, OIDC_T *tlist){SNMP_TARGET_PARAMS_T *target_params;bits8_t *params_name;OIDC_T min_name_len = 0, *temp_oid, len;if (tcount == 0) return(root_target_params);for (target_params = root_target_params; target_params; target_params = target_params->next) { params_name = EBufferStart(&(target_params)->params_name); min_name_len = min(tcount, EBufferUsed(&(target_params->params_name))); temp_oid = tlist; for (len = min_name_len; len && (*params_name == *temp_oid); len--, params_name++, temp_oid++) ; if (len) { if (*params_name > *temp_oid) return(target_params); } else { if (EBufferUsed(&(target_params->params_name)) > tcount) return(target_params); } }return(0);}/********************************************************************************* SNMP_Target_Params_Next_Params - find the entry in the target params table* SYNOPSIS** \cs* SNMP_TARGET_PARAMS_T * SNMP_Target_Params_Next_Params * (* SNMP_TARGET_PARAMS_T * target_params* )* \ce** DESCRIPTION** This routine finds the <target params> entry in the <target params> table * after the specified <target params> entry. Use this routine to step through * the <target params> table to find all installed <target params>.** Parameters:* \is* \i <*target_params>* Specify the <target params> entry.* \ie** RETURNS: If successful, this routine returns a pointer to the target params * entry. If there is no successor or the specified <target params> entry is not * installed, it returns 0. If the <target params> entry is specified as 0, then * it returns a pointer to the first <target params> entry in the table.** ERRNO: N/A** SEE ALSO: SNMP_Target_Params_Create(), SNMP_Target_Params_Deinstall(), * SNMP_Target_Params_Destroy(), SNMP_Target_Params_Install(), * SNMP_Target_Params_Lookup(), SNMP_Target_Params_Name(), SNMP Target Params * Table Field Routines*/SNMP_TARGET_PARAMS_T * SNMP_Target_Params_Next_Params (SNMP_TARGET_PARAMS_T *target_params){if (target_params) return(target_params->next);return(root_target_params);}/********************************************************************************* SNMP_Target_Params_Destroy - destroy a target params entry and frees resources* SYNOPSIS** \cs* void SNMP_Target_Params_Destroy* (* SNMP_Target_Params_T * target_params * )* \ce** DESCRIPTION** This routine destroys the specified <target params> entry, frees the space * for the entry, and frees the space for any resources the entry might contain.** \&NOTE: If the specified target params entry has been installed, call * SNMP_Target_Params_Deinstall() before calling this routine.** Parameters:* \is* \i <*target_params>* Specify the <target params> entry to remove from the target params table.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_Target_Params_Create(), SNMP_Target_Params_Deinstall(), * SNMP_Target_Params_Install(), SNMP_Target_Params_Lookup(), * SNMP_Target_Params_Name(), SNMP_Target_Params_Next_Params(), SNMP Target * Params Table Field Routines*/void SNMP_Target_Params_Destroy(SNMP_TARGET_PARAMS_T *target_params){EBufferClean(&target_params->sec_name);SNMP_memory_free_lt(target_params);}/********************************************************************************* SNMP_Target_Params_Create - create a target params structure* SYNOPSIS** \cs* SNMP_TARGET_PARAMS_T * SNMP_Target_Params_Create* (* void * )* \ce** DESCRIPTION** This routine creates a target params structure ('snmpTargetParamsTable'), * 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_Params_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_Params_Deinstall(), SNMP_Target_Params_Destroy(), * SNMP_Target_Params_Install(), SNMP_Target_Params_Lookup(), * SNMP_Target_Params_Name(), SNMP_Target_Params_Next_Params(), SNMP Target * Params Table Field Routines*/SNMP_TARGET_PARAMS_T * SNMP_Target_Params_Create(void){SNMP_TARGET_PARAMS_T *target_params;target_params = (SNMP_TARGET_PARAMS_T *) SNMP_memory_alloc_lt(sizeof(SNMP_TARGET_PARAMS_T));if (target_params == 0) return(0);SNMP_Target_Params_Set_Defaults(target_params);return(target_params);}/********************************************************************************* SNMP_Target_Params_Install - install a target params entry in the target params table* SYNOPSIS** \cs* int SNMP_Target_Params_Install* (* SNMP_TARGET_PARAMS_T * target_params,* bits8_t * params_name,* ALENGTH_T params_name_len* )* \ce** DESCRIPTION** This routine installs the specified <target params> entry in the <target * params> table using <params_name> as an index.** \&NOTE: Once a <target params> entry has been installed, you must call * SNMP_Target_Params_Deinstall()before calling SNMP_Target_Params_Destroy() to * remove it.** Parameters:* \is* \i <*target_params>* Specify the <target params> entry to add to the target params table.* \i <*params_name>* Specify the name of the <target params> entry, which corresponds to the MIB * object <snmpParamsName>.* \i <params_name_len>* Specify the length in bytes of the <target params> 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 -l.** ERRNO: N/A** SEE ALSO: SNMP_Target_Params_Create(), SNMP_Target_Params_Deinstall(), * SNMP_Target_Params_Destroy(), SNMP_Target_Params_Lookup(), * SNMP_Target_Params_Name(), SNMP_Target_Params_Next_Params(), SNMP Target * Params Table Field Routines*/int SNMP_Target_Params_Install(SNMP_TARGET_PARAMS_T *in_target_params, bits8_t *params_name, ALENGTH_T params_name_len){SNMP_TARGET_PARAMS_T **target_params;/* see if the naming information is reasonable */if ((params_name_len == 0) || (params_name_len > ETC_TARGET_PARAMS_MAX)) return(-1);/* see if the target_params already exists */target_params = target_params_find_before(params_name, params_name_len);if (*target_params && (EBufferUsed(&((*target_params)->params_name)) == params_name_len) && (MEMCMP(EBufferStart(&((*target_params)->params_name)), params_name, params_name_len) == 0)) return(-1);/* allocate space for the name */EBufferAllocateLoad(BFL_IS_ALLOC, &(in_target_params->params_name), params_name, params_name_len);if (EBufferUsed(&(in_target_params->params_name)) == 0) return(-1);/* insert the target_params into the list */in_target_params->next = *target_params;*target_params = in_target_params;return(0);}/********************************************************************************* SNMP_Target_Params_Deinstall - remove a target params entry from the table* SYNOPSIS** \cs* void SNMP_Target_Params_Deinstall* (* SNMP_TARGET_PARAMS_T * target_params* )* \ce** DESCRIPTION** This routine removes the specified <target params> entry from the target * params table and cleans up any resources that might have been used for * indexing purposes.** Parameters:* \is* \i <*target_params>* Specify the <target params> entry to remove from the target params table.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_Target_Params_Create(), SNMP_Target_Params_Destroy(), * SNMP_Target_Params_Install(), SNMP_Target_Params_Lookup(), * SNMP_Target_Params_Name(), SNMP_Target_Params_Next_Params(), SNMP Target * Params Table Field Routines*/void SNMP_Target_Params_Deinstall(SNMP_TARGET_PARAMS_T *in_target_params){SNMP_TARGET_PARAMS_T **target_params;for(target_params = &root_target_params; *target_params; target_params = &(*target_params)->next) if (*target_params == in_target_params) { *target_params = in_target_params->next; EBufferClean(&(in_target_params)->params_name); in_target_params->next = 0; return; }return;}/********************************************************************************* SNMP_Target_Params_Name - extract the indexing information for a target params entry* SYNOPSIS** \cs* void SNMP_Target_Params_Name * (* SNMP_TARGET_PARAMS_T * target_params,* bits8_t * params_name,* ALENGTH_T * params_name_len* )* \ce** DESCRIPTION** This routine extracts the indexing information for the specified <target * params> entry. After this routine completes, check the values in the * <params_name> and <params_name_len> fields.** Parameters:* \is* \i <*target_params>* Specify the <target params> entry.* \i <*params_name>* Specify the name of the <target params> entry, which corresponds to the MIB * object <snmpParamsName>. If the buffer is long enough to hold the name, the * name is copied and returned.* \i <*params_name_len>* Specify the length in bytes of the <target params> name.* \ie** RETURNS: This routine always returns void.** ERRNO: N/A** SEE ALSO: SNMP_Target_Params_Create(), SNMP_Target_Params_Deinstall(), * SNMP_Target_Params_Destroy(), SNMP_Target_Params_Install(), * SNMP_Target_Params_Lookup(), SNMP_Target_Params_Next_Params(), SNMP Target * Params Table Field Routines*/void SNMP_Target_Params_Name(SNMP_TARGET_PARAMS_T *target_params, bits8_t *params_name, ALENGTH_T *params_name_len){if (EBufferUsed(&(target_params->params_name)) && (*params_name_len >= EBufferUsed(&(target_params->params_name)))) { MEMCPY(params_name, EBufferStart(&(target_params->params_name)), EBufferUsed(&(target_params->params_name))); }*params_name_len = EBufferUsed(&(target_params->params_name));return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -