home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / netramet / part21 < prev    next >
Encoding:
Text File  |  1993-11-08  |  64.0 KB  |  2,127 lines

  1. Newsgroups: comp.sources.misc
  2. From: nevil@ccu1.aukuni.ac.nz (J Nevil Brownlee)
  3. Subject: v40i109:  netramet - Network Traffic Accounting Meter, Part21/25
  4. Message-ID: <1993Nov9.020449.18834@sparky.sterling.com>
  5. X-Md4-Signature: 28aba8417d577895b6709cdf839bc849
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Tue, 9 Nov 1993 02:04:49 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: nevil@ccu1.aukuni.ac.nz (J Nevil Brownlee)
  12. Posting-number: Volume 40, Issue 109
  13. Archive-name: netramet/part21
  14. Environment: INET, UNIX, DOS
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  netramet/examples/rules.sample
  21. #   netramet/src/apps/snmpnetstat/if.c netramet/src/apps/snmpstatus.c
  22. #   netramet/src/apps/snmptest.c netramet/src/manager/nmc_pars.c
  23. #   netramet/src/snmplib/snmpclnt.c
  24. # Wrapped by kent@sparky on Tue Nov  2 18:17:12 1993
  25. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  26. echo If this archive is complete, you will see the following message:
  27. echo '          "shar: End of archive 21 (of 25)."'
  28. if test -f 'netramet/examples/rules.sample' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'netramet/examples/rules.sample'\"
  30. else
  31.   echo shar: Extracting \"'netramet/examples/rules.sample'\" \(3166 characters\)
  32.   sed "s/^X//" >'netramet/examples/rules.sample' <<'END_OF_FILE'
  33. X#  1705, Mon 13 Sep 93
  34. X#
  35. X#  Rule specification file to tally IP net <-> IP net,
  36. X#     tally DECnet and Novell and aggregate EtherTalk
  37. X#
  38. X#  Nevil Brownlee,  Computer Centre,  University of Auckland
  39. X#
  40. XSET 2  # Rule + action set number 2
  41. X#
  42. XRULES
  43. X#
  44. XSourcePeerType & 255 = DECnet :         Tally,  9;  #   1
  45. XSourcePeerType & 255 = IP.0.0.0 :      Pushto,  8;  #   2
  46. XSourcePeerType & 255 = EtherTalk :  Aggregate,  7;  #   3
  47. XSourcePeerType & 255 = Novell :         Tally,  8;  #   4
  48. XNull & 0 = 0 :                        Succeed,  0;  #   5  Ignore
  49. X#
  50. XNull & 0 = 0 :                        Succeed,  0;  #   6
  51. XNull & 0 = 0 :                        Succeed,  0;  #   7
  52. X#
  53. X#  IP ...
  54. X#
  55. XSourcePeerAddress & 192.0.0.0 = 128.0.0.0 :  Pushto, 13;  #   8  Low B
  56. XSourcePeerAddress & 192.0.0.0 = 192.0.0.0 :  Pushto, 16;  #   9  Low C
  57. XSourcePeerAddress & 192.0.0.0 = 64.0.0.0 :   Pushto, 18;  #  10  Low A
  58. XSourcePeerAddress & 192.0.0.0 = 0.0.0.0 :    Pushto, 18;  #  11  Low A
  59. XNull & 0 = 0 :                                 Fail,  0;  #  12
  60. X#
  61. XDestPeerAddress & 192.0.0.0 = 128.0.0.0 :     Tally,  1;  #  13  High B: B-B
  62. XDestPeerAddress & 192.0.0.0 = 192.0.0.0 :     Tally,  2;  #  14  High C: B-C
  63. XNull & 0 = 0 :                                 Fail,  0;  #  15
  64. X#
  65. XDestPeerAddress & 192.0.0.0 = 192.0.0.0 :     Tally,  3;  #  16  High C: C-C
  66. XNull & 0 = 0 :                                 Fail,  0;  #  17
  67. X#
  68. XDestPeerAddress & 192.0.0.0 = 128.0.0.0 :    Tally,   4;  #  18  High B: A-B
  69. XDestPeerAddress & 192.0.0.0 = 192.0.0.0 :    Tally,   5;  #  19  High C: A-C
  70. XDestPeerAddress & 192.0.0.0 = 64.0.0.0 :     Tally,   6;  #  20  High A: A-A
  71. XDestPeerAddress & 192.0.0.0 = 0.0.0.0 :      Tally,   6;  #  21  High A: A-A
  72. XNull & 0 = 0 :                                 Fail,  0;  #  22
  73. X#
  74. XNull & 0 = 0 :                                 Fail,  0;  #  23
  75. XNull & 0 = 0 :                                 Fail,  0;  #  24
  76. X#
  77. XACTIONS
  78. X#
  79. XSourcePeerType=IP, SourcePeerMask=255.255.0.0,   
  80. X                   DestPeerMask=255.255.0.0;            # 1  B-B
  81. XSourcePeerType=IP, SourcePeerMask=255.255.0.0,   
  82. X                   DestPeerMask=255.255.255.0;          # 2  B-C
  83. XSourcePeerType=IP, SourcePeerMask=255.255.255.0, 
  84. X                   DestPeerMask=255.255.255.0;          # 3  C-C
  85. XSourcePeerType=IP, SourcePeerMask=255.0.0.0,     
  86. X                   DestPeerMask=255.255.0.0;            # 4  A-B
  87. XSourcePeerType=IP, SourcePeerMask=255.0.0.0,     
  88. X                   DestPeerMask=255.255.255.0;          # 5  A-C
  89. XSourcePeerType=IP, SourcePeerMask=255.0.0.0,     
  90. X                   DestPeerMask=255.0.0.0;              # 6  A-A
  91. X#
  92. XSourcePeerType=EtherTalk, 
  93. X   SourcePeerAddress=1.0.0.0, SourcePeerMask=255.0.0.0,
  94. X   DestPeerAddress=1.0.0.0, DestPeerMask=255.0.0.0;     # 7  Aggregate
  95. X#
  96. XSourcePeerType=Novell, SourcePeerMask=255.255.255.255, 
  97. X                       DestPeerMask=255.255.255.255;    # 8  Tally all
  98. XSourcePeerType=DECnet, SourcePeerMask=255.255.255.0, 
  99. X                       DestPeerMask=255.255.255.0;      # 9  Tally all
  100. X#
  101. XFORMAT FlowRuleSet FlowIndex FirstTime "  "
  102. X   SourcePeerType SourcePeerAddress DestPeerAddress "  "
  103. X   ToPDUs FromPDUs "  " ToOctets FromOctets;
  104. X#
  105. X# end of file
  106. END_OF_FILE
  107.   if test 3166 -ne `wc -c <'netramet/examples/rules.sample'`; then
  108.     echo shar: \"'netramet/examples/rules.sample'\" unpacked with wrong size!
  109.   fi
  110.   # end of 'netramet/examples/rules.sample'
  111. fi
  112. if test -f 'netramet/src/apps/snmpnetstat/if.c' -a "${1}" != "-c" ; then 
  113.   echo shar: Will not clobber existing file \"'netramet/src/apps/snmpnetstat/if.c'\"
  114. else
  115.   echo shar: Extracting \"'netramet/src/apps/snmpnetstat/if.c'\" \(9741 characters\)
  116.   sed "s/^X//" >'netramet/src/apps/snmpnetstat/if.c' <<'END_OF_FILE'
  117. X/***********************************************************
  118. X    Copyright 1989 by Carnegie Mellon University
  119. X
  120. X                      All Rights Reserved
  121. X
  122. XPermission to use, copy, modify, and distribute this software and its 
  123. Xdocumentation for any purpose and without fee is hereby granted, 
  124. Xprovided that the above copyright notice appear in all copies and that
  125. Xboth that copyright notice and this permission notice appear in 
  126. Xsupporting documentation, and that the name of CMU not be
  127. Xused in advertising or publicity pertaining to distribution of the
  128. Xsoftware without specific, written prior permission.  
  129. X
  130. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  131. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  132. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  133. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  134. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  135. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  136. XSOFTWARE.
  137. X******************************************************************/
  138. X/*
  139. X * Copyright (c) 1983,1988 Regents of the University of California.
  140. X * All rights reserved.
  141. X *
  142. X * Redistribution and use in source and binary forms are permitted
  143. X * provided that this notice is preserved and that due credit is given
  144. X * to the University of California at Berkeley. The name of the University
  145. X * may not be used to endorse or promote products derived from this
  146. X * software without specific prior written permission. This software
  147. X * is provided ``as is'' without express or implied warranty.
  148. X */
  149. X
  150. X#include <sys/types.h>
  151. X#include <sys/socket.h>
  152. X
  153. X#include <netinet/in.h>
  154. X
  155. X#include <stdio.h>
  156. X#include <signal.h>
  157. X
  158. X#include "ausnmp.h"
  159. X#include "main.h"
  160. X#include "asn1.h"
  161. X#include "snmp.h"
  162. X#include "snmpimpl.h"
  163. X#include "snmpapi.h"
  164. X#include "snmpclnt.h"
  165. X#include "mib.h"
  166. X
  167. X#define    YES    1
  168. X#define    NO    0
  169. X
  170. Xextern    int nflag;
  171. Xextern    char *interface;
  172. Xextern    char *routename(), *netname();
  173. Xextern    struct snmp_session *Session;
  174. Xextern    struct variable_list *getvarbyname();
  175. X
  176. Xoid oid_ifname[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 1};
  177. Xstatic oid oid_ifinucastpkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 1};
  178. Xstatic oid oid_cfg_nnets[] = {1, 3, 6, 1, 2, 1, 2, 1, 0};
  179. X
  180. X#define IFNAME        2
  181. X#define IFMTU        4
  182. X#define IFOPERSTATUS    8
  183. X#define INUCASTPKTS    11
  184. X#define INNUCASTPKTS    12
  185. X#define INERRORS    14
  186. X#define OUTUCASTPKTS    17
  187. X#define OUTNUCASTPKTS    18
  188. X#define OUTERRORS    20
  189. X
  190. X/*
  191. X * Print a description of the network interfaces.
  192. X */
  193. Xintpr(interval)
  194. X    int interval;
  195. X{
  196. X    oid varname[MAX_NAME_LEN], *instance, *ifentry;
  197. X    int varname_len;
  198. X    int ifnum, cfg_nnets;
  199. X    struct variable_list *var;
  200. X    char name[128];
  201. X    int mtu;
  202. X    int ipkts, ierrs, opkts, oerrs, operstatus, collisions;
  203. X
  204. X    if (interval) {
  205. X        sidewaysintpr((unsigned)interval);
  206. X        return;
  207. X    }
  208. X    printf("%-11.11s %-5.5s %-11.11s %-15.15s %8.8s %5.5s %8.8s %5.5s",
  209. X        "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
  210. X        "Opkts", "Oerrs");
  211. X    putchar('\n');
  212. X    var = getvarbyname(Session, oid_cfg_nnets, sizeof(oid_cfg_nnets) / sizeof(oid));
  213. X    if (var)
  214. X        cfg_nnets = *var->val.integer;
  215. X    else
  216. X        return;
  217. X    bcopy((char *)oid_ifname, (char *)varname, sizeof(oid_ifname));
  218. X    varname_len = sizeof(oid_ifname) / sizeof(oid);
  219. X    ifentry = varname + 9;
  220. X    instance = varname + 10;
  221. X    for (ifnum = 1; ifnum <= cfg_nnets; ifnum++) {
  222. X        register char *cp;
  223. X        char *index();
  224. X
  225. X        *name = mtu = 0;
  226. X        ipkts = ierrs = opkts = oerrs = operstatus = collisions = 0;
  227. X        *instance = ifnum;
  228. X        *ifentry = IFNAME;
  229. X        var = getvarbyname(Session, varname, varname_len);
  230. X        if (var){
  231. X            bcopy((char *)var->val.string, name, var->val_len);
  232. X            name[var->val_len] = 0;
  233. X        }
  234. X        *ifentry = IFMTU;
  235. X        var = getvarbyname(Session, varname, varname_len);
  236. X        if (var)
  237. X            mtu = *var->val.integer;
  238. X        *ifentry = IFOPERSTATUS;
  239. X        var = getvarbyname(Session, varname, varname_len);
  240. X        if (var)
  241. X            operstatus = *var->val.integer;
  242. X        *ifentry = INUCASTPKTS;
  243. X        var = getvarbyname(Session, varname, varname_len);
  244. X        if (var)
  245. X            ipkts = *var->val.integer;
  246. X        *ifentry = INNUCASTPKTS;
  247. X        var = getvarbyname(Session, varname, varname_len);
  248. X        if (var)
  249. X            ipkts += *var->val.integer;
  250. X        *ifentry = INERRORS;
  251. X        var = getvarbyname(Session, varname, varname_len);
  252. X        if (var)
  253. X            ierrs = *var->val.integer;
  254. X        *ifentry = OUTUCASTPKTS;
  255. X        var = getvarbyname(Session, varname, varname_len);
  256. X        if (var)
  257. X            opkts = *var->val.integer;
  258. X        *ifentry = OUTNUCASTPKTS;
  259. X        var = getvarbyname(Session, varname, varname_len);
  260. X        if (var)
  261. X            opkts += *var->val.integer;
  262. X        *ifentry = OUTERRORS;
  263. X        var = getvarbyname(Session, varname, varname_len);
  264. X        if (var)
  265. X            oerrs = *var->val.integer;
  266. X
  267. X        name[15] = '\0';
  268. X        if (interface != 0 &&
  269. X            strcmp(name, interface) != 0)
  270. X            continue;
  271. X        cp = index(name, '\0');
  272. X        if (operstatus != MIB_IFSTATUS_UP)
  273. X            *cp++ = '*';
  274. X        *cp = '\0';
  275. X        printf("%-11.11s %-5d ", name, mtu);
  276. X        printf("%-11.11s ", "none");
  277. X        printf("%-15.15s ", "none");
  278. X        printf("%8d %5d %8d %5d %5d",
  279. X            ipkts, ierrs,
  280. X            opkts, oerrs, collisions);
  281. X        putchar('\n');
  282. X    }
  283. X}
  284. X
  285. X#define    MAXIF    10
  286. Xstruct    iftot {
  287. X    char    ift_name[128];        /* interface name */
  288. X    int    ift_ip;            /* input packets */
  289. X    int    ift_ie;            /* input errors */
  290. X    int    ift_op;            /* output packets */
  291. X    int    ift_oe;            /* output errors */
  292. X    int    ift_co;            /* collisions */
  293. X} iftot[MAXIF];
  294. X
  295. Xu_char    signalled;            /* set if alarm goes off "early" */
  296. X
  297. X/*
  298. X * Print a running summary of interface statistics.
  299. X * Repeat display every interval seconds, showing statistics
  300. X * collected over that interval.  Assumes that interval is non-zero.
  301. X * First line printed at top of screen is always cumulative.
  302. X */
  303. Xsidewaysintpr(interval)
  304. X    unsigned interval;
  305. X{
  306. X    register struct iftot *ip, *total;
  307. X    register int line;
  308. X    struct iftot *lastif, *sum, *interesting, ifnow, *now = &ifnow;
  309. X    int oldmask;
  310. X    int catchalarm();
  311. X    struct variable_list *var;
  312. X    oid varname[MAX_NAME_LEN], *instance, *ifentry;
  313. X    int varname_len;
  314. X    int ifnum, cfg_nnets;
  315. X    char *index();
  316. X
  317. X    lastif = iftot;
  318. X    sum = iftot + MAXIF - 1;
  319. X    total = sum - 1;
  320. X    interesting = iftot;
  321. X    var = getvarbyname(Session, oid_cfg_nnets, sizeof(oid_cfg_nnets) / sizeof(oid));
  322. X    if (var)
  323. X        cfg_nnets = *var->val.integer;
  324. X    else
  325. X        return;
  326. X    bcopy((char *)oid_ifname, (char *)varname, sizeof(oid_ifname));
  327. X    varname_len = sizeof(oid_ifname) / sizeof(oid);
  328. X    for (ifnum = 1, ip = iftot; ifnum <= cfg_nnets; ifnum++) {
  329. X        char *cp;
  330. X
  331. X        ip->ift_name[0] = '(';
  332. X        varname[10] = ifnum;
  333. X        var = getvarbyname(Session, varname, varname_len);
  334. X        if (var){
  335. X            bcopy((char *)var->val.string, ip->ift_name + 1, var->val_len);
  336. X        }
  337. X        if (interface && strcmp(ip->ift_name + 1, interface) == 0)
  338. X            interesting = ip;
  339. X        ip->ift_name[15] = '\0';
  340. X        cp = index(ip->ift_name, '\0');
  341. X        sprintf(cp, ")");
  342. X        ip++;
  343. X        if (ip >= iftot + MAXIF - 2)
  344. X            break;
  345. X    }
  346. X    lastif = ip;
  347. X
  348. X    (void)signal(SIGALRM, catchalarm);
  349. X    signalled = NO;
  350. X    (void)alarm(interval);
  351. Xbanner:
  352. X    printf("    input   %-6.6s    output       ", interesting->ift_name);
  353. X    if (lastif - iftot > 0)
  354. X        printf("     input  (Total)    output");
  355. X    for (ip = iftot; ip < iftot + MAXIF; ip++) {
  356. X        ip->ift_ip = 0;
  357. X        ip->ift_ie = 0;
  358. X        ip->ift_op = 0;
  359. X        ip->ift_oe = 0;
  360. X        ip->ift_co = 0;
  361. X    }
  362. X    putchar('\n');
  363. X    printf("%8.8s %5.5s %8.8s %5.5s %5.5s ",
  364. X        "packets", "errs", "packets", "errs", "colls");
  365. X    if (lastif - iftot > 0)
  366. X        printf("%8.8s %5.5s %8.8s %5.5s %5.5s ",
  367. X            "packets", "errs", "packets", "errs", "colls");
  368. X    putchar('\n');
  369. X    fflush(stdout);
  370. X    line = 0;
  371. Xloop:
  372. X    sum->ift_ip = 0;
  373. X    sum->ift_ie = 0;
  374. X    sum->ift_op = 0;
  375. X    sum->ift_oe = 0;
  376. X    sum->ift_co = 0;
  377. X    bcopy((char *)oid_ifinucastpkts, (char *)varname, sizeof(oid_ifinucastpkts));
  378. X    varname_len = sizeof(oid_ifinucastpkts) / sizeof(oid);
  379. X    ifentry = varname + 9;
  380. X    instance = varname + 10;
  381. X    for (ifnum = 1, ip = iftot; ifnum <= cfg_nnets && ip < lastif; ip++, ifnum++) {
  382. X        bzero((char *)now, sizeof(*now));
  383. X        *instance = ifnum;
  384. X        *ifentry = INUCASTPKTS;
  385. X        var = getvarbyname(Session, varname, varname_len);
  386. X        if (var)
  387. X            now->ift_ip = *var->val.integer;
  388. X        *ifentry = INNUCASTPKTS;
  389. X        var = getvarbyname(Session, varname, varname_len);
  390. X        if (var)
  391. X            now->ift_ip += *var->val.integer;
  392. X        *ifentry = INERRORS;
  393. X        var = getvarbyname(Session, varname, varname_len);
  394. X        if (var)
  395. X            now->ift_ie = *var->val.integer;
  396. X        *ifentry = OUTUCASTPKTS;
  397. X        var = getvarbyname(Session, varname, varname_len);
  398. X        if (var)
  399. X            now->ift_op = *var->val.integer;
  400. X        *ifentry = OUTNUCASTPKTS;
  401. X        var = getvarbyname(Session, varname, varname_len);
  402. X        if (var)
  403. X            now->ift_op += *var->val.integer;
  404. X        *ifentry = OUTERRORS;
  405. X        var = getvarbyname(Session, varname, varname_len);
  406. X        if (var)
  407. X            now->ift_oe = *var->val.integer;
  408. X
  409. X        if (ip == interesting)
  410. X            printf("%8d %5d %8d %5d %5d ",
  411. X                now->ift_ip - ip->ift_ip,
  412. X                now->ift_ie - ip->ift_ie,
  413. X                now->ift_op - ip->ift_op,
  414. X                now->ift_oe - ip->ift_oe,
  415. X                now->ift_co - ip->ift_co);
  416. X        ip->ift_ip = now->ift_ip;
  417. X        ip->ift_ie = now->ift_ie;
  418. X        ip->ift_op = now->ift_op;
  419. X        ip->ift_oe = now->ift_oe;
  420. X        ip->ift_co = now->ift_co;
  421. X        sum->ift_ip += ip->ift_ip;
  422. X        sum->ift_ie += ip->ift_ie;
  423. X        sum->ift_op += ip->ift_op;
  424. X        sum->ift_oe += ip->ift_oe;
  425. X        sum->ift_co += ip->ift_co;
  426. X    }
  427. X    if (lastif - iftot > 0)
  428. X        printf("%8d %5d %8d %5d %5d ",
  429. X            sum->ift_ip - total->ift_ip,
  430. X            sum->ift_ie - total->ift_ie,
  431. X            sum->ift_op - total->ift_op,
  432. X            sum->ift_oe - total->ift_oe,
  433. X            sum->ift_co - total->ift_co);
  434. X    *total = *sum;
  435. X    putchar('\n');
  436. X    fflush(stdout);
  437. X    line++;
  438. X    oldmask = sigblock(sigmask(SIGALRM));
  439. X    if (! signalled) {
  440. X        sigpause(0);
  441. X    }
  442. X    sigsetmask(oldmask);
  443. X    signalled = NO;
  444. X    (void)alarm(interval);
  445. X    if (line == 21)
  446. X        goto banner;
  447. X    goto loop;
  448. X    /*NOTREACHED*/
  449. X}
  450. X
  451. X/*
  452. X * Called if an interval expires before sidewaysintpr has completed a loop.
  453. X * Sets a flag to not wait for the alarm.
  454. X */
  455. Xcatchalarm()
  456. X{
  457. X    signalled = YES;
  458. X}
  459. END_OF_FILE
  460.   if test 9741 -ne `wc -c <'netramet/src/apps/snmpnetstat/if.c'`; then
  461.     echo shar: \"'netramet/src/apps/snmpnetstat/if.c'\" unpacked with wrong size!
  462.   fi
  463.   # end of 'netramet/src/apps/snmpnetstat/if.c'
  464. fi
  465. if test -f 'netramet/src/apps/snmpstatus.c' -a "${1}" != "-c" ; then 
  466.   echo shar: Will not clobber existing file \"'netramet/src/apps/snmpstatus.c'\"
  467. else
  468.   echo shar: Extracting \"'netramet/src/apps/snmpstatus.c'\" \(9974 characters\)
  469.   sed "s/^X//" >'netramet/src/apps/snmpstatus.c' <<'END_OF_FILE'
  470. X/*
  471. X * snmpstatus.c - send snmp GET requests to a network entity.
  472. X *
  473. X */
  474. X/***********************************************************
  475. X    Copyright 1988, 1989 by Carnegie Mellon University
  476. X
  477. X                      All Rights Reserved
  478. X
  479. XPermission to use, copy, modify, and distribute this software and its 
  480. Xdocumentation for any purpose and without fee is hereby granted, 
  481. Xprovided that the above copyright notice appear in all copies and that
  482. Xboth that copyright notice and this permission notice appear in 
  483. Xsupporting documentation, and that the name of CMU not be
  484. Xused in advertising or publicity pertaining to distribution of the
  485. Xsoftware without specific, written prior permission.  
  486. X
  487. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  488. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  489. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  490. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  491. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  492. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  493. XSOFTWARE.
  494. X******************************************************************/
  495. X#include <sys/types.h>
  496. X#include <netinet/in.h>
  497. X#include <stdio.h>
  498. X
  499. X#include "ausnmp.h"
  500. X#include "snmp.h"
  501. X#include "snmpimpl.h"
  502. X#include "asn1.h"
  503. X#include "snmpclnt.h"
  504. X#include "snmpapi.h"
  505. X#include "mib.h"
  506. X
  507. Xint    snmp_dump_packet = 0;
  508. X
  509. Xoid    objid_sysDescr[] = {1, 3, 6, 1, 2, 1, 1, 1, 0};
  510. Xint    length_sysDescr = sizeof(objid_sysDescr)/sizeof(oid);
  511. Xoid    objid_sysUpTime[] = {1, 3, 6, 1, 2, 1, 1, 3, 0};
  512. Xint    length_sysUpTime = sizeof(objid_sysUpTime)/sizeof(oid);
  513. Xoid    objid_ifOperStatus[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 8};
  514. Xint    length_ifOperStatus = sizeof(objid_ifOperStatus)/sizeof(oid);
  515. Xoid    objid_ifInUCastPkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 11};
  516. Xint    length_ifInUCastPkts = sizeof(objid_ifInUCastPkts)/sizeof(oid);
  517. Xoid    objid_ifInNUCastPkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 12};
  518. Xint    length_ifInNUCastPkts = sizeof(objid_ifInNUCastPkts)/sizeof(oid);
  519. Xoid    objid_ifOutUCastPkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 17};
  520. Xint    length_ifOutUCastPkts = sizeof(objid_ifOutUCastPkts)/sizeof(oid);
  521. Xoid    objid_ifOutNUCastPkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 18};
  522. Xint    length_ifOutNUCastPkts = sizeof(objid_ifOutNUCastPkts)/sizeof(oid);
  523. Xoid    objid_ipInReceives[] = {1, 3, 6, 1, 2, 1, 4, 3, 0};
  524. Xint    length_ipInReceives = sizeof(objid_ipInReceives)/sizeof(oid);
  525. Xoid    objid_ipOutRequests[] = {1, 3, 6, 1, 2, 1, 4, 10, 0};
  526. Xint    length_ipOutRequests = sizeof(objid_ipOutRequests)/sizeof(oid);
  527. X
  528. Xchar *
  529. Xuptime_string(timeticks, buf)
  530. X    register u_long timeticks;
  531. X    char *buf;
  532. X{
  533. X    int    seconds, minutes, hours, days;
  534. X
  535. X    timeticks /= 100;
  536. X    days = timeticks / (60 * 60 * 24);
  537. X    timeticks %= (60 * 60 * 24);
  538. X
  539. X    hours = timeticks / (60 * 60);
  540. X    timeticks %= (60 * 60);
  541. X
  542. X    minutes = timeticks / 60;
  543. X    seconds = timeticks % 60;
  544. X
  545. X    if (days == 0){
  546. X    sprintf(buf, "%d:%02d:%02d", hours, minutes, seconds);
  547. X    } else if (days == 1) {
  548. X    sprintf(buf, "%d day, %d:%02d:%02d", days, hours, minutes, seconds);
  549. X    } else {
  550. X    sprintf(buf, "%d days, %d:%02d:%02d", days, hours, minutes, seconds);
  551. X    }
  552. X    return buf;
  553. X}
  554. X
  555. Xmain(argc, argv)
  556. X    int        argc;
  557. X    char    *argv[];
  558. X{
  559. X    struct snmp_session session, *ss;
  560. X    struct snmp_pdu *pdu, *response;
  561. X    struct variable_list *vars;
  562. X    int    arg;
  563. X    char *gateway = NULL;
  564. X    char *community = NULL;
  565. X    char    name[256];
  566. X    char    buf[64];
  567. X    int        good_var, index;
  568. X    int        status, count;
  569. X    u_long  ipackets = 0, opackets = 0, down_interfaces = 0;
  570. X    u_long  ipin = 0, ipout = 0;
  571. X    u_long  uptime = 0;
  572. X
  573. X    /*
  574. X     * usage: snmpstatus gateway-name [community-name]
  575. X     */
  576. X    for(arg = 1; arg < argc; arg++){
  577. X    if (argv[arg][0] == '-'){
  578. X        switch(argv[arg][1]){
  579. X        case 'd':
  580. X            snmp_dump_packet++;
  581. X            break;
  582. X        default:
  583. X            printf("invalid option: -%c\n", argv[arg][1]);
  584. X            break;
  585. X        }
  586. X        continue;
  587. X    }
  588. X    if (gateway == NULL){
  589. X        gateway = argv[arg];
  590. X    } else if (community == NULL){
  591. X        community = argv[arg]; 
  592. X    } else {
  593. X        printf("usage: snmpstatus gateway-name [community-name]\n");
  594. X        exit(1);
  595. X    }
  596. X    }
  597. X    if (!(gateway)){
  598. X    printf("usage: snmpstatus gateway-name [community-name]\n");
  599. X    exit(1);
  600. X    }
  601. X
  602. X    bzero((char *)&session, sizeof(struct snmp_session));
  603. X    session.peername = gateway;
  604. X    session.community = (u_char *)community;
  605. X    if (community == NULL){
  606. X    session.community_len = SNMP_DEFAULT_COMMUNITY_LEN;
  607. X    } else {
  608. X    session.community_len = strlen(community);
  609. X    }
  610. X    session.retries = 4;
  611. X    session.timeout = 500000;
  612. X    session.authenticator = NULL;
  613. X    snmp_synch_setup(&session);
  614. X    ss = snmp_open(&session);
  615. X    if (ss == NULL){
  616. X    printf("Couldn't open snmp\n");
  617. X    exit(-1);
  618. X    }
  619. X
  620. X    strcpy(name, "No System Description Available");
  621. X    pdu = snmp_pdu_create(GET_REQ_MSG);
  622. X
  623. X    snmp_add_null_var(pdu, objid_sysDescr, length_sysDescr);
  624. X    snmp_add_null_var(pdu, objid_sysUpTime, length_sysUpTime);
  625. X    snmp_add_null_var(pdu, objid_ipInReceives, length_ipInReceives);
  626. X    snmp_add_null_var(pdu, objid_ipOutRequests, length_ipOutRequests);
  627. X
  628. Xretry:
  629. X    status = snmp_synch_response(ss, pdu, &response);
  630. X    if (status == STAT_SUCCESS){
  631. X    if (response->errstat == SNMP_ERR_NOERROR){
  632. X        for(vars = response->variables; vars; vars = vars->next_variable){
  633. X        if (vars->name_length == length_sysDescr &&
  634. X            !bcmp((char *)objid_sysDescr, (char*)vars->name, sizeof(objid_sysDescr))){
  635. X            bcopy((char *)vars->val.string, name, vars->val_len);
  636. X            name[vars->val_len] = '\0';
  637. X        }
  638. X        if (vars->name_length == length_sysUpTime &&
  639. X            !bcmp((char *)objid_sysUpTime, (char*)vars->name, sizeof(objid_sysUpTime))){
  640. X            uptime = *vars->val.integer;
  641. X        }
  642. X        if (vars->name_length == length_ipInReceives &&
  643. X            !bcmp((char *)objid_ipInReceives, (char*)vars->name, sizeof(objid_ipInReceives))){
  644. X            ipin = *vars->val.integer;
  645. X        }
  646. X        if (vars->name_length == length_ipOutRequests &&
  647. X            !bcmp((char *)objid_ipOutRequests, (char*)vars->name, sizeof(objid_ipOutRequests))){
  648. X            ipout = *vars->val.integer;
  649. X        }
  650. X        }
  651. X    } else {
  652. X        printf("Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
  653. X        if (response->errstat == SNMP_ERR_NOSUCHNAME){
  654. X        printf("This name doesn't exist: ");
  655. X        for(count = 1, vars = response->variables; vars && count != response->errindex;
  656. X            vars = vars->next_variable, count++)
  657. X            ;
  658. X        if (vars)
  659. X            print_objid(vars->name, vars->name_length);
  660. X        printf("\n");
  661. X        }
  662. X        if ((pdu = snmp_fix_pdu(response, GET_REQ_MSG)) != NULL)
  663. X        goto retry;
  664. X    }
  665. X
  666. X    } else if (status == STAT_TIMEOUT){
  667. X    printf("No Response from %s\n", gateway);
  668. X    exit(1);
  669. X    } else {    /* status == STAT_ERROR */
  670. X    printf("An error occurred, Quitting\n");
  671. X    exit(2);
  672. X    }
  673. X
  674. X    printf("[%s]=>[%s] Up: %s\n", inet_ntoa(response->address.sin_addr), name,
  675. X    uptime_string(uptime, buf));
  676. X
  677. X    if (response)
  678. X    snmp_free_pdu(response);
  679. X
  680. X    pdu = snmp_pdu_create(GETNEXT_REQ_MSG);
  681. X
  682. X    snmp_add_null_var(pdu, objid_ifOperStatus, length_ifOperStatus);
  683. X    snmp_add_null_var(pdu, objid_ifInUCastPkts, length_ifInUCastPkts);
  684. X    snmp_add_null_var(pdu, objid_ifInNUCastPkts, length_ifInNUCastPkts);
  685. X    snmp_add_null_var(pdu, objid_ifOutUCastPkts, length_ifOutUCastPkts);
  686. X    snmp_add_null_var(pdu, objid_ifOutNUCastPkts, length_ifOutNUCastPkts);
  687. X
  688. X    good_var = 5;
  689. X    while(good_var == 5){
  690. X    good_var = 0;
  691. X    status = snmp_synch_response(ss, pdu, &response);
  692. X    if (status == STAT_SUCCESS){
  693. X        if (response->errstat == SNMP_ERR_NOERROR){
  694. X        pdu = snmp_pdu_create(GETNEXT_REQ_MSG);
  695. X
  696. X        index = 0;
  697. X        for(vars = response->variables; vars; vars = vars->next_variable){
  698. X            if (index == 0 && vars->name_length >= length_ifOperStatus &&
  699. X            !bcmp((char *)objid_ifOperStatus, (char *)vars->name,
  700. X            sizeof(objid_ifOperStatus))){
  701. X                if (*vars->val.integer != MIB_IFSTATUS_UP)
  702. X                down_interfaces++;
  703. X                snmp_add_null_var(pdu, vars->name, vars->name_length);
  704. X                good_var++;
  705. X            } else if (index == 1 && vars->name_length >= length_ifInUCastPkts &&
  706. X            !bcmp((char *)objid_ifInUCastPkts, (char *)vars->name,
  707. X            sizeof(objid_ifInUCastPkts))){
  708. X                ipackets += *vars->val.integer;
  709. X                snmp_add_null_var(pdu, vars->name, vars->name_length);
  710. X                good_var++;
  711. X            } else if (index == 2 && vars->name_length >= length_ifInNUCastPkts &&
  712. X            !bcmp((char *)objid_ifInNUCastPkts, (char *)vars->name,
  713. X            sizeof(objid_ifInNUCastPkts))){
  714. X                ipackets += *vars->val.integer;
  715. X                snmp_add_null_var(pdu, vars->name, vars->name_length);
  716. X                good_var++;
  717. X            } else if (index == 3 && vars->name_length >= length_ifOutUCastPkts &&
  718. X            !bcmp((char *)objid_ifOutUCastPkts, (char *)vars->name,
  719. X            sizeof(objid_ifOutUCastPkts))){
  720. X                opackets += *vars->val.integer;
  721. X                snmp_add_null_var(pdu, vars->name, vars->name_length);
  722. X                good_var++;
  723. X            } else if (index == 4 && vars->name_length >= length_ifOutNUCastPkts &&
  724. X            !bcmp((char *)objid_ifOutNUCastPkts, (char *)vars->name,
  725. X            sizeof(objid_ifOutNUCastPkts))){
  726. X                opackets += *vars->val.integer;
  727. X                snmp_add_null_var(pdu, vars->name, vars->name_length);
  728. X                good_var++;
  729. X            }
  730. X            index++;
  731. X        }
  732. X        } else {
  733. X        printf("Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
  734. X        if (response->errstat == SNMP_ERR_NOSUCHNAME){
  735. X            printf("This name doesn't exist: ");
  736. X            for(count = 1, vars = response->variables; vars && count != response->errindex;
  737. X            vars = vars->next_variable, count++)
  738. X                ;
  739. X            if (vars)
  740. X            print_objid(vars->name, vars->name_length);
  741. X            printf("\n");
  742. X        }
  743. X        }
  744. X
  745. X    } else if (status == STAT_TIMEOUT){
  746. X        printf("No Response from %s\n", gateway);
  747. X    } else {    /* status == STAT_ERROR */
  748. X        printf("An error occurred, Quitting\n");
  749. X    }
  750. X
  751. X    if (response)
  752. X        snmp_free_pdu(response);
  753. X    }
  754. X    printf("Recv/Trans packets: Interfaces: %d/%d | IP: %d/%d\n", ipackets, opackets, ipin, ipout);
  755. X    if (down_interfaces > 0){
  756. X    printf("%d interface%s down!\n", down_interfaces, down_interfaces > 1 ? "s are": " is" );
  757. X    }
  758. X}
  759. X
  760. END_OF_FILE
  761.   if test 9974 -ne `wc -c <'netramet/src/apps/snmpstatus.c'`; then
  762.     echo shar: \"'netramet/src/apps/snmpstatus.c'\" unpacked with wrong size!
  763.   fi
  764.   # end of 'netramet/src/apps/snmpstatus.c'
  765. fi
  766. if test -f 'netramet/src/apps/snmptest.c' -a "${1}" != "-c" ; then 
  767.   echo shar: Will not clobber existing file \"'netramet/src/apps/snmptest.c'\"
  768. else
  769.   echo shar: Extracting \"'netramet/src/apps/snmptest.c'\" \(9319 characters\)
  770.   sed "s/^X//" >'netramet/src/apps/snmptest.c' <<'END_OF_FILE'
  771. X/*
  772. X * snmptest.c - send snmp requests to a network entity.
  773. X *
  774. X */
  775. X/***********************************************************
  776. X    Copyright 1988, 1989 by Carnegie Mellon University
  777. X
  778. X                      All Rights Reserved
  779. X
  780. XPermission to use, copy, modify, and distribute this software and its 
  781. Xdocumentation for any purpose and without fee is hereby granted, 
  782. Xprovided that the above copyright notice appear in all copies and that
  783. Xboth that copyright notice and this permission notice appear in 
  784. Xsupporting documentation, and that the name of CMU not be
  785. Xused in advertising or publicity pertaining to distribution of the
  786. Xsoftware without specific, written prior permission.  
  787. X
  788. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  789. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  790. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  791. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  792. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  793. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  794. XSOFTWARE.
  795. X******************************************************************/
  796. X#include <sys/types.h>
  797. X#include <netinet/in.h>
  798. X#include <stdio.h>
  799. X#include <ctype.h>
  800. X#include <errno.h>
  801. X
  802. X#include "ausnmp.h"
  803. X#include "snmp.h"
  804. X#include "snmpimpl.h"
  805. X#include "asn1.h"
  806. X#include "snmpapi.h"
  807. X#include "snmpclnt.h"
  808. X
  809. Xextern int  errno;
  810. Xint command = GET_REQ_MSG;
  811. Xint    snmp_dump_packet = 0;
  812. X
  813. Xmain(argc, argv)
  814. X    int        argc;
  815. X    char    *argv[];
  816. X{
  817. X    struct snmp_session session, *ss;
  818. X    struct snmp_pdu *pdu, *response;
  819. X    struct variable_list *vars, *vp;
  820. X    int    arg, ret;
  821. X    char *gateway = NULL;
  822. X    char *community = NULL;
  823. X    int        status, count;
  824. X
  825. X    init_mib();
  826. X    /*
  827. X     * usage: snmptest gateway-name community-name
  828. X     */
  829. X    for(arg = 1; arg < argc; arg++){
  830. X    if (argv[arg][0] == '-'){
  831. X        switch(argv[arg][1]){
  832. X        case 'd':
  833. X            snmp_dump_packet++;
  834. X            break;
  835. X        default:
  836. X            fprintf(stderr, "invalid option: -%c\n", argv[arg][1]);
  837. X            break;
  838. X        }
  839. X        continue;
  840. X    }
  841. X    if (gateway == NULL){
  842. X        gateway = argv[arg];
  843. X    } else if (community == NULL){
  844. X        community = argv[arg]; 
  845. X    } else {
  846. X        fprintf(stderr, "usage: snmptest gateway-name community-name\n");
  847. X        exit(1);
  848. X    }
  849. X    }
  850. X    if (community == NULL)
  851. X    community = "public";    /* default to public */
  852. X
  853. X    if (!(gateway && community)){
  854. X    fprintf(stderr, "usage: snmptest gateway-name community-name\n");
  855. X    exit(1);
  856. X    }
  857. X
  858. X    bzero((char *)&session, sizeof(struct snmp_session));
  859. X    session.peername = gateway;
  860. X    session.community = (u_char *)community;
  861. X    session.community_len = strlen((char *)community);
  862. X    session.retries = SNMP_DEFAULT_RETRIES;
  863. X    session.timeout = SNMP_DEFAULT_TIMEOUT;
  864. X    session.authenticator = NULL;
  865. X    snmp_synch_setup(&session);
  866. X    ss = snmp_open(&session);
  867. X    if (ss == NULL){
  868. X    fprintf(stderr, "Couldn't open snmp\n");
  869. X    exit(-1);
  870. X    }
  871. X
  872. X    while(1){
  873. X    vars = NULL;
  874. X    for(ret = 1; ret != 0;){
  875. X        vp = (struct variable_list *)malloc(sizeof(struct variable_list));
  876. X        vp->next_variable = NULL;
  877. X        vp->name = NULL;
  878. X        vp->val.string = NULL;
  879. X
  880. X        while((ret = input_variable(vp)) == -1)
  881. X        ;
  882. X        if (ret == 1){
  883. X        /* add it to the list */
  884. X        if (vars == NULL){
  885. X            /* if first variable */
  886. X            pdu = snmp_pdu_create(command);
  887. X            pdu->variables = vp;
  888. X        } else {
  889. X            vars->next_variable = vp;
  890. X        }
  891. X        vars = vp;
  892. X        } else {
  893. X        /* free the last (unused) variable */
  894. X        if (vp->name)
  895. X            free((char *)vp->name);
  896. X        if (vp->val.string)
  897. X            free((char *)vp->val.string);
  898. X        free((char *)vp);
  899. X        }
  900. X    }
  901. X    status = snmp_synch_response(ss, pdu, &response);
  902. X    if (status == STAT_SUCCESS){
  903. X        switch(response->command){
  904. X        case GET_REQ_MSG:
  905. X            printf("Received GET REQUEST ");
  906. X            break;
  907. X        case GETNEXT_REQ_MSG:
  908. X            printf("Received GETNEXT REQUEST ");
  909. X            break;
  910. X        case GET_RSP_MSG:
  911. X            printf("Received GET RESPONSE ");
  912. X            break;
  913. X        case SET_REQ_MSG:
  914. X            printf("Received SET REQUEST ");
  915. X            break;
  916. X        case TRP_REQ_MSG:
  917. X            printf("Received TRAP REQUEST ");
  918. X            break;
  919. X        }
  920. X        printf("from %s\n", inet_ntoa(response->address.sin_addr));
  921. X        printf("requestid 0x%x errstat 0x%x errindex 0x%x\n",
  922. X        response->reqid, response->errstat, response->errindex);
  923. X        if (response->errstat == SNMP_ERR_NOERROR){
  924. X        for(vars = response->variables; vars; vars = vars->next_variable)
  925. X            print_variable(vars->name, vars->name_length, vars);
  926. X        } else {
  927. X        fprintf(stderr, "Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
  928. X        if (response->errstat == SNMP_ERR_NOSUCHNAME){
  929. X            for(count = 1, vars = response->variables; vars && count != response->errindex;
  930. X            vars = vars->next_variable, count++)
  931. X                ;
  932. X            if (vars){
  933. X            printf("This name doesn't exist: ");
  934. X            print_objid(vars->name, vars->name_length);
  935. X            }
  936. X            printf("\n");
  937. X        }
  938. X        }
  939. X
  940. X    } else if (status == STAT_TIMEOUT){
  941. X        fprintf(stderr, "No Response from %s\n", gateway);
  942. X    } else {    /* status == STAT_ERROR */
  943. X        fprintf(stderr, "An error occurred, Quitting\n");
  944. X    }
  945. X
  946. X    if (response)
  947. X        snmp_free_pdu(response);
  948. X    }
  949. X}
  950. X
  951. Xint
  952. Xascii_to_binary(cp, bufp)
  953. X    u_char  *cp;
  954. X    u_char *bufp;
  955. X{
  956. X    int    subidentifier;
  957. X    u_char *bp = bufp;
  958. X
  959. X    for(; *cp != '\0'; cp++){
  960. X    if (isspace(*cp))
  961. X        continue;
  962. X    if (!isdigit(*cp)){
  963. X        fprintf(stderr, "Input error\n");
  964. X        return -1;
  965. X    }
  966. X    subidentifier = atoi(cp);
  967. X    if (subidentifier > 255){
  968. X        fprintf(stderr, "subidentifier %d is too large ( > 255)\n", subidentifier);
  969. X        return -1;
  970. X    }
  971. X    *bp++ = (u_char)subidentifier;
  972. X    while(isdigit(*cp))
  973. X        cp++;
  974. X    cp--;
  975. X    }
  976. X    return bp - bufp;
  977. X}
  978. X
  979. X
  980. Xint
  981. Xhex_to_binary(cp, bufp)
  982. X    u_char  *cp;
  983. X    u_char *bufp;
  984. X{
  985. X    int    subidentifier;
  986. X    u_char *bp = bufp;
  987. X
  988. X    for(; *cp != '\0'; cp++){
  989. X    if (isspace(*cp))
  990. X        continue;
  991. X    if (!isxdigit(*cp)){
  992. X        fprintf(stderr, "Input error\n");
  993. X        return -1;
  994. X    }
  995. X    sscanf(cp, "%x", &subidentifier);
  996. X    if (subidentifier > 255){
  997. X        fprintf(stderr, "subidentifier %d is too large ( > 255)\n", subidentifier);
  998. X        return -1;
  999. X    }
  1000. X    *bp++ = (u_char)subidentifier;
  1001. X    while(isxdigit(*cp))
  1002. X        cp++;
  1003. X    cp--;
  1004. X    }
  1005. X    return bp - bufp;
  1006. X}
  1007. X
  1008. X
  1009. Xinput_variable(vp)
  1010. X    struct variable_list    *vp;
  1011. X{
  1012. X    u_char  buf[256], value[256], ch;
  1013. X
  1014. X    printf("Please enter the variable name: ");
  1015. X    fflush(stdout);
  1016. X    gets(buf);
  1017. X
  1018. X    if (*buf == 0){
  1019. X    vp->name_length = 0;
  1020. X    return 0;
  1021. X    }
  1022. X    if (*buf == '$'){
  1023. X    switch(buf[1]){
  1024. X        case 'G':
  1025. X        command = GET_REQ_MSG;
  1026. X        printf("Request type is GET REQUEST\n");
  1027. X        break;
  1028. X        case 'N':
  1029. X        command = GETNEXT_REQ_MSG;
  1030. X        printf("Request type is GETNEXT REQUEST\n");
  1031. X        break;
  1032. X        case 'S':
  1033. X        command = SET_REQ_MSG;
  1034. X        printf("Request type is SET REQUEST\n");
  1035. X        break;
  1036. X        case 'D':
  1037. X        if (snmp_dump_packet){
  1038. X            snmp_dump_packet = 0;
  1039. X            printf("Turned packet dump off\n");
  1040. X        } else {
  1041. X            snmp_dump_packet = 1;
  1042. X            printf("Turned packet dump on\n");
  1043. X        }
  1044. X        break;
  1045. X        case 'Q':
  1046. X        printf("Quitting,  Goodbye\n");
  1047. X        exit(0);
  1048. X        break;
  1049. X        default:
  1050. X        fprintf(stderr, "Bad command\n");
  1051. X    }
  1052. X    return -1;
  1053. X    }
  1054. X    vp->name_length = MAX_NAME_LEN;
  1055. X    if (!read_objid(buf, value, &vp->name_length))
  1056. X    return -1;
  1057. X    vp->name = (oid *)malloc(vp->name_length * sizeof(oid));
  1058. X    bcopy((char *)value, (char *)vp->name, vp->name_length * sizeof(oid));
  1059. X
  1060. X    if (command == SET_REQ_MSG){
  1061. X    printf("Please enter variable type [i|s|x|d|n|o|t|a]: ");
  1062. X    fflush(stdout);
  1063. X    gets(buf);
  1064. X    ch = *buf;
  1065. X    switch(ch){
  1066. X        case 'i':
  1067. X        vp->type = INTEGER;
  1068. X        break;
  1069. X        case 's':
  1070. X        vp->type = STRING;
  1071. X        break;
  1072. X        case 'x':
  1073. X        vp->type = STRING;
  1074. X        break;
  1075. X        case 'd':
  1076. X        vp->type = STRING;
  1077. X        break;
  1078. X        case 'n':
  1079. X        vp->type = NULLOBJ;
  1080. X        break;
  1081. X        case 'o':
  1082. X        vp->type = OBJID;
  1083. X        break;
  1084. X        case 't':
  1085. X        vp->type = TIMETICKS;
  1086. X        break;
  1087. X        case 'a':
  1088. X        vp->type = IPADDRESS;
  1089. X        break;
  1090. X        default:
  1091. X        fprintf(stderr, "bad type \"%c\", use \"i\", \"s\", \"x\", \"d\", \"n\", \"o\", \"t\", or \"a\".\n", *buf);
  1092. X        return -1;
  1093. X    }
  1094. X    printf("Please enter new value: "); fflush(stdout);
  1095. X    gets(buf);
  1096. X    switch(vp->type){
  1097. X        case INTEGER:
  1098. X        vp->val.integer = (long *)malloc(sizeof(long));
  1099. X        *(vp->val.integer) = atoi(buf);
  1100. X        vp->val_len = sizeof(long);
  1101. X        break;
  1102. X        case STRING:
  1103. X        if (ch == 'd'){
  1104. X            vp->val_len = ascii_to_binary(buf, value);
  1105. X        } else if (ch == 's'){
  1106. X            strcpy(value, buf);
  1107. X            vp->val_len = strlen(buf);
  1108. X        } else if (ch == 'x'){
  1109. X            vp->val_len = hex_to_binary(buf, value);
  1110. X        }
  1111. X        vp->val.string = (u_char *)malloc(vp->val_len);
  1112. X        bcopy((char *)value, (char *)vp->val.string, vp->val_len);
  1113. X        break;
  1114. X        case NULLOBJ:
  1115. X        vp->val_len = 0;
  1116. X        vp->val.string = NULL;
  1117. X        break;
  1118. X        case OBJID:
  1119. X        vp->val_len = MAX_NAME_LEN;;
  1120. X        read_objid(buf, value, &vp->val_len);
  1121. X        vp->val_len *= sizeof(oid);
  1122. X        vp->val.objid = (oid *)malloc(vp->val_len);
  1123. X        bcopy((char *)value, (char *)vp->val.objid, vp->val_len);
  1124. X        break;
  1125. X        case TIMETICKS:
  1126. X        vp->val.integer = (long *)malloc(sizeof(long));
  1127. X        *(vp->val.integer) = atoi(buf);
  1128. X        vp->val_len = sizeof(long);
  1129. X        break;
  1130. X        case IPADDRESS:
  1131. X        vp->val.integer = (long *)malloc(sizeof(long));
  1132. X        *(vp->val.integer) = inet_addr(buf);
  1133. X        vp->val_len = sizeof(long);
  1134. X        break;
  1135. X        default:
  1136. X        fprintf(stderr, "Internal error\n");
  1137. X        break;
  1138. X    }
  1139. X    } else {    /* some form of get message */
  1140. X    vp->type = NULLOBJ;
  1141. X    vp->val_len = 0;
  1142. X    }
  1143. X    return 1;
  1144. X}
  1145. X
  1146. END_OF_FILE
  1147.   if test 9319 -ne `wc -c <'netramet/src/apps/snmptest.c'`; then
  1148.     echo shar: \"'netramet/src/apps/snmptest.c'\" unpacked with wrong size!
  1149.   fi
  1150.   # end of 'netramet/src/apps/snmptest.c'
  1151. fi
  1152. if test -f 'netramet/src/manager/nmc_pars.c' -a "${1}" != "-c" ; then 
  1153.   echo shar: Will not clobber existing file \"'netramet/src/manager/nmc_pars.c'\"
  1154. else
  1155.   echo shar: Extracting \"'netramet/src/manager/nmc_pars.c'\" \(16910 characters\)
  1156.   sed "s/^X//" >'netramet/src/manager/nmc_pars.c' <<'END_OF_FILE'
  1157. X/* 1135, Tue 28 Sep 93
  1158. X
  1159. X   NMCC_PARS.C:  Scanner/parser for nmc config and rules files
  1160. X
  1161. X   Copyright (C) 1992,1993 by Nevil Brownlee,
  1162. X   Computer Centre,  University of Auckland */
  1163. X
  1164. X#include <stdio.h>
  1165. X#include <ctype.h>
  1166. X#include <errno.h>
  1167. X
  1168. X#include <string.h>
  1169. X#include <malloc.h>
  1170. X#include <sys/param.h>
  1171. X#include <sys/types.h>
  1172. X#include <sys/time.h>
  1173. X#include <netinet/in.h>
  1174. X
  1175. X#include "ausnmp.h"
  1176. X
  1177. X#include "snmp.h"
  1178. X#include "snmpimpl.h"
  1179. X#include "asn1.h"
  1180. X#include "snmpclnt.h"
  1181. X#include "snmpapi.h"
  1182. X#include "mib.h"
  1183. X
  1184. X#include "nmc.h"
  1185. X
  1186. Xvoid mswait(unsigned int ms)  /* Wait for ms milliseconds */
  1187. X{
  1188. X   struct timeval timeout;
  1189. X   timeout.tv_sec = ms/1000;  timeout.tv_usec = (long)(ms%1000)*1000L;
  1190. X   select(FD_SETSIZE, 0, 0, 0, &timeout);
  1191. X   }
  1192. X
  1193. XFILE *wfopen(fn)  /* Open next file in sequence for write */
  1194. Xchar *fn;
  1195. X{
  1196. X   char lfn[NAME_LN];
  1197. X   int n;
  1198. X   FILE *f;
  1199. X   for (n = 1; ; ++n) {
  1200. X      sprintf(lfn,"%s.%03d",fn,n);
  1201. X      if ((f = fopen(lfn,"r")) == NULL) {
  1202. X         if ((f = fopen(lfn,"w")) != NULL) return f;
  1203. X         printf("Failed to open %s\n",lfn);
  1204. X         exit(0);
  1205. X         }
  1206. X      fclose(f);
  1207. X      }
  1208. X   }
  1209. X
  1210. Xchar *gnbr(unsigned int *n, char *s)
  1211. X   /* Get nbr from 's', return updated 's' */
  1212. X{
  1213. X   unsigned int v = 0, b = 10, d;
  1214. X   while (*s == ' ') ++s;
  1215. X   if (*s == 'x' || *s == 'X') {
  1216. X      ++s;  b = 16;
  1217. X      }
  1218. X   else if (*s == '0') {
  1219. X      ++s;  b = 8;
  1220. X      }
  1221. X   for (;;) {
  1222. X      d = *s;
  1223. X      if (b == 16) {
  1224. X         if (!isxdigit(d)) break;
  1225. X         }
  1226. X      else {
  1227. X         if (!isdigit(d)) break;
  1228. X         if (b == 8 && d > '7') break;
  1229. X         }
  1230. X      if (d <= '9') d -= '0';
  1231. X      else if (d <= 'F') d -= ('A'-10);
  1232. X      else d -= ('a'-10);
  1233. X      v = v*b + d;  ++s;
  1234. X      }
  1235. X   *n = v;  return s;
  1236. X   }
  1237. X
  1238. Xchar *gcstring(char *s, int *len)  /* Get string from s */
  1239. X{
  1240. X   static char escin[] = {
  1241. X      'b', 'f', 'n', 'r', 't', 'v','\\','\'','\"','\?', 0 };
  1242. X   static char escout[] ={
  1243. X      '\b','\f','\n','\r','\t','\v','\\','\'','\"','\?' };
  1244. X   unsigned int c,j;
  1245. X   char sbuf[80], *t = sbuf, *rp;
  1246. X   while (*s) {
  1247. X      if (*s == '\\') {
  1248. X     ++s;  c = *s;
  1249. X     if (c == '0' || c == 'x' || c == 'X') {  /* Octal or hex nbr */
  1250. X        s = gnbr(&c,s);  *t++ = c;
  1251. X        }
  1252. X     else if isdigit(c) {  /* Octal number */
  1253. X        --s;  *s = '0';  /* Make gnbr use base 8 */
  1254. X        s = gnbr(&c,s);  *t++ = c;
  1255. X        }
  1256. X     else {
  1257. X        j = 0;  do {
  1258. X           if (c == escin[j]) break;
  1259. X           } while (escin[++j] != 0);
  1260. X        if (escin[j] != 0) {
  1261. X           *t++ = escout[j];  ++s;
  1262. X           }
  1263. X        }
  1264. X     }
  1265. X      else *t++ = *s++;
  1266. X      }
  1267. X   *t = '\0';
  1268. X   rp = malloc(*len = t-sbuf);  strcpy(rp,sbuf);
  1269. X   return rp;
  1270. X   }
  1271. X
  1272. Xstatic char ftb[32];
  1273. X
  1274. Xchar *fmt_time(time_t *t)
  1275. X{
  1276. X   char *ts = ctime(t);
  1277. X   strncpy(&ftb[0],  &ts[11], 9);  /* 17:31:42_ */
  1278. X   strncpy(&ftb[9],  &ts[0],  4);  /* Thu_ */
  1279. X   strncpy(&ftb[13], &ts[8],  3);  /* 23_  */
  1280. X   strncpy(&ftb[16], &ts[4],  4);  /* Sep_ */
  1281. X   strncpy(&ftb[20], &ts[22], 2);  /* 93   */
  1282. X   ftb[22] = '\0';
  1283. X   return ftb;
  1284. X   }   
  1285. X
  1286. Xchar *uptime_string(unsigned long timeticks, char *buf)
  1287. X{
  1288. X   int    seconds, minutes, hours, days;
  1289. X
  1290. X   timeticks /= 100;
  1291. X   days = timeticks / (60 * 60 * 24);
  1292. X   timeticks %= (60 * 60 * 24);
  1293. X
  1294. X   hours = timeticks / (60 * 60);
  1295. X   timeticks %= (60 * 60);
  1296. X
  1297. X   minutes = timeticks / 60;
  1298. X   seconds = timeticks % 60;
  1299. X
  1300. X   if (days == 0){
  1301. X      sprintf(buf, "%d:%02d:%02d", hours, minutes, seconds);
  1302. X      }
  1303. X   else if (days == 1) {
  1304. X      sprintf(buf, "%d day, %d:%02d:%02d",
  1305. X     days, hours, minutes, seconds);
  1306. X      }
  1307. X   else {
  1308. X      sprintf(buf, "%d days, %d:%02d:%02d",
  1309. X     days, hours, minutes, seconds);
  1310. X      }
  1311. X   return buf;
  1312. X   }
  1313. X
  1314. Xvoid printaddress(FILE *f, unsigned char *a, unsigned char addrsz)
  1315. X{
  1316. X   int j;
  1317. X   switch (addrsz) {
  1318. X   case MAC_ADDR_LEN:
  1319. X      fprintf(f,"%02X", a[0]);
  1320. X      for (j = 1; j != addrsz; ++j) fprintf(f,"-%02X", a[j]);
  1321. X      break;
  1322. X   case PEER_ADDR_LEN:
  1323. X      fprintf(f,"%u", a[0]);
  1324. X      for (j = 1; j != addrsz; ++j) fprintf(f,".%u", a[j]);
  1325. X      break;
  1326. X   case DETAIL_ADDR_LEN:
  1327. X      fprintf(f,"%u", a[0]*256 + a[1]);
  1328. X      break;
  1329. X      }
  1330. X   }
  1331. X
  1332. Xvoid printruleaddress(FILE *f, unsigned char *a, unsigned char addrsz)
  1333. X{
  1334. X   int j;
  1335. X   fprintf(f,"%u", a[0]);
  1336. X   for (j = 1; j != addrsz; ++j) fprintf(f,".%u", a[j]);
  1337. X   for ( ; j != RULE_ADDR_LEN; ++j) fprintf(f,".0");
  1338. X   }
  1339. X
  1340. X
  1341. Xint parse_open(char *fn)  /* Open file and initialise parser */
  1342. X{
  1343. X   if ((rfp = fopen(fn, "r")) == NULL) return 0;
  1344. X   rferrors = rule_line = 0;  ic = '\n';
  1345. X   return 1;
  1346. X   }
  1347. X
  1348. Xvoid getarg(char *arg)
  1349. X{
  1350. X   for (;;) {
  1351. X      if (ic == EOF) {
  1352. X         *arg = NULL;  return;
  1353. X         }
  1354. X      if (!isspace(ic)) break;
  1355. X      nextchar();
  1356. X      }
  1357. X   do {
  1358. X      *arg++ = ic;
  1359. X      nextchar();
  1360. X      } while (ic != EOF && !isspace(ic));
  1361. X   *arg = NULL;  return;
  1362. X   }
  1363. X
  1364. Xint nextchar()
  1365. X{
  1366. X   lic = ic;
  1367. X   for (;;) {
  1368. X      if (lic == '\n') {
  1369. X     if (fgets(inbuf, sizeof(inbuf), rfp) == NULL) return ic = EOF;
  1370. X     iblisted = 0;  ++rule_line;
  1371. X     ibp = inbuf;
  1372. X     }
  1373. X      ic = *ibp++;
  1374. X      if (ic == '#') lic = '\n';  /* Ignore comments */
  1375. X      else return ic;
  1376. X      }
  1377. X   }
  1378. X
  1379. Xint wordis(p,w)
  1380. Xchar *p, *w;
  1381. X{
  1382. X   return strncmp(p,w,strlen(w)) == 0;
  1383. X   }
  1384. X
  1385. Xint getword()
  1386. X{
  1387. X   char wbuf[30], *wp = wbuf;
  1388. X   int j;
  1389. X   for (;;) {
  1390. X      *wp++ = tolower(ic);
  1391. X      nextchar();
  1392. X      if (ic == EOF) return EOF;
  1393. X      if (!isalpha(ic)) break;
  1394. X      }
  1395. X
  1396. X   if (wordis(wbuf,"ip")) return AT_IP;
  1397. X   if (wordis(wbuf,"novell")) return AT_NOVELL;
  1398. X   if (wordis(wbuf,"decnet")) return AT_DECNET;
  1399. X   if (wordis(wbuf,"ethertalk")) return AT_ETHERTALK;
  1400. X
  1401. X   if (wordis(wbuf,"count")) return RA_COUNT;
  1402. X   if (wordis(wbuf,"tally")) return RA_TALLY;
  1403. X   if (wordis(wbuf,"aggregate")) return RA_AGGREGATE;
  1404. X   if (wordis(wbuf,"succeed")) return RA_SUCCEED;
  1405. X   if (wordis(wbuf,"fail")) return RA_FAIL;
  1406. X   if (wordis(wbuf,"pushto")) return RA_PUSHTO;
  1407. X   if (wordis(wbuf,"popto")) return RA_POPTO;
  1408. X   if (wordis(wbuf,"goto")) return RA_GOTO;
  1409. X
  1410. X   if (wordis(wbuf,"set")) return RF_SET;
  1411. X   if (wordis(wbuf,"rules")) return RF_RULES;
  1412. X   if (wordis(wbuf,"actions")) return RF_ACTIONS;
  1413. X   if (wordis(wbuf,"format")) return RF_FORMAT;
  1414. X   if (wordis(wbuf,"statistics")) return RF_STATS;
  1415. X
  1416. X   if (wordis(wbuf,"icmp")) return PT_ICMP;
  1417. X   if (wordis(wbuf,"tcp")) return PT_TCP;
  1418. X   if (wordis(wbuf,"udp")) return PT_UDP;
  1419. X
  1420. X   if (wordis(wbuf,"ftpdata")) return WNP_FTPDATA;
  1421. X   if (wordis(wbuf,"ftp")) return WNP_FTP;
  1422. X   if (wordis(wbuf,"telnet")) return WNP_TELNET;
  1423. X   if (wordis(wbuf,"smtp")) return WNP_SMTP;
  1424. X   if (wordis(wbuf,"domain")) return WNP_DOMAIN;
  1425. X   if (wordis(wbuf,"nntp")) return WNP_NNTP;
  1426. X   if (wordis(wbuf,"ntp")) return WNP_NTP;
  1427. X   if (wordis(wbuf,"snmp")) return WNP_SNMP;
  1428. X
  1429. X   for (j = 0; j != NATTRIBS+1; ++j)
  1430. X      if (wordis(wbuf,attribs[j].name)) return attribs[j].index;
  1431. X
  1432. X   if (!iblisted) {
  1433. X      printf("RULEFILE line %d: %s\n", rule_line,inbuf);
  1434. X      iblisted = 1;
  1435. X      }
  1436. X   printf("Unknown word %s !!!\n", wbuf);
  1437. X   ++rferrors;
  1438. X   return 0;
  1439. X   }
  1440. X
  1441. Xint getnbr()
  1442. X{
  1443. X   int v = 0;
  1444. X   for (;;) {
  1445. X      if (ic == EOF) return EOF;
  1446. X      if (isdigit(ic)) break;
  1447. X      else if (isalpha(ic)) return getword();
  1448. X      else nextchar();
  1449. X      }
  1450. X   for (;;) {
  1451. X      v = v*10 + ic-'0';
  1452. X      if (nextchar() == EOF) return EOF;
  1453. X      if (!isdigit(ic)) break;
  1454. X      }
  1455. X   if (v > 255) {
  1456. X      if (!iblisted) {
  1457. X     printf("RULEFILE line %d: %s\n", rule_line,inbuf);
  1458. X     iblisted = 1;
  1459. X     }
  1460. X      printf("Number > 255 !!!\n");
  1461. X      ++rferrors;
  1462. X      }
  1463. X   return v;
  1464. X   }
  1465. X
  1466. Xunsigned int getint(unsigned int *base)
  1467. X{
  1468. X   char wbuf[30], *wp;
  1469. X   unsigned long v;
  1470. X   unsigned char c, word;
  1471. X   int sic;  char *sibp;
  1472. X   for (;;) {
  1473. X      if (ic == EOF) return EOF;
  1474. X      if (isalnum(ic)) break;
  1475. X      else nextchar();
  1476. X      }
  1477. X   sic = ic;  sibp = ibp;  /* Save scanner state */
  1478. X   for (word = 0, wp = wbuf; ; ) {
  1479. X      if (isalpha(ic) && !isxdigit(ic)) word = 1;
  1480. X      *wp++ = tolower(ic);
  1481. X      nextchar();
  1482. X      if (ic == EOF) break;
  1483. X      if (!isalnum(ic)) break;
  1484. X      }
  1485. X   if (word) {
  1486. X      if (*base == 0) *base = 10;
  1487. X      ic = sic;  ibp = sibp;  /* Back up scanner */
  1488. X      return getword();
  1489. X      }
  1490. X   *wp = NULL;
  1491. X   if (*base == 0)
  1492. X      *base = ic == '-' ? 16 : 10;  /* Hex address bytes separated by - */
  1493. X   for (wp = wbuf, v = 0; *wp != NULL; ) {
  1494. X      c = *wp++;
  1495. X      if (isdigit(c)) c -= '0';
  1496. X      else c = c-'a' + 10;
  1497. X      v = v*(*base) + c;
  1498. X      }
  1499. X   return v;
  1500. X   }
  1501. X
  1502. Xvoid getaddress(unsigned char *a,unsigned char len, unsigned char addrsz)
  1503. X{
  1504. X   unsigned int j, base, v;
  1505. X   for (base = j = 0; j != addrsz; ++j) {
  1506. X      v = getint(&base);
  1507. X      if (len != 1 &&  /* Two or more bytes in address */
  1508. X            ic != '.' && ic != '-' &&  /* No byte separator character */
  1509. X            j == 0) {  /* Allow 16-bit decimal in first two bytes */
  1510. X         a[j++] = (v>>8) & 0xFF;  v &= 0x00FF;
  1511. X         }
  1512. X      a[j] = v;
  1513. X      if (ic != '.' && ic != '-') {  /* End of token; pad with zeroes */
  1514. X         for (++j; j != addrsz; ++j) a[j] = 0;
  1515. X         return;
  1516. X         }
  1517. X      }
  1518. X   }
  1519. X
  1520. Xint getattribute(unsigned char col, struct flow_info *fp)
  1521. X{
  1522. X   switch(col) {
  1523. X   case FTLOWINTERFACE:
  1524. X      fp->LowInterface = getnbr();
  1525. X      break;
  1526. X   case FTLOWADJACENTTYPE:
  1527. X      fp->LowAdjType = getnbr();
  1528. X      break;
  1529. X   case FTLOWADJACENTADDRESS:
  1530. X      getaddress(fp->LowAdjAddress,MAC_ADDR_LEN, MAC_ADDR_LEN);
  1531. X      break;
  1532. X   case FTLOWADJACENTMASK:
  1533. X      getaddress(fp->LowAdjMask,MAC_ADDR_LEN, MAC_ADDR_LEN);
  1534. X      break;
  1535. X   case FTLOWPEERTYPE:
  1536. X      fp->LowPeerType = getnbr();
  1537. X      break;
  1538. X   case FTLOWPEERTYPEMASK:
  1539. X      fp->LowPeerTypeMask = getnbr();
  1540. X      break;
  1541. X   case FTLOWPEERADDRESS:
  1542. X      getaddress(fp->LowPeerAddress,PEER_ADDR_LEN, PEER_ADDR_LEN);
  1543. X      break;
  1544. X   case FTLOWPEERMASK:
  1545. X      getaddress(fp->LowPeerMask,PEER_ADDR_LEN, PEER_ADDR_LEN);
  1546. X      break;
  1547. X   case FTLOWDETAILTYPE:
  1548. X      fp->LowDetailType = getnbr();
  1549. X      break;
  1550. X   case FTLOWDETAILTYPEMASK:
  1551. X      fp->LowDetailTypeMask = getnbr();
  1552. X      break;
  1553. X   case FTLOWDETAILADDRESS:
  1554. X      getaddress(fp->LowDetailAddress,DETAIL_ADDR_LEN, DETAIL_ADDR_LEN);
  1555. X      break;
  1556. X   case FTLOWDETAILMASK:
  1557. X      getaddress(fp->LowDetailMask,DETAIL_ADDR_LEN, DETAIL_ADDR_LEN);
  1558. X      break;
  1559. X   case FTHIINTERFACE:
  1560. X      fp->HighInterface = getnbr();
  1561. X      break;
  1562. X   case FTHIADJACENTTYPE:
  1563. X      fp->HighAdjType = getnbr();
  1564. X      break;
  1565. X   case FTHIADJACENTADDRESS:
  1566. X      getaddress(fp->HighAdjAddress,MAC_ADDR_LEN, MAC_ADDR_LEN);
  1567. X      break;
  1568. X   case FTHIADJACENTMASK:
  1569. X      getaddress(fp->HighAdjMask,MAC_ADDR_LEN, MAC_ADDR_LEN);
  1570. X      break;
  1571. X   case FTHIPEERTYPE:
  1572. X      fp->HighPeerType = getnbr();
  1573. X      break;
  1574. X   case FTHIPEERTYPEMASK:
  1575. X      fp->HighPeerTypeMask = getnbr();
  1576. X      break;
  1577. X   case FTHIPEERADDRESS:
  1578. X      getaddress(fp->HighPeerAddress,PEER_ADDR_LEN, PEER_ADDR_LEN);
  1579. X      break;
  1580. X   case FTHIPEERMASK:
  1581. X      getaddress(fp->HighPeerMask,PEER_ADDR_LEN, PEER_ADDR_LEN);
  1582. X      break;
  1583. X   case FTHIDETAILTYPE:
  1584. X      fp->HighDetailType = getnbr();
  1585. X      break;
  1586. X   case FTHIDETAILTYPEMASK:
  1587. X      fp->HighDetailTypeMask = getnbr();
  1588. X      break;
  1589. X   case FTHIDETAILADDRESS:
  1590. X      getaddress(fp->HighDetailAddress,DETAIL_ADDR_LEN, DETAIL_ADDR_LEN);
  1591. X      break;
  1592. X   case FTHIDETAILMASK:
  1593. X      getaddress(fp->HighDetailMask,DETAIL_ADDR_LEN, DETAIL_ADDR_LEN);
  1594. X      break;
  1595. X   default:
  1596. X      if (!iblisted) {
  1597. X     printf("RULEFILE line %d: %s\n", rule_line,inbuf);
  1598. X     iblisted = 1;
  1599. X     }
  1600. X      printf("Attribute %d not allowed in action !!!\n",col);
  1601. X      ++rferrors;
  1602. X      }
  1603. X   }
  1604. X
  1605. Xint scan_rulefile(ms,doset,list)
  1606. Xstruct meter_status *ms;
  1607. Xint doset,list;
  1608. X{
  1609. X   struct rule_info ri;
  1610. X   int rule_set, nrules, nactions, n, kind;
  1611. X   struct flow_info ai;
  1612. X   unsigned char a, b, actions[1+NATTRIBS];
  1613. X   char sbuf[32], *sp;
  1614. X   int len;
  1615. X
  1616. X   if (!parse_open(ms->rulefile)) {
  1617. X      printf("   Couldn't open rule file %s !!!\n", ms->rulefile);
  1618. X      return 0;  /* Fail */
  1619. X      }
  1620. X
  1621. X   rule_set = 0;
  1622. X   nrules = nactions = 0;  kind = RF_RULES;
  1623. X   for (;;) {
  1624. X      do {  /* First char of a line */
  1625. X     nextchar();
  1626. X     if (ic == EOF) break;
  1627. X     } while (lic != '\n');
  1628. X      if (ic == EOF) break;
  1629. X      n = getnbr();  /* What kind of line is it? */
  1630. X      if (n == RF_SET) {
  1631. X         ri.RuleSet = rule_set = getnbr();
  1632. X         kind = RF_RULES;  continue;
  1633. X         }
  1634. X      if (n == RF_RULES) {
  1635. X         kind = RF_RULES;  continue;
  1636. X         }
  1637. X      if (n == RF_ACTIONS) {
  1638. X         kind = RF_ACTIONS;   continue;
  1639. X         }
  1640. X      if (n == RF_FORMAT) {
  1641. X         for (a = 0; a != NATTRIBS+1; ++a)
  1642. X            ms->format[a] = ms->required[a] = 0;
  1643. X         for (a = 0; ; ) {
  1644. X            n = getnbr();
  1645. X            if (n < NULL || n > FTLASTTIME) {
  1646. X               if (!iblisted) {
  1647. X              printf("RULEFILE line %d: %s\n", rule_line,inbuf);
  1648. X              iblisted = 1;
  1649. X                  }
  1650. X               printf("Attribute %d not allowed in format !!!\n",n);
  1651. X               ++rferrors;
  1652. X           }
  1653. X            else {
  1654. X               ms->format[a] = n;  ms->required[n] = 1;
  1655. X               }
  1656. X            if (ic == ';' || ic == EOF) break;
  1657. X            for (;;) {
  1658. X               if (ic == EOF) return EOF;
  1659. X               if (ic == '\"' || isalnum(ic)) break;
  1660. X               else nextchar();
  1661. X               }
  1662. X            if (ic == '\"') {  /* Separator string */
  1663. X               nextchar();
  1664. X               for (sp = sbuf; ; ) {
  1665. X                  if (ic == EOF) {
  1666. X                     if (!iblisted) {
  1667. X                    printf("RULEFILE line %d: %s\n", rule_line,inbuf);
  1668. X                    iblisted = 1;
  1669. X                        }
  1670. X                     printf("Missing \" !!!\n");
  1671. X                     ++rferrors;  break;
  1672. X                 }
  1673. X                  else if (ic == '\"') {
  1674. X                     *sp = '\0';
  1675. X                     ms->separator[a] = gcstring(sbuf, &len);
  1676. X                     break;
  1677. X                     }
  1678. X                  else *sp++ = ic;
  1679. X                  nextchar();
  1680. X                  }
  1681. X               }
  1682. X            else ms->separator[a] = " ";
  1683. X            ++a;
  1684. X            if (ic == ';' || ic == EOF) break;
  1685. X            }
  1686. X         if (list) {
  1687. X        printf("Format: ");
  1688. X            for (n = ms->format[a = 0]; ; ) {
  1689. X               for (b = 1; attribs[b].index != n; ++b) ;
  1690. X               if (n != NULL) printf(attribs[b].name);
  1691. X               if ((n = ms->format[a+1]) == NULL) break;
  1692. X               printf(ms->separator[a++]);
  1693. X               }
  1694. X            printf("\n");
  1695. X            }
  1696. X         continue;
  1697. X         }
  1698. X      if (n == RF_STATS) {
  1699. X         ms->statsreqd = 1;  /* Collect statistics */
  1700. X         continue;
  1701. X         }
  1702. X
  1703. X      if (kind == RF_RULES) {
  1704. X         ri.RuleSelector = n;  /* Attribute nbr */
  1705. X         getaddress(ri.RuleMask,attribs[n].len, RULE_ADDR_LEN);
  1706. X         if (ic == EOF) break;
  1707. X         getaddress(ri.RuleMatchedValue,attribs[n].len, RULE_ADDR_LEN);
  1708. X         if (ic == EOF) break;
  1709. X         ri.RuleAction = getnbr();
  1710. X         if (ic == EOF) break;
  1711. X         ri.RuleJumpIndex = getnbr();
  1712. X         if (ic == EOF) break;
  1713. X         ri.RuleNbr = ++nrules;
  1714. X         if (list) {
  1715. X        printf("Rule %d,%d:  %d  ", rule_set,nrules,ri.RuleSelector);
  1716. X        printruleaddress(stdout, ri.RuleMask, RULE_ADDR_LEN);
  1717. X            printf(" ");
  1718. X        printruleaddress(stdout, ri.RuleMatchedValue,RULE_ADDR_LEN);
  1719. X        printf(" %d %d\n", ri.RuleAction,ri.RuleJumpIndex);
  1720. X        }
  1721. X         if (doset) add_rule(ms,&ri);  /* Add rule to meter's rule table */
  1722. X     }
  1723. X
  1724. X      if (kind == RF_ACTIONS) {
  1725. X         for (a = 0; a != NATTRIBS+1; ++a) actions[a] = 0;
  1726. X         for (;;) {
  1727. X            getattribute(n,&ai);
  1728. X            if (n > NULL || n <= NATTRIBS) {
  1729. X               actions[n] = 1;  /* Remember which attribs are set */
  1730. X               }
  1731. X            if (ic == ';' || ic == EOF) break;
  1732. X            n = getnbr();
  1733. X            }
  1734. X         ++nactions;
  1735. X         if (list) {
  1736. X        printf("Action %d,%d: ", rule_set,nactions);
  1737. X            for (a = 1;  a != NATTRIBS+1; ++a) {
  1738. X               if (actions[a] != 0) {
  1739. X                  for (b = 1; attribs[b].index != a; ++b) ;
  1740. X                  printf(" %s=",attribs[b].name);
  1741. X                  write_attrib(stdout,&ai,a);
  1742. X                  }
  1743. X               }
  1744. X            printf("\n");
  1745. X            }
  1746. X         if (doset) add_action(ms, &ai, rule_set,nactions, actions);
  1747. X     }
  1748. X      }
  1749. X
  1750. X   fclose(rfp);
  1751. X   if (rferrors == 0) {
  1752. X      ms->ruleset = rule_set;  ms->nrules = nrules;  ms->nactions = nactions;
  1753. X      return 1;  /* Succeed */
  1754. X      }
  1755. X   return 0;  /* Fail */
  1756. X   }
  1757. X
  1758. Xvoid parse_rulefile(ms,list)
  1759. Xstruct meter_status *ms;
  1760. Xint list;
  1761. X{
  1762. X   int NewRuleSet;
  1763. X   if (scan_rulefile(ms,0,list)) {  /* Rulefile is OK */
  1764. X      if (ms->ruleset == 0) return;
  1765. X      if (ms->nrules != 0) {  /* Rules were specified */
  1766. X         if (ms->CurrentRuleSet == (NewRuleSet = ms->ruleset))  {
  1767. X            ms->ruleset = 1;  /* Ask meter to use default rule set */
  1768. X            set_rule_info(ms,1);
  1769. X            ms->ruleset = NewRuleSet;
  1770. X            }
  1771. X         if (set_rule_info(ms,0)) {  /* Set rule+action table sizes */
  1772. X            scan_rulefile(ms,1,0);  /* Download the rules and actions */
  1773. X            }
  1774. X         }
  1775. X      set_rule_info(ms,1);  /* Tell meter to start using specified rules */
  1776. X      }
  1777. X   }
  1778. END_OF_FILE
  1779.   if test 16910 -ne `wc -c <'netramet/src/manager/nmc_pars.c'`; then
  1780.     echo shar: \"'netramet/src/manager/nmc_pars.c'\" unpacked with wrong size!
  1781.   fi
  1782.   # end of 'netramet/src/manager/nmc_pars.c'
  1783. fi
  1784. if test -f 'netramet/src/snmplib/snmpclnt.c' -a "${1}" != "-c" ; then 
  1785.   echo shar: Will not clobber existing file \"'netramet/src/snmplib/snmpclnt.c'\"
  1786. else
  1787.   echo shar: Extracting \"'netramet/src/snmplib/snmpclnt.c'\" \(9588 characters\)
  1788.   sed "s/^X//" >'netramet/src/snmplib/snmpclnt.c' <<'END_OF_FILE'
  1789. X/*
  1790. X * snmp_client.c - a toolkit of common functions for an SNMP client.
  1791. X *
  1792. X */
  1793. X/***********************************************************
  1794. X    Copyright 1988, 1989 by Carnegie Mellon University
  1795. X
  1796. X                      All Rights Reserved
  1797. X
  1798. XPermission to use, copy, modify, and distribute this software and its 
  1799. Xdocumentation for any purpose and without fee is hereby granted, 
  1800. Xprovided that the above copyright notice appear in all copies and that
  1801. Xboth that copyright notice and this permission notice appear in 
  1802. Xsupporting documentation, and that the name of CMU not be
  1803. Xused in advertising or publicity pertaining to distribution of the
  1804. Xsoftware without specific, written prior permission.  
  1805. X
  1806. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1807. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  1808. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  1809. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1810. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1811. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1812. XSOFTWARE.
  1813. X******************************************************************/
  1814. X#include <sys/types.h>
  1815. X#include <sys/param.h>
  1816. X#include <stdio.h>
  1817. X#include <netinet/in.h>
  1818. X#include <sys/time.h>
  1819. X#include <errno.h>
  1820. X
  1821. X#include "ausnmp.h"
  1822. X#include "asn1.h"
  1823. X#include "snmp.h"
  1824. X#include "snmpimpl.h"
  1825. X#include "snmpapi.h"
  1826. X#include "snmpclnt.h"
  1827. X
  1828. X#ifndef BSD4_3
  1829. X#define BSD4_2
  1830. X#endif
  1831. X
  1832. X#ifndef BSD4_3
  1833. X
  1834. Xtypedef long    fd_mask;
  1835. X#define NFDBITS    (sizeof(fd_mask) * NBBY)    /* bits per mask */
  1836. X
  1837. X#define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  1838. X#define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  1839. X#define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  1840. X#define FD_ZERO(p)    bzero((char *)(p), sizeof(*(p)))
  1841. X#endif
  1842. X
  1843. X
  1844. Xextern int errno;
  1845. Xstruct synch_state snmp_synch_state;
  1846. X
  1847. Xstruct snmp_pdu *
  1848. Xsnmp_pdu_create(command)
  1849. X    int command;
  1850. X{
  1851. X    struct snmp_pdu *pdu;
  1852. X
  1853. X    pdu = (struct snmp_pdu *)malloc(sizeof(struct snmp_pdu));
  1854. X    bzero((char *)pdu, sizeof(struct snmp_pdu));
  1855. X    pdu->command = command;
  1856. X    pdu->errstat = SNMP_DEFAULT_ERRSTAT;
  1857. X    pdu->errindex = SNMP_DEFAULT_ERRINDEX;
  1858. X    pdu->address.sin_addr.s_addr = SNMP_DEFAULT_ADDRESS;
  1859. X    pdu->enterprise = NULL;
  1860. X    pdu->enterprise_length = 0;
  1861. X    pdu->variables = NULL;
  1862. X    return pdu;
  1863. X}
  1864. X
  1865. X/*
  1866. X * Add a null variable with the requested name to the end of the list of
  1867. X * variables for this pdu.
  1868. X */
  1869. Xsnmp_add_null_var(pdu, name, name_length)
  1870. X    struct snmp_pdu *pdu;
  1871. X    oid *name;
  1872. X    int name_length;
  1873. X{
  1874. X    struct variable_list *vars;
  1875. X
  1876. X    if (pdu->variables == NULL){
  1877. X    pdu->variables = vars = (struct variable_list *)malloc(sizeof(struct variable_list));
  1878. X    } else {
  1879. X    for(vars = pdu->variables; vars->next_variable; vars = vars->next_variable)
  1880. X        ;
  1881. X    vars->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
  1882. X    vars = vars->next_variable;
  1883. X    }
  1884. X
  1885. X    vars->next_variable = NULL;
  1886. X    vars->name = (oid *)malloc(name_length * sizeof(oid));
  1887. X    bcopy((char *)name, (char *)vars->name, name_length * sizeof(oid));
  1888. X    vars->name_length = name_length;
  1889. X    vars->type = ASN_NULL;
  1890. X    vars->val.string = NULL;
  1891. X    vars->val_len = 0;
  1892. X}
  1893. X
  1894. Xsnmp_synch_input(op, session, reqid, pdu, magic)
  1895. X    int op;
  1896. X    struct snmp_session *session;
  1897. X    int reqid;
  1898. X    struct snmp_pdu *pdu;
  1899. X    void *magic;
  1900. X{
  1901. X    struct variable_list *var, *newvar;
  1902. X    struct synch_state *state = (struct synch_state *)magic;
  1903. X    struct snmp_pdu *newpdu;
  1904. X
  1905. X    if (reqid != state->reqid)
  1906. X    return 0;
  1907. X    state->waiting = 0;
  1908. X    if (op == RECEIVED_MESSAGE && pdu->command == GET_RSP_MSG){
  1909. X    /* clone the pdu */
  1910. X    state->pdu = newpdu = (struct snmp_pdu *)malloc(sizeof(struct snmp_pdu));
  1911. X    bcopy((char *)pdu, (char *)newpdu, sizeof(struct snmp_pdu));
  1912. X    newpdu->variables = 0;
  1913. X    var = pdu->variables;
  1914. X    if (var != NULL){
  1915. X        newpdu->variables = newvar = (struct variable_list *)malloc(sizeof(struct variable_list));
  1916. X        bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1917. X        if (var->name != NULL){
  1918. X        newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1919. X        bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1920. X        }
  1921. X        if (var->val.string != NULL){
  1922. X        newvar->val.string = (u_char *)malloc(var->val_len);
  1923. X        bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1924. X        }
  1925. X        newvar->next_variable = 0;
  1926. X        while(var->next_variable){
  1927. X        newvar->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
  1928. X        var = var->next_variable;
  1929. X        newvar = newvar->next_variable;
  1930. X        bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1931. X        if (var->name != NULL){
  1932. X            newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1933. X            bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1934. X        }
  1935. X        if (var->val.string != NULL){
  1936. X            newvar->val.string = (u_char *)malloc(var->val_len);
  1937. X            bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1938. X        }
  1939. X        newvar->next_variable = 0;
  1940. X        }
  1941. X    }
  1942. X    state->status = STAT_SUCCESS;
  1943. X    } else if (op == TIMED_OUT){
  1944. X    state->status = STAT_TIMEOUT;
  1945. X    }
  1946. X    return 1;
  1947. X}
  1948. X
  1949. X
  1950. X/*
  1951. X * If there was an error in the input pdu, creates a clone of the pdu
  1952. X * that includes all the variables except the one marked by the errindex.
  1953. X * The command is set to the input command and the reqid, errstat, and
  1954. X * errindex are set to default values.
  1955. X * If the error status didn't indicate an error, the error index didn't
  1956. X * indicate a variable, the pdu wasn't a get response message, or there
  1957. X * would be no remaining variables, this function will return NULL.
  1958. X * If everything was successful, a pointer to the fixed cloned pdu will
  1959. X * be returned.
  1960. X */
  1961. Xstruct snmp_pdu *
  1962. Xsnmp_fix_pdu(pdu, command)
  1963. X    struct snmp_pdu *pdu;
  1964. X    int command;
  1965. X{
  1966. X    struct variable_list *var, *newvar;
  1967. X    struct snmp_pdu *newpdu;
  1968. X    int index, copied = 0;
  1969. X
  1970. X    if (pdu->command != GET_RSP_MSG || pdu->errstat == SNMP_ERR_NOERROR || pdu->errindex <= 0)
  1971. X    return NULL;
  1972. X    /* clone the pdu */
  1973. X    newpdu = (struct snmp_pdu *)malloc(sizeof(struct snmp_pdu));
  1974. X    bcopy((char *)pdu, (char *)newpdu, sizeof(struct snmp_pdu));
  1975. X    newpdu->variables = 0;
  1976. X    newpdu->command = command;
  1977. X    newpdu->reqid = SNMP_DEFAULT_REQID;
  1978. X    newpdu->errstat = SNMP_DEFAULT_ERRSTAT;
  1979. X    newpdu->errindex = SNMP_DEFAULT_ERRINDEX;
  1980. X    var = pdu->variables;
  1981. X    index = 1;
  1982. X    if (pdu->errindex == index){    /* skip first variable */
  1983. X    var = var->next_variable;
  1984. X    index++;
  1985. X    }
  1986. X    if (var != NULL){
  1987. X    newpdu->variables = newvar = (struct variable_list *)malloc(sizeof(struct variable_list));
  1988. X    bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1989. X    if (var->name != NULL){
  1990. X        newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1991. X        bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1992. X    }
  1993. X    if (var->val.string != NULL){
  1994. X        newvar->val.string = (u_char *)malloc(var->val_len);
  1995. X        bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1996. X    }
  1997. X    newvar->next_variable = 0;
  1998. X    copied++;
  1999. X
  2000. X    while(var->next_variable){
  2001. X        var = var->next_variable;
  2002. X        if (++index == pdu->errindex)
  2003. X        continue;
  2004. X        newvar->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
  2005. X        newvar = newvar->next_variable;
  2006. X        bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  2007. X        if (var->name != NULL){
  2008. X        newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  2009. X        bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  2010. X        }
  2011. X        if (var->val.string != NULL){
  2012. X        newvar->val.string = (u_char *)malloc(var->val_len);
  2013. X        bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  2014. X        }
  2015. X        newvar->next_variable = 0;
  2016. X        copied++;
  2017. X    }
  2018. X    }
  2019. X    if (index < pdu->errindex || copied == 0){
  2020. X    snmp_free_pdu(newpdu);
  2021. X    return NULL;
  2022. X    }
  2023. X    return newpdu;
  2024. X}
  2025. X
  2026. X
  2027. Xint
  2028. Xsnmp_synch_response(ss, pdu, response)
  2029. X    struct snmp_session *ss;
  2030. X    struct snmp_pdu *pdu;
  2031. X    struct snmp_pdu **response;
  2032. X{
  2033. X    struct synch_state *state = &snmp_synch_state;
  2034. X    int numfds, count;
  2035. X    fd_set fdset;
  2036. X    struct timeval timeout, *tvp;
  2037. X    int block;
  2038. X
  2039. X
  2040. X    if ((state->reqid = snmp_send(ss, pdu)) == 0){
  2041. X    *response = NULL;
  2042. X    snmp_free_pdu(pdu);
  2043. X    return STAT_ERROR;
  2044. X    }
  2045. X    state->waiting = 1;
  2046. X
  2047. X    while(state->waiting){
  2048. X    numfds = 0;
  2049. X    FD_ZERO(&fdset);
  2050. X    block = 1;
  2051. X    tvp = &timeout;
  2052. X    timerclear(tvp);
  2053. X    snmp_select_info(&numfds, &fdset, tvp, &block);
  2054. X    if (block == 1)
  2055. X        tvp = NULL;    /* block without timeout */
  2056. X    count = select(numfds, &fdset, 0, 0, tvp);
  2057. X    if (count > 0){
  2058. X        snmp_read(&fdset);
  2059. X    } else switch(count){
  2060. X        case 0:
  2061. X        snmp_timeout();
  2062. X        break;
  2063. X        case -1:
  2064. X        if (errno == EINTR){
  2065. X            continue;
  2066. X        } else {
  2067. X            perror("select");
  2068. X        }
  2069. X        /* FALLTHRU */
  2070. X        default:
  2071. X        return STAT_ERROR;
  2072. X    }
  2073. X    }
  2074. X    *response = state->pdu;
  2075. X    return state->status;
  2076. X}
  2077. X
  2078. Xsnmp_synch_setup(session)
  2079. X    struct snmp_session *session;
  2080. X{
  2081. X    session->callback = snmp_synch_input;
  2082. X    session->callback_magic = (void *)&snmp_synch_state;
  2083. X}
  2084. X
  2085. Xchar    *error_string[6] = {
  2086. X    "No Error",
  2087. X    "Response message would have been too large.",
  2088. X    "There is no such variable name in this MIB.",
  2089. X    "The value given has the wrong type or length",
  2090. X    "This variable is read only",
  2091. X    "A general failure occured"
  2092. X};
  2093. X
  2094. Xchar *
  2095. Xsnmp_errstring(errstat)
  2096. X    int    errstat;
  2097. X{
  2098. X    if (errstat <= SNMP_ERR_GENERR && errstat >= SNMP_ERR_NOERROR){
  2099. X    return error_string[errstat];
  2100. X    } else {
  2101. X    return "Unknown Error";
  2102. X    }
  2103. X}
  2104. END_OF_FILE
  2105.   if test 9588 -ne `wc -c <'netramet/src/snmplib/snmpclnt.c'`; then
  2106.     echo shar: \"'netramet/src/snmplib/snmpclnt.c'\" unpacked with wrong size!
  2107.   fi
  2108.   # end of 'netramet/src/snmplib/snmpclnt.c'
  2109. fi
  2110. echo shar: End of archive 21 \(of 25\).
  2111. cp /dev/null ark21isdone
  2112. MISSING=""
  2113. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ; do
  2114.     if test ! -f ark${I}isdone ; then
  2115.     MISSING="${MISSING} ${I}"
  2116.     fi
  2117. done
  2118. if test "${MISSING}" = "" ; then
  2119.     echo You have unpacked all 25 archives.
  2120.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2121. else
  2122.     echo You still must unpack the following archives:
  2123.     echo "        " ${MISSING}
  2124. fi
  2125. exit 0
  2126. exit 0 # Just in case...
  2127.