📄 mibutils.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/snmptalk/mibutils.c,v 1.3 2003/01/15 14:04:55 josh Exp $ *//* * Copyright (C) 1999-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 1991-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. ****************************************************************************//* * $Log: mibutils.c,v $ * Revision 1.3 2003/01/15 14:04:55 josh * directory structure shifting * * Revision 1.2 2001/11/08 16:47:26 tneale * Updated for newset file layout * * Revision 1.1.1.1 2001/11/05 17:49:12 tneale * Tornado shuffle * * Revision 7.11 2001/01/19 22:24:47 paul * Update copyright. * * Revision 7.10 2000/03/17 00:14:33 meister * Update copyright message * * Revision 7.9 1998/06/03 21:50:31 sar * Moved nvutils and nvviews to snark/lib so we can have one copy shared * amongst the demos * Moved the common string functions from stdf to common/lib and created * a series of macros for this code to use * Moved strdup to snark/lib and renamed it to etc_strdup to avoid * needing one from the system libraries * * Revision 7.8 1998/05/23 19:18:37 sar * Corrected oid2string so it won't overrun the buffer * * Revision 7.7 1998/02/25 04:57:56 sra * Update copyrights. * * Revision 7.6 1997/05/17 23:08:58 sra * Clean up some SunOS/gcc warnings. * * Revision 7.5 1997/03/20 06:53:47 sra * DFARS-safe copyright text. Zap! * * Revision 7.4 1997/02/25 10:58:16 sra * Update copyright notice, dust under the bed. * * Revision 7.3 1997/01/08 23:26:53 sar * Updated include files to use envoy/h as appropriate after * move from envoy/utils to snark/snmptalk * * Revision 7.2 1997/01/08 01:58:11 sar * Removed no_pp stuff and updated copyrights * * Revision 7.1 1996/10/26 17:25:25 sra * Cast to suppress compiler warning. * * Revision 7.0 1996/03/18 20:19:20 sar * Updated rev to 7.0 and copyright to 96 * * Revision 6.1 1995/11/01 00:56:58 sar * removed no_pp stuff * * Revision 6.0 1995/05/31 21:50:11 sra * Release 6.0. * * Revision 5.2 1995/03/21 20:11:20 sar * Changed isnumber to ifisnumber to avoid conflicts with system defs. * * Revision 5.1 1994/07/24 15:41:03 dab * Added ability to set UDP port used by manager and the set command can * now specify enumerated integer values by symbolic name. * * Revision 5.0 1994/05/16 15:57:40 sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.0 1993/06/24 17:14:56 sar * Updated rev to 4.0 and copyright to 93 * * Revision 3.4 1993/06/13 02:48:16 sar * moved inclusion of stdf.h to be after asn1.h so that NO_PP will be defined * if desired. * * Revision 3.3 1993/05/17 20:36:13 sar * added <install.h> and "stdf.h" to include string routines that zortech * didn't have. * * Revision 3.2 1993/02/19 19:29:35 dab * Changes to use readmib instead of mibtree * * Revision 3.1 1993/02/05 18:47:56 dab * Changed "system.h" to <snmptalk.h> * * Revision 3.0 1992/04/03 19:53:14 dab * Release 3.0 * * Revision 2.106 92/02/11 10:56:20 dab * Casts to make Microsoft C happier. * * Revision 2.105 91/12/12 09:41:01 dab * Changed to use "nprint.h" instead of <print.h>. * * Revision 2.104 91/11/06 13:55:01 dab * Added function prototypes for internal functions and other fixups so * pickier compilers would be happy. * * Revision 2.103 91/11/04 16:14:41 dab * Improved for use with higher warning levels on the compiler. * * Revision 2.102 91/11/03 10:03:43 dab * Changed static function declarations so maybe they'll be accepted by * all the various compilers now. * * Revision 2.101 91/09/12 13:55:58 dab * Removed reference to <libfuncs.h>. * * Revision 2.100 91/08/09 14:05:19 dab * Update version number. This is just before the work to upgrade to * release 3.0. * * Revision 1.1 91/07/11 18:13:26 romkey * Initial revision * *//* [clearcase]modification history-------------------01b,19apr05,job update copyright notices01a,28mar05,job add strToOctet() function*//* Utility routines for making use of the -nametree output of the * MIB compiler. */#include <wrn/wm/common/install.h>#include <wrn/wm/common/config.h>#include <snmptalk.h>#include <snark.h>#include <stdio.h>#include <ctype.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/decode.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/objectid.h>#include "readmib.h"#include <wrn/wm/common/glue.h>static struct nametree *oid_find (OIDC_T *, int, struct nametree *, int *);static int mib_bfsearch (struct nametree *, char *, OIDC_T *, int);static int ifisnumber (char *);/* OID to string translation. Fills in buf with a printable version * of the OID. The length of the string is returned. If too long * then as much as fits is put in the buffer and the length needed is * returned. If verbose is true then the intermediate names in the * MIB are also printed. [Not yet implemented.] */int oid2string(OIDC_T *oid, int oidlen, char *buf, int buflen, int verbose){ struct nametree *nt; int plen; int numlen; int depth; char numbuf[11]; static char numpfsb[] = ".%lu"; char *numpfs; nt = oid_find(oid, oidlen, mibt, &depth); if (nt != 0) { oid += depth; oidlen -= depth; strncpy(buf, nt->name, buflen); plen = STRLEN(nt->name); if (plen >= buflen) buf[buflen-1] = '\0'; numpfs = numpfsb; } else { plen = 0; numpfs = &numpfsb[1]; } while (oidlen--) { sprintf(numbuf, numpfs, (unsigned long)*oid++); numpfs = numpfsb; numlen = STRLEN(numbuf); if (plen < buflen) { if (plen+numlen >= buflen) { strncpy(buf+plen, numbuf, buflen-plen); buf[buflen-1] = '\0'; } else STRCPY(buf+plen, numbuf); } plen += numlen; } return plen;}/* Look up a node in the mib tree given an oid and starting with the * given node in the tree. Fills in depth with how far down the tree * it went before running out of MIB. */static struct nametree * oid_find( OIDC_T *oid, int oidlen, struct nametree *tree, int *depth){ struct nametree *ret; int count; ret = 0; count = 0; while (oidlen && tree) { for (; tree; tree = tree->sibling) { if (tree->number == *oid) { ret = tree; count++; oidlen--; oid++; if (tree->type == 0) /* not a leaf node */ tree = tree->children; else tree = 0; break; } } } if (ret) *depth = count; return ret;}/* Return the type of the OID if it's found in the MIB. Otherwise return -1. */int oid_type(OIDC_T *oid, int oidlen){ struct nametree *nt; int depth; nt = oid_find(oid, oidlen, mibt, &depth); if (!nt) return -1; return nt->type;}/* Print an integer into a buffer symbolically if the oid is for a * variable that is an enumerated type. Otherwise, or if the * enumerated value isn't found, just fill in buf with the printed * form of the number. */void int2string(OIDC_T *oid, int oidlen, long val, char *buf, int buflen, int verbose){ struct nametree *nt; int depth; int len; char tmpbuf[14]; nt = oid_find(oid, oidlen, mibt, &depth); if (nt && nt->type != 0) { /* if a leaf node */ for (nt = nt->children; nt; nt = nt->sibling) { if (nt->number == (unsigned long)val) { strncpy(buf, nt->name, buflen);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -