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

📄 smdump.c

📁 基于单片机的 snmp协议解析的一些原代码 给有用的 同行
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 * Copyright 1992 SynOptics Communications, Inc.  All Rights Reserved.
 * SynOptics grants a non-exclusive license to use, copy, modify, and
 * distribute this software for any purpose and without fee, provided
 * that this copyright notice and license appear on all copies and
 * supporting documentation.
 * SynOptics makes no representations about the suitability of this
 * software for any particular purpose.  The software is supplied
 * "AS IS", and SynOptics makes no warranty, either express or implied,
 * as to the use, operation, condition, or performance of the software.
 * SynOptics retains all title and ownership in the software.
 *
 * file: SMDUMP.C - functions to dump the various lists in the compiler
 *                  and their necessary support routines.
 *
 * $Revision:   1.4  $ $Date:   08 Jul 1992 17:29:08  $
 * $Log:   R:/MIBTOOLS/V1.0/SMIC/SRC/SMDUMP.C_V  $
 * 
 *    Rev 1.4   08 Jul 1992 17:29:08   gfoster
 * Removed unnecessary revision comment lines added by
 * PVCS to make revision history easier to read.
 * 
 *    Rev 1.3   29 Jun 1992 20:53:50   gfoster
 * Removed the unreferenced local variable pD from
 * the printNameOID function.
 * 
 *    Rev 1.2   29 Jun 1992 19:34:26   gfoster
 * Changed dump of names to always print "**dup**"
 * if fDup is set (this means that the back-end
 * should be changed to clear and set fDup based
 * on include/exclude flag).
 * 
 * Changed dump of names so that if parent is not
 * defined, then "**not defined**" is printed
 * as the OID value instead of 4gig.
 * 
 *    Rev 1.1   19 Jun 1992 15:59:44   gfoster
 * Copyright text was reformated.
 * 
 * The misspelling of "not-accessible" was corrected.
 * 
 * Dump of Opaque will print size, if given in the MIB.
 * 
 * Dumps work with excluded objects.  The OID list,
 * name list, and MOSY lists don't print the excluded
 * objects, dumps do.
 * 
 * Corrects print of OID value if not defined.
 * 
 * The OID list also prints the traps in the MIB.
 * 
 *    Rev 1.0   27 May 1992 16:16:34   gfoster
 * Initial revision.
 *
*/

#include <stdio.h>

#ifdef MS_DOS
#include <stdlib.h>
#endif /* MS_DOS */

#include <string.h>

#include "tds.h"
#include "smscdefs.h"
#include "smstdefs.h"
#include "smsydefs.h"
#include "smic.h"

PSZ extMosySYN(MIBSYN *pSyn);

/** oidType - return values of OID type
*
* call with:
*   usOType
*
* returns:
*   ptr to name of type
*/
    PSZ
#ifdef __STDC__
oidType(USHORT usOType)
#else
oidType(usOType)
    USHORT usOType;
#endif /* __STDC__ */
{
    switch(usOType) {
    case MIBOToid:
        return("oid");
    case MIBOTtab:
        return("table");
    case MIBOTrow:
        return("row");
    case MIBOTobj:
        return("object");
    case MIBOTunk:
        return("**unknown or bad**");
    default:
        sprintf(szBuf, "**unknown type(%d)**", usOType);
        return(&szBuf[0]);
    }
} /* oidType */


/** accessType - return values of access
*
* call with:
*   usAccess - access type
*
* returns:
*   ptr to name of type
*/
    PSZ
#ifdef __STDC__
accessType(USHORT usAccess)
#else
accessType(usAccess)
    USHORT usAccess;
#endif /* __STDC__ */
{
    switch(usAccess) {
    case MIBACCnu:
        return("not used");
    case MIBACCbad:
        return("**bad**");
    case MIBACCro:
        return("read-only");
    case MIBACCrw:
        return("read-write");
    case MIBACCwo:
        return("write-only");
    case MIBACCna:
        return("not-accessible");
    default:
        sprintf(szBuf, "**unknown access(%d)**", usAccess);
        return(&szBuf[0]);
    }
} /* accessType */


/** dumpSYN - dump syntax info
*
* call with:
*   pSyn - syntax info
*/
    VOID
#ifdef __STDC__
dumpSYN(MIBSYN *pSyn)
#else
dumpSYN(pSyn)
    MIBSYN *pSyn;
#endif /* __STDC__ */
{
    MIBENUM *pEnum;


    switch(pSyn->usSyntax) {
    case MIBSYNnu:
        fprintf(fhOut, "  **syntax not used\n");
        break;
    case MIBSYNbad:
        fprintf(fhOut, "  **bad syntax\n");
        break;
    case MIBSYNint:
        fprintf(fhOut, "  INTEGER%s\n", dumpSR(pSyn));
        break;
    case MIBSYNoctstr:
        fprintf(fhOut, "  OCTET STRING%s\n", dumpSR(pSyn));
        break;
    case MIBSYNoid:
        fprintf(fhOut, "  OBJECT IDENTIFIER\n");
        break;
    case MIBSYNnull:
        fprintf(fhOut, "  NULL\n");
        break;
    case MIBSYNnaddr:
        fprintf(fhOut, "  NetworkAddress\n");
        break;
    case MIBSYNipaddr:
        fprintf(fhOut, "  IpAddress\n");
        break;
    case MIBSYNcntr:
        fprintf(fhOut, "  Counter\n");
        break;
    case MIBSYNgauge:
        fprintf(fhOut, "  Gauge\n");
        break;
    case MIBSYNticks:
        fprintf(fhOut, "  TimeTicks\n");
        break;
    case MIBSYNopaque:
        fprintf(fhOut, "  Opaque%s\n", dumpSR(pSyn));
        break;
    case MIBSYNenum:
        fprintf(fhOut, "  enum(%u):\n", pSyn->cEnum);
        for (pEnum = pSyn->usi.pEnumL; pEnum != NULL; pEnum = pEnum->pNext) {
            fprintf(fhOut, "    %s(%lu)\n", pEnum->pszName, pEnum->ulVal);
        }
        break;
    case MIBSYNseqOf:
        fprintf(fhOut, "  SEQUENCE OF \"%s\"\n", (pSyn->usi.pSeq)->pszName);
        break;
    case MIBSYNseq:
        fprintf(fhOut, "  SEQUENCE \"%s\"\n", (pSyn->usi.pSeq)->pszName);
        break;
    case MIBSYNtc:
        fprintf(fhOut, "  [%s%s]->",
                (pSyn->usi.pTC)->pszName, dumpSR(pSyn));
        dumpSYN(&(pSyn->usi.pTC)->ut.tc.syn);
        break;
    default:
        fprintf(fhOut, "**unknown value(%d)\n", pSyn->usSyntax);
        break;
    }
} /* dumpSYN */


/** prInst - print encoding for instance
*
* call with:
*  pIndx - list of index items
*
*/
    VOID
#ifdef __STDC__
prInst(MIBINDX *pIndx)
#else
prInst(pIndx)
    MIBINDX *pIndx;
#endif /* __STDC__ */
{
    USHORT i;
    USHORT n;

    
    fprintf(fhOut, "  instance encoding: ");
    while(pIndx != NULL) {
        switch (pIndx->usItype) {
        case MIBITbad:  /* bad index item */
            fprintf(fhOut, ".**BAD**");
            break;

        case MIBITobj:  /* index item is an object */
        case MIBITnlobj:/* index item is no length object */
            if ((pIndx->pOid)->ut.oid.usOType != MIBOTobj) {
                fprintf(fhOut, ".**bad**");
                break;
            }
            switch ((pIndx->pOid)->ut.oid.rsyn.usSyntax) {
            case MIBSYNnu:      /* not used */
            case MIBSYNbad:     /* invalid syntax specified */
            case MIBSYNnull:    /* NULL */
            case MIBSYNopaque:  /* opaque */
            case MIBSYNseqOf:   /* sequence of (table) */
            case MIBSYNseq:     /* sequence (row) */
            case MIBSYNtc:      /* textual convention */
            default:
                fprintf(fhOut, ".**BAD**");
                break;

            case MIBSYNint:     /* integer */
            case MIBSYNcntr:    /* counter */
            case MIBSYNgauge:   /* gauge */
            case MIBSYNticks:   /* timer tics */
            case MIBSYNenum:    /* enumerated */
                fprintf(fhOut, ".<int>");
                break;

            case MIBSYNoctstr:  /* octet string */
                if ((pIndx->pOid)->ut.oid.rsyn.usSizeRange == MIBSRfs) {
                    /* fixed size string */
                    for (i = 0, n = (pIndx->pOid)->ut.oid.rsyn.usr.usSize[0]; i < n; i++) {
                        fprintf(fhOut, ".<oct%d>", i+1);
                    }
                } else if (((pIndx->pOid)->ut.oid.rsyn.usSizeRange == MIBSRvs) ||
                            ((pIndx->pOid)->ut.oid.rsyn.usSizeRange == MIBSRno)) {
                    /* variable size */
                    if (pIndx->usItype == MIBITobj)
                        fprintf(fhOut, ".<len><com_per_octet>");
                    else
                        fprintf(fhOut, "<com_per_octet>");
                } else {
                    /* a problem */
                    fprintf(fhOut, ".***BAD***");
                }
                break;

            case MIBSYNoid:     /* object identifier */
                if (pIndx->usItype == MIBITobj)
                    fprintf(fhOut, ".<len>.<com_per_oid_com>");
                else
                    fprintf(fhOut, ".<com_per_oid_com>");
                break;

            case MIBSYNnaddr:   /* network address */
                fprintf(fhOut, ".<1>.<ip1>.<ip2>.<ip3>.<ip4>");
                break;

            case MIBSYNipaddr:  /* IP address */
                fprintf(fhOut, ".<ip1>.<ip2>.<ip3>.<ip4>");
                break;
            }
            break;

        case MIBITint:  /* index item is INTEGER */
            fprintf(fhOut, ".<int>");
            break;

        case MIBIToct:  /* index item is OCTET STRING */
            fprintf(fhOut, ".<len>.<com_per_octet>");
            break;

        case MIBITnloct:/* index item is no length OCTET STRING */
            fprintf(fhOut, ".<com_per_oct>");
            break;

        case MIBITfloct:/* index item is fixed length OCTET STRING */
            for (i = 0, n = (USHORT)(pIndx->ulLow); i < n; i++) {
                fprintf(fhOut, ".<oct%d>", i+1);
            }
            break;

        case MIBIToid:  /* index item is OBJECT IDENTIFIER */
            fprintf(fhOut, ".<len>.<com_per_oid_com>");
            break;

        case MIBITnloid:/* index item is no length OID */
            fprintf(fhOut, "<com_per_oid_com>");
            break;

        case MIBITnaddr:/* index item is NetworkAddress */
            fprintf(fhOut, ".<1>.<ip1>.<ip2>.<ip3>.<ip4>");
            break;

        case MIBITipaddr:/* index item is IpAddress */
            fprintf(fhOut, ".<ip1>.<ip2>.<ip3>.<ip4>");
            break;

        default:
            fprintf(fhOut, "**unknown type %d**",
                    pIndx->usItype);
            break;
        }

        pIndx = pIndx->pNext;
    }

    fprintf(fhOut, "\n");

} /* prInst */


/** prIndx - print index list
*
* call with:
*  cIndx - number of items in list
*  pIndx - list of index items
*
*/
    VOID
#ifdef __STDC__
prIndx(USHORT cIndx, MIBINDX *pIndx)
#else
prIndx(cIndx, pIndx)
    USHORT cIndx;
    MIBINDX *pIndx;
#endif /* __STDC__ */
{
    fprintf(fhOut, "  indices(%d):\n", cIndx);
    while (pIndx != NULL) {
        switch (pIndx->usItype) {
        case MIBITbad:  /* bad index item */
            fprintf(fhOut, "    **BAD**\n");
            break;

        case MIBITobj:  /* index item is an object */
            fprintf(fhOut, "    %s\n", (pIndx->pOid)->pszName);
            break;

        case MIBITnlobj:/* index item is no length object */
            fprintf(fhOut, "    NOLENGTH %s\n", (pIndx->pOid)->pszName);
            break;

        case MIBITint:  /* index item is INTEGER */
            if ((pIndx->ulLow == 0L) &&
                    (pIndx->ulHigh == 0xFFFFFFFFL))
                fprintf(fhOut, "    INTEGER\n");
            else
                fprintf(fhOut, "    INTEGER (%lu..%lu)\n",
                        pIndx->ulLow, pIndx->ulHigh);
            break;

        case MIBIToct:  /* index item is OCTET STRING */
            if ((pIndx->ulLow == 0L) &&
                    (pIndx->ulHigh == 0L))
                fprintf(fhOut, "    OCTET STRING\n");
            else
                fprintf(fhOut, "    OCTET STRING (SIZE(%lu..%lu))\n",
                        pIndx->ulLow, pIndx->ulHigh);
            break;

        case MIBITnloct:/* index item is no length OCTET STRING */
            if ((pIndx->ulLow == 0L) &&
                    (pIndx->ulHigh == 0L))
                fprintf(fhOut, "    NOLENGTH OCTET STRING\n");
            else
                fprintf(fhOut, "    NOLENGTH OCTET STRING (SIZE(%lu..%lu))\n",
                        pIndx->ulLow, pIndx->ulHigh);
            break;

        case MIBITfloct:/* index item is fixed length OCTET STRING */
            fprintf(fhOut, "    OCTET STRING (SIZE(%lu))\n",
                    pIndx->ulLow);
            break;

        case MIBIToid:  /* index item is OBJECT IDENTIFIER */
            fprintf(fhOut, "    OBJECT IDENTIFIER\n");
            break;

        case MIBITnloid:/* index item is no length OID */
            fprintf(fhOut, "    NOLENGTH OBJECT IDENTIFIER\n");
            break;

        case MIBITnaddr:/* index item is NetworkAddress */
            fprintf(fhOut, "    NetworkAddress\n");
            break;

        case MIBITipaddr:/* index item is IpAddress */
            fprintf(fhOut, "    IpAddress\n");
            break;

        default:
            fprintf(fhOut, "    **unknown type %d**\n",
                    pIndx->usItype);
            break;
        }
        pIndx = pIndx->pNext;
    }

} /* prIndx */


/** dumpOID - dump OID info
*
*/
    VOID
#ifdef __STDC__
dumpOID(VOID)
#else
dumpOID()
#endif /* __STDC__ */
{
    USHORT i;
    USHORT j;
    MIBSYM *pT;


    fprintf(fhOut, "\nOID object info\n");

    for (pT = pOidAvail, i = 0; pT != NULL; pT = pT->pNext) {
        i++;
    }
    fprintf(fhOut, "%d of %d oid objects in avail list\n", i, MIBOIDACT);

    for (pT = pOidGHL, i = 0, j = 0; pT != NULL; pT = pT->pNext) {
        i++;
        if (pT->usNeed == MIBIEex)
            j++;
    }
    fprintf(fhOut, "%d oid objects specified\n", i);
    if (j != 0)
        fprintf(fhOut, "%d oid objects excluded\n", j);


    for (pT = pOidGHL, i = 0; pT != NULL; pT = pT->pNext) {
        i++;
        dumpSYM((MIBSYM *)pT);
        if (pT->ut.oid.fDup)
            fprintf(fhOut, "  **has dup**\n");
        fprintf(fhOut, "  type: %s\n",
                oidType(pT->ut.oid.usOType));
        if ((pT->ut.oid.pPar == NULL) &&
                (pT->ut.oid.ulVal == 0xFFFFFFFFL))
            fprintf(fhOut, "  val: --not defined--\n");
        else
            fprintf(fhOut, "  val: %s.%lu\n", 
                    (pT->ut.oid.pPar == NULL) ?
                        "--none--" : (pT->ut.oid.pPar)->pszName,
                                    pT->ut.oid.ulVal);
        switch(pT->ut.oid.usOType) {
        case MIBOToid:

⌨️ 快捷键说明

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