📄 buildpkt.c
字号:
/* buildpkt.c - buildpkt.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 1988-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. *//* * $Log: buildpkt.c,v $ * Revision 1.2 2001/11/06 21:20:06 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:42 tneale * Tornado shuffle * * Revision 9.6 2001/04/11 20:12:02 josh * merging changes from the kingfisher branch back onto * the trunk * * Revision 9.5 2001/01/19 22:22:19 paul * Update copyright. * * Revision 9.4.2.2 2001/03/12 22:08:12 tneale * Updated copyright * * Revision 9.4.2.1 2001/02/09 18:38:38 josh * vblp_index_to_vbp() was updated to walk linked varbind lists * * Revision 9.4 2000/03/17 00:19:01 meister * Update copyright message * * Revision 9.3 1999/10/02 01:37:27 sar * Update the vbp to index code to handle get bulk error conditions. * * Revision 9.2 1999/09/14 19:27:03 josh * New function: vblp_index_to_vbp() * * Revision 9.1 1998/11/30 20:28:16 sar * Fix vbp to index code to allow the multiple vblists to be allocated from * random pieces of memory, previously the vblists would need to have been * allocated from lower addresses to higher address in order. * * Revision 9.0 1998/10/16 22:11:09 sar * Update version stamp to match release * * Revision 8.2 1998/06/05 18:53:10 sra * "#include <foo.h>" => "#include <envoy/h/foo.h>". * * Revision 8.1 1998/02/25 04:51:30 sra * Update copyrights. * * Revision 8.0 1997/11/18 00:56:44 sar * Updated revision to 8.0 * * Revision 7.2 1997/03/20 06:48:45 sra * DFARS-safe copyright text. Zap! * * Revision 7.1 1997/02/25 10:49:26 sra * Update copyright notice, dust under the bed. * * Revision 7.0 1996/03/18 20:01:11 sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.0 1995/05/31 21:47:16 sra * Release 6.0. * * Revision 5.2 1995/05/08 20:32:04 sar * Did some casting between pointer arithmetic, ints and ALENGTH_Ts to * keep compilers happy. * * Revision 5.1 1995/03/21 00:25:01 sar * Added vbp_to_index and updated index_to_vbp to understand var bind list * chains. * * Revision 5.0 1994/05/16 15:42:42 sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.0 1993/06/24 15:45:46 sar * Updated revision to 4.0 and copyright to 93 * * Revision 3.3 1993/06/02 23:09:24 dab * Changed #ifdef's to #if's for things from install.h * * Revision 3.2 1993/04/27 21:10:00 sar * Changed locate_vb to index_to_vbp * * Revision 3.1 1993/04/26 20:37:09 sar * Added ifdefs to allow clean makes of version 1 and 2, added bit strings, * arrange for deletion of acls with the party or context they refer to * is deleted. * * Revision 3.0 1992/04/03 19:52:37 dab * Release 3.0 * * Revision 2.102 91/10/30 20:41:50 dab * Directly include asn1conf.h, snmpdefs.h, and snmpstat.h (if needed). * * Revision 2.101 91/08/15 12:30:48 dab * Removed <libfuncs.h>. * * Revision 2.100 91/08/09 14:08:17 dab * Update version. * * Revision 1.1 91/07/30 02:23:29 romkey * Initial revision * * * Rev 2.0 31 Mar 1990 15:06:40 * Release 2.00 * * Rev 1.7 27 Apr 1989 15:55:58 * Removed unused variables * * Rev 1.6 11 Jan 1989 12:11:22 * Split into multiple files to prevent linker from picking up unused files. * * Rev 1.5 20 Sep 1988 22:51:38 * Corrected erroneous call to EBufferInitialize (should have been * EBufferPreLoad. * * Rev 1.4 20 Sep 1988 19:11:50 * Added procedure to build a VB list element containing a null value. * * Rev 1.3 19 Sep 1988 17:26:56 * Made changes to make the Sun C compiler happy. * * Rev 1.2 17 Sep 1988 18:57:14 * Corrected miscalculation of whether a given var bind index was in-range. * * Rev 1.1 14 Sep 1988 17:57:14 * Moved includes of system include files into libfuncs.h. * * Rev 1.0 12 Sep 1988 10:46:54 * Initial revision.*//* [clearcase]modification history-------------------01d,12may05,job fix apigen comments01c,18apr05,job update copyright notices01b,16feb05,job apigen for documented APIs01a,24nov03,job update copyright information*//*DESCRIPTIONThis library contains buildpkt.c routines.INCLUDE FILES: snmp.h*/#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/snmp.h>/********************************************************************************* index_to_vbp - translate an index into a 'VarBind'* SYNOPSIS** \cs* VB_T * index_to_vbp* ( * SNMP_PKT_T * pktp, * int index * )* \ce** DESCRIPTION** This routine translates an index into a 'VarBind'.** PARAMETERS* \is* \i <*pktp>* Specify an SNMP packet.* \i <index>* Specify the index to translate.* \ie** RETURNS: If successful, this routine returns a pointer to the 'VarBind'. * Otherwise, it returns 0.** ERRNO: N/A** SEE ALSO: 'VB_TO_COOKIE(),' vbp_to_index()*/VB_T * index_to_vbp(SNMP_PKT_T *pktp, int indx){VBL_T *vblp;/* If this is version 1 where we get the vblp from depends on the pdu type in version 2 we always get it from the standard area. In version 2 we have the complication of multiple vblists chained together for the getbulk operation */ #if INSTALL_ENVOY_SNMP_VERSION_1if (pktp->pdu_type == TRAP_PDU) vblp = &(pktp->pdu.trap_pdu.trap_vbl);else#endif vblp = &(pktp->pdu.std_pdu.std_vbl);return(vblp_index_to_vbp(vblp, indx));}/****************************************************************************\NOMANUALNAME: vblp_index_to_vbpPURPOSE: Given a VarBindList and the zero-based index of a varBind element in that list, return a pointer to that VB_TPARAMETERS: VBL_T * The VarBindList. int The index of the VB_T desired. (0 is the index of the first VB_T).RETURNS: VB_T * The address of the desired varBind element (VB_T *)0 returned if out of range.****************************************************************************/VB_T * vblp_index_to_vbp(VBL_T *vblp, int vb_index){for (; vblp; vblp = vblp->vblp) { if (vb_index < vblp->vbl_count) return &(vblp->vblist[vb_index]); else vb_index -= vblp->vbl_count; }return(0);}/********************************************************************************* vbp_to_index - determine the index for a specific 'VarBind'* SYNOPSIS** \cs* int vbp_to_index * ( * SNMP_PKT_T * pktp, * VB_T * vbp * )* \ce** DESCRIPTION** This routine determines the index for a specific 'VarBind'.** PARAMETERS* \is* \i <*pktp>* Specify an SNMP packet.* \i <*vbp>* Specify the root of a 'VarBindList'. The first 'VarBind' is index 0.* \ie** RETURNS: If successful, this routine returns the index. Otherwise, it returns * -1.** ERRNO: N/A** SEE ALSO: index_to_vbp(), VB_TO_COOKIE()*/int vbp_to_index_error(SNMP_PKT_T *pktp, VB_T *vbp, int mode){VBL_T *vblp;int count = 0;/* If this is version 1 where we get the vblp from depends on the pdu type in version 2 we always get it from the standard area. In version 2 we have the complication of multiple vblists chained together for the getbulk operation */ #if INSTALL_ENVOY_SNMP_VERSION_1if (pktp->pdu_type == TRAP_PDU) vblp = &(pktp->pdu.trap_pdu.trap_vbl);else vblp = &(pktp->pdu.std_pdu.std_vbl);#elsevblp = &(pktp->pdu.std_pdu.std_vbl);#endif/* Check whether the requested index is within the VarBindList */for (; vblp; vblp = vblp->vblp) { if ((vbp >= vblp->vblist) && (vbp < (vblp->vblist + vblp->vbl_count))) { if (mode == 0) return(count + ((int)(vbp - vblp->vblist))); else { /* If count is zero we are processing the first vblp and we can get the index directly, otherise we need to adjust the count for the non repeaters which aren't in the othe vblps */ if (count == 0) count = 1; else count = pktp->pdu.std_pdu.non_reps + 1; return(count + ((int)(vbp - vblp->vblist))); } } else count += vblp->vbl_count; }return(-1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -