home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / manage / snmp / mit / smptest / smptest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-17  |  3.6 KB  |  175 lines

  1.  
  2. /*
  3.  *    $Header: smptest.c,v 3.0 91/05/17 16:15:21 jrd Rel $
  4.  *    Author: J. Davin
  5.  *    Copyright 1988, 1989, Massachusetts Institute of Technology
  6.  *    See permission and disclaimer notice in file "notice.h"
  7.  */
  8.  
  9. #include    <notice.h>
  10.  
  11. #include    <strings.h>
  12.  
  13. #include    <ctypes.h>
  14. #include    <rdx.h>
  15. #include    <debug.h>
  16. #include    <smp.h>
  17. #include    <smx.h>
  18. #include    <mis.h>
  19. #include    <miv.h>
  20. #include    <aps.h>
  21. #include    <avl.h>
  22. #include    <ap0.h>
  23. #include    <asn.h>
  24.  
  25. #define        cmdStringSize        (32)
  26.  
  27. ApsIdType    smpPublic;
  28.  
  29. CIntlType    smpVar0;
  30. CIntlType    smpVar1;
  31. CUnslType    smpVar2;
  32. CUnslType    smpVar3;
  33. CUnslType    smpVar4;
  34. CUnslType    smpVar5;
  35. CUnslType    smpVar6;
  36. CUnslType    smpVar7;
  37.  
  38. MivStrType    smpVar8;
  39. CByteType    smpBuf8 [ cmdStringSize ];
  40.  
  41. MivStrType    smpVar9;
  42. CByteType    smpBuf9 [ cmdStringSize ];
  43.  
  44. CByteType    smpVar10 [ cmdStringSize ];
  45.  
  46. static    int        mainInit ()
  47.  
  48. {
  49.     aslInit ();
  50.     asnInit ();
  51.     misInit ();
  52.     avlInit ();
  53.     mixInit ();
  54.     apsInit ();
  55.     ap0Init ();
  56.     smpInit ();
  57.  
  58.     (void) mivIntlRW ((MixNamePtrType) "\53\6\1\2\1\1\0",
  59.         (MixLengthType) 7, & smpVar0);
  60.     smpVar0 = (CIntlType) 7;
  61.     (void) mivIntlRW ((MixNamePtrType) "\53\6\1\2\1\1\1",
  62.         (MixLengthType) 7, & smpVar1);
  63.     smpVar1 = (CIntlType) -7;
  64.  
  65.     (void) mivUnslRW ((MixNamePtrType) "\53\6\1\2\1\1\2",
  66.         (MixLengthType) 7, & smpVar2);
  67.     smpVar2 = (CUnslType) 8;
  68.     (void) mivUnslRW ((MixNamePtrType) "\53\6\1\2\1\1\3",
  69.         (MixLengthType) 7, & smpVar3);
  70.     smpVar3 = (CUnslType) -8;
  71.  
  72.     (void) mivCounterRW ((MixNamePtrType) "\53\6\1\2\1\1\4",
  73.         (MixLengthType) 7, & smpVar4);
  74.     smpVar4 = (CUnslType) 9;
  75.     (void) mivCounterRW ((MixNamePtrType) "\53\6\1\2\1\1\5",
  76.         (MixLengthType) 7, & smpVar5);
  77.     smpVar5 = (CUnslType) -9;
  78.  
  79.     (void) mivGuageRW ((MixNamePtrType) "\53\6\1\2\1\1\6",
  80.         (MixLengthType) 7, & smpVar6);
  81.     smpVar6 = (CUnslType) 10;
  82.     (void) mivGuageRW ((MixNamePtrType) "\53\6\1\2\1\1\7",
  83.         (MixLengthType) 7, & smpVar7);
  84.     smpVar7 = (CUnslType) -10;
  85.  
  86.     (void) mivStringRW ((MixNamePtrType) "\53\6\1\2\1\1\8",
  87.         (MixLengthType) 7, & smpVar8);
  88.     (void) strcpy ((char *) smpBuf8, "hello, world!");
  89.     smpVar8.mivStrData = smpBuf8;
  90.     smpVar8.mivStrLen = (CUnsfType) strlen ((char *) smpBuf8);
  91.     smpVar8.mivStrMaxLen = (CUnsfType) cmdStringSize;
  92.  
  93.     (void) mivObjectIdRW ((MixNamePtrType) "\53\6\1\2\1\1\11",
  94.         (MixLengthType) 7, & smpVar9);
  95.     smpVar9.mivStrData = smpBuf9;
  96.     smpVar9.mivStrLen = (CUnsfType) smxTextToObjectId (smpBuf9,
  97.         (CIntfType) cmdStringSize, "1.3.6.1.2.1.1.1.0");
  98.     smpVar9.mivStrMaxLen = (CUnsfType) cmdStringSize;
  99.  
  100.     (void) mivIPAddrRW ((MixNamePtrType) "\53\6\1\2\1\1\12",
  101.         (MixLengthType) 7, smpVar10);
  102.     (void) smxTextToIPAddr (smpVar10, (CIntfType) cmdStringSize,
  103.         "18.26.0.99");
  104.  
  105.     smpPublic = apsNew ((ApsNameType) "public", (ApsNameType) "trivial",
  106.         (ApsGoodiesType) 0);
  107.     return (0);
  108. }
  109.  
  110. static    SmpStatusType    mySend (s, cp, n)
  111.  
  112. SmpSocketType        s;
  113. CBytePtrType        cp;
  114. CIntfType        n;
  115.  
  116. {
  117.     printf ("mySend:\n");
  118.     s = s;
  119.     while (n-- > 0) {
  120.         printf ("%02.02X ", *cp++);
  121.     }
  122.     printf ("\n");
  123.     return (errOk);
  124. }
  125.  
  126. int    main (argc, argv)
  127.  
  128. int    argc;
  129. char    *argv [];
  130.  
  131. {
  132.     SmpIdType        smp;
  133.     SmpStatusType        status;
  134.     CByteType        buf [ 512 ];
  135.     CBytePtrType        cp;
  136.     CIntfType        i;
  137.     CUnslType        number;
  138.  
  139.     cp = buf;
  140.     for (i = 1; i < (CIntfType) argc; i++) {
  141.         (void) rdxDecodeAny (& number, argv [ i ]);
  142.         *cp++ = (CByteType) number;
  143.     }
  144.  
  145.     (void) mainInit ();
  146.  
  147.     smp = smpNew ((SmpSocketType) 0, mySend, (SmpHandlerType) 0);
  148.  
  149.     status = errOk;
  150.     cp = buf;
  151.     for (i = 1; ((status == errOk) && (i < (CIntfType) argc)); i++) {
  152.         status = smpInput (smp, *cp);
  153.         DEBUG2 ("%02.02X %d\n", (unsigned) *cp, status);
  154.         cp++;
  155.     }
  156.  
  157.     switch (status) {
  158.  
  159.     case errOk:
  160.         DEBUG0 ("++OK\n");
  161.         break;
  162.  
  163.     case errBad:
  164.         DEBUG0 ("++BAD\n");
  165.         break;
  166.  
  167.     default:
  168.         DEBUG0 ("++Panic\n");
  169.         break;
  170.     }
  171.  
  172.     smp = smpFree (smp);
  173.     exit (0);
  174. }
  175.