home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / nocol / part18 < prev    next >
Encoding:
Text File  |  1993-11-23  |  75.1 KB  |  2,438 lines

  1. Newsgroups: comp.sources.misc
  2. From: vikas@jvnc.net (Vikas Aggarwal)
  3. Subject: v40i148:  nocol - Network Monitoring System, Part18/26
  4. Message-ID: <1993Nov23.212803.21957@sparky.sterling.com>
  5. X-Md4-Signature: 9412511bd24c9b17792d670aa273dbf1
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Tue, 23 Nov 1993 21:28:03 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: vikas@jvnc.net (Vikas Aggarwal)
  12. Posting-number: Volume 40, Issue 148
  13. Archive-name: nocol/part18
  14. Environment: INET, UNIX
  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:  nocol-3.0/src/cmu-snmp/apps/snmpnetstat/if.c
  21. #   nocol-3.0/src/cmu-snmp/apps/snmpstatus.c
  22. #   nocol-3.0/src/cmu-snmp/apps/snmptest.c
  23. #   nocol-3.0/src/cmu-snmp/include/snmp_client.c
  24. #   nocol-3.0/src/cmu-snmp/snmplib/snmp_client.c
  25. #   nocol-3.0/src/netmon/filter.c nocol-3.0/src/perlnocol/nrmon
  26. #   nocol-3.0/src/utility/log-maint
  27. # Wrapped by kent@sparky on Tue Nov  9 22:22:22 1993
  28. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  29. echo If this archive is complete, you will see the following message:
  30. echo '          "shar: End of archive 18 (of 26)."'
  31. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/if.c' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/if.c'\"
  33. else
  34.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/if.c'\" \(9726 characters\)
  35.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/if.c' <<'END_OF_FILE'
  36. X/***********************************************************
  37. X    Copyright 1989 by Carnegie Mellon University
  38. X
  39. X                      All Rights Reserved
  40. X
  41. XPermission to use, copy, modify, and distribute this software and its 
  42. Xdocumentation for any purpose and without fee is hereby granted, 
  43. Xprovided that the above copyright notice appear in all copies and that
  44. Xboth that copyright notice and this permission notice appear in 
  45. Xsupporting documentation, and that the name of CMU not be
  46. Xused in advertising or publicity pertaining to distribution of the
  47. Xsoftware without specific, written prior permission.  
  48. X
  49. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  50. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  51. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  52. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  53. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  54. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  55. XSOFTWARE.
  56. X******************************************************************/
  57. X/*
  58. X * Copyright (c) 1983,1988 Regents of the University of California.
  59. X * All rights reserved.
  60. X *
  61. X * Redistribution and use in source and binary forms are permitted
  62. X * provided that this notice is preserved and that due credit is given
  63. X * to the University of California at Berkeley. The name of the University
  64. X * may not be used to endorse or promote products derived from this
  65. X * software without specific prior written permission. This software
  66. X * is provided ``as is'' without express or implied warranty.
  67. X */
  68. X
  69. X#include <sys/types.h>
  70. X#include <sys/socket.h>
  71. X
  72. X#include <netinet/in.h>
  73. X
  74. X#include <stdio.h>
  75. X#include <signal.h>
  76. X
  77. X#include "main.h"
  78. X#include "asn1.h"
  79. X#include "snmp.h"
  80. X#include "snmp_impl.h"
  81. X#include "snmp_api.h"
  82. X#include "snmp_client.h"
  83. X#include "mib.h"
  84. X
  85. X#define    YES    1
  86. X#define    NO    0
  87. X
  88. Xextern    int nflag;
  89. Xextern    char *interface;
  90. Xextern    char *routename(), *netname();
  91. Xextern    struct snmp_session *Session;
  92. Xextern    struct variable_list *getvarbyname();
  93. X
  94. Xoid oid_ifname[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 1};
  95. Xstatic oid oid_ifinucastpkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 1};
  96. Xstatic oid oid_cfg_nnets[] = {1, 3, 6, 1, 2, 1, 2, 1, 0};
  97. X
  98. X#define IFNAME        2
  99. X#define IFMTU        4
  100. X#define IFOPERSTATUS    8
  101. X#define INUCASTPKTS    11
  102. X#define INNUCASTPKTS    12
  103. X#define INERRORS    14
  104. X#define OUTUCASTPKTS    17
  105. X#define OUTNUCASTPKTS    18
  106. X#define OUTERRORS    20
  107. X
  108. X/*
  109. X * Print a description of the network interfaces.
  110. X */
  111. Xintpr(interval)
  112. X    int interval;
  113. X{
  114. X    oid varname[MAX_NAME_LEN], *instance, *ifentry;
  115. X    int varname_len;
  116. X    int ifnum, cfg_nnets;
  117. X    struct variable_list *var;
  118. X    char name[128];
  119. X    int mtu;
  120. X    int ipkts, ierrs, opkts, oerrs, operstatus, collisions;
  121. X
  122. X    if (interval) {
  123. X        sidewaysintpr((unsigned)interval);
  124. X        return;
  125. X    }
  126. X    printf("%-11.11s %-5.5s %-11.11s %-15.15s %8.8s %5.5s %8.8s %5.5s",
  127. X        "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
  128. X        "Opkts", "Oerrs");
  129. X    putchar('\n');
  130. X    var = getvarbyname(Session, oid_cfg_nnets, sizeof(oid_cfg_nnets) / sizeof(oid));
  131. X    if (var)
  132. X        cfg_nnets = *var->val.integer;
  133. X    else
  134. X        return;
  135. X    bcopy((char *)oid_ifname, (char *)varname, sizeof(oid_ifname));
  136. X    varname_len = sizeof(oid_ifname) / sizeof(oid);
  137. X    ifentry = varname + 9;
  138. X    instance = varname + 10;
  139. X    for (ifnum = 1; ifnum <= cfg_nnets; ifnum++) {
  140. X        register char *cp;
  141. X        char *index();
  142. X
  143. X        *name = mtu = 0;
  144. X        ipkts = ierrs = opkts = oerrs = operstatus = collisions = 0;
  145. X        *instance = ifnum;
  146. X        *ifentry = IFNAME;
  147. X        var = getvarbyname(Session, varname, varname_len);
  148. X        if (var){
  149. X            bcopy((char *)var->val.string, name, var->val_len);
  150. X            name[var->val_len] = 0;
  151. X        }
  152. X        *ifentry = IFMTU;
  153. X        var = getvarbyname(Session, varname, varname_len);
  154. X        if (var)
  155. X            mtu = *var->val.integer;
  156. X        *ifentry = IFOPERSTATUS;
  157. X        var = getvarbyname(Session, varname, varname_len);
  158. X        if (var)
  159. X            operstatus = *var->val.integer;
  160. X        *ifentry = INUCASTPKTS;
  161. X        var = getvarbyname(Session, varname, varname_len);
  162. X        if (var)
  163. X            ipkts = *var->val.integer;
  164. X        *ifentry = INNUCASTPKTS;
  165. X        var = getvarbyname(Session, varname, varname_len);
  166. X        if (var)
  167. X            ipkts += *var->val.integer;
  168. X        *ifentry = INERRORS;
  169. X        var = getvarbyname(Session, varname, varname_len);
  170. X        if (var)
  171. X            ierrs = *var->val.integer;
  172. X        *ifentry = OUTUCASTPKTS;
  173. X        var = getvarbyname(Session, varname, varname_len);
  174. X        if (var)
  175. X            opkts = *var->val.integer;
  176. X        *ifentry = OUTNUCASTPKTS;
  177. X        var = getvarbyname(Session, varname, varname_len);
  178. X        if (var)
  179. X            opkts += *var->val.integer;
  180. X        *ifentry = OUTERRORS;
  181. X        var = getvarbyname(Session, varname, varname_len);
  182. X        if (var)
  183. X            oerrs = *var->val.integer;
  184. X
  185. X        name[15] = '\0';
  186. X        if (interface != 0 &&
  187. X            strcmp(name, interface) != 0)
  188. X            continue;
  189. X        cp = index(name, '\0');
  190. X        if (operstatus != MIB_IFSTATUS_UP)
  191. X            *cp++ = '*';
  192. X        *cp = '\0';
  193. X        printf("%-11.11s %-5d ", name, mtu);
  194. X        printf("%-11.11s ", "none");
  195. X        printf("%-15.15s ", "none");
  196. X        printf("%8d %5d %8d %5d %5d",
  197. X            ipkts, ierrs,
  198. X            opkts, oerrs, collisions);
  199. X        putchar('\n');
  200. X    }
  201. X}
  202. X
  203. X#define    MAXIF    10
  204. Xstruct    iftot {
  205. X    char    ift_name[128];        /* interface name */
  206. X    int    ift_ip;            /* input packets */
  207. X    int    ift_ie;            /* input errors */
  208. X    int    ift_op;            /* output packets */
  209. X    int    ift_oe;            /* output errors */
  210. X    int    ift_co;            /* collisions */
  211. X} iftot[MAXIF];
  212. X
  213. Xu_char    signalled;            /* set if alarm goes off "early" */
  214. X
  215. X/*
  216. X * Print a running summary of interface statistics.
  217. X * Repeat display every interval seconds, showing statistics
  218. X * collected over that interval.  Assumes that interval is non-zero.
  219. X * First line printed at top of screen is always cumulative.
  220. X */
  221. Xsidewaysintpr(interval)
  222. X    unsigned interval;
  223. X{
  224. X    register struct iftot *ip, *total;
  225. X    register int line;
  226. X    struct iftot *lastif, *sum, *interesting, ifnow, *now = &ifnow;
  227. X    int oldmask;
  228. X    int catchalarm();
  229. X    struct variable_list *var;
  230. X    oid varname[MAX_NAME_LEN], *instance, *ifentry;
  231. X    int varname_len;
  232. X    int ifnum, cfg_nnets;
  233. X    char *index();
  234. X
  235. X    lastif = iftot;
  236. X    sum = iftot + MAXIF - 1;
  237. X    total = sum - 1;
  238. X    interesting = iftot;
  239. X    var = getvarbyname(Session, oid_cfg_nnets, sizeof(oid_cfg_nnets) / sizeof(oid));
  240. X    if (var)
  241. X        cfg_nnets = *var->val.integer;
  242. X    else
  243. X        return;
  244. X    bcopy((char *)oid_ifname, (char *)varname, sizeof(oid_ifname));
  245. X    varname_len = sizeof(oid_ifname) / sizeof(oid);
  246. X    for (ifnum = 1, ip = iftot; ifnum <= cfg_nnets; ifnum++) {
  247. X        char *cp;
  248. X
  249. X        ip->ift_name[0] = '(';
  250. X        varname[10] = ifnum;
  251. X        var = getvarbyname(Session, varname, varname_len);
  252. X        if (var){
  253. X            bcopy((char *)var->val.string, ip->ift_name + 1, var->val_len);
  254. X        }
  255. X        if (interface && strcmp(ip->ift_name + 1, interface) == 0)
  256. X            interesting = ip;
  257. X        ip->ift_name[15] = '\0';
  258. X        cp = index(ip->ift_name, '\0');
  259. X        sprintf(cp, ")");
  260. X        ip++;
  261. X        if (ip >= iftot + MAXIF - 2)
  262. X            break;
  263. X    }
  264. X    lastif = ip;
  265. X
  266. X    (void)signal(SIGALRM, catchalarm);
  267. X    signalled = NO;
  268. X    (void)alarm(interval);
  269. Xbanner:
  270. X    printf("    input   %-6.6s    output       ", interesting->ift_name);
  271. X    if (lastif - iftot > 0)
  272. X        printf("     input  (Total)    output");
  273. X    for (ip = iftot; ip < iftot + MAXIF; ip++) {
  274. X        ip->ift_ip = 0;
  275. X        ip->ift_ie = 0;
  276. X        ip->ift_op = 0;
  277. X        ip->ift_oe = 0;
  278. X        ip->ift_co = 0;
  279. X    }
  280. X    putchar('\n');
  281. X    printf("%8.8s %5.5s %8.8s %5.5s %5.5s ",
  282. X        "packets", "errs", "packets", "errs", "colls");
  283. X    if (lastif - iftot > 0)
  284. X        printf("%8.8s %5.5s %8.8s %5.5s %5.5s ",
  285. X            "packets", "errs", "packets", "errs", "colls");
  286. X    putchar('\n');
  287. X    fflush(stdout);
  288. X    line = 0;
  289. Xloop:
  290. X    sum->ift_ip = 0;
  291. X    sum->ift_ie = 0;
  292. X    sum->ift_op = 0;
  293. X    sum->ift_oe = 0;
  294. X    sum->ift_co = 0;
  295. X    bcopy((char *)oid_ifinucastpkts, (char *)varname, sizeof(oid_ifinucastpkts));
  296. X    varname_len = sizeof(oid_ifinucastpkts) / sizeof(oid);
  297. X    ifentry = varname + 9;
  298. X    instance = varname + 10;
  299. X    for (ifnum = 1, ip = iftot; ifnum <= cfg_nnets && ip < lastif; ip++, ifnum++) {
  300. X        bzero((char *)now, sizeof(*now));
  301. X        *instance = ifnum;
  302. X        *ifentry = INUCASTPKTS;
  303. X        var = getvarbyname(Session, varname, varname_len);
  304. X        if (var)
  305. X            now->ift_ip = *var->val.integer;
  306. X        *ifentry = INNUCASTPKTS;
  307. X        var = getvarbyname(Session, varname, varname_len);
  308. X        if (var)
  309. X            now->ift_ip += *var->val.integer;
  310. X        *ifentry = INERRORS;
  311. X        var = getvarbyname(Session, varname, varname_len);
  312. X        if (var)
  313. X            now->ift_ie = *var->val.integer;
  314. X        *ifentry = OUTUCASTPKTS;
  315. X        var = getvarbyname(Session, varname, varname_len);
  316. X        if (var)
  317. X            now->ift_op = *var->val.integer;
  318. X        *ifentry = OUTNUCASTPKTS;
  319. X        var = getvarbyname(Session, varname, varname_len);
  320. X        if (var)
  321. X            now->ift_op += *var->val.integer;
  322. X        *ifentry = OUTERRORS;
  323. X        var = getvarbyname(Session, varname, varname_len);
  324. X        if (var)
  325. X            now->ift_oe = *var->val.integer;
  326. X
  327. X        if (ip == interesting)
  328. X            printf("%8d %5d %8d %5d %5d ",
  329. X                now->ift_ip - ip->ift_ip,
  330. X                now->ift_ie - ip->ift_ie,
  331. X                now->ift_op - ip->ift_op,
  332. X                now->ift_oe - ip->ift_oe,
  333. X                now->ift_co - ip->ift_co);
  334. X        ip->ift_ip = now->ift_ip;
  335. X        ip->ift_ie = now->ift_ie;
  336. X        ip->ift_op = now->ift_op;
  337. X        ip->ift_oe = now->ift_oe;
  338. X        ip->ift_co = now->ift_co;
  339. X        sum->ift_ip += ip->ift_ip;
  340. X        sum->ift_ie += ip->ift_ie;
  341. X        sum->ift_op += ip->ift_op;
  342. X        sum->ift_oe += ip->ift_oe;
  343. X        sum->ift_co += ip->ift_co;
  344. X    }
  345. X    if (lastif - iftot > 0)
  346. X        printf("%8d %5d %8d %5d %5d ",
  347. X            sum->ift_ip - total->ift_ip,
  348. X            sum->ift_ie - total->ift_ie,
  349. X            sum->ift_op - total->ift_op,
  350. X            sum->ift_oe - total->ift_oe,
  351. X            sum->ift_co - total->ift_co);
  352. X    *total = *sum;
  353. X    putchar('\n');
  354. X    fflush(stdout);
  355. X    line++;
  356. X    oldmask = sigblock(sigmask(SIGALRM));
  357. X    if (! signalled) {
  358. X        sigpause(0);
  359. X    }
  360. X    sigsetmask(oldmask);
  361. X    signalled = NO;
  362. X    (void)alarm(interval);
  363. X    if (line == 21)
  364. X        goto banner;
  365. X    goto loop;
  366. X    /*NOTREACHED*/
  367. X}
  368. X
  369. X/*
  370. X * Called if an interval expires before sidewaysintpr has completed a loop.
  371. X * Sets a flag to not wait for the alarm.
  372. X */
  373. Xcatchalarm()
  374. X{
  375. X    signalled = YES;
  376. X}
  377. END_OF_FILE
  378.   if test 9726 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/if.c'`; then
  379.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/if.c'\" unpacked with wrong size!
  380.   fi
  381.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/if.c'
  382. fi
  383. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmpstatus.c' -a "${1}" != "-c" ; then 
  384.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmpstatus.c'\"
  385. else
  386.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmpstatus.c'\" \(9959 characters\)
  387.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmpstatus.c' <<'END_OF_FILE'
  388. X/*
  389. X * snmpstatus.c - send snmp GET requests to a network entity.
  390. X *
  391. X */
  392. X/***********************************************************
  393. X    Copyright 1988, 1989 by Carnegie Mellon University
  394. X
  395. X                      All Rights Reserved
  396. X
  397. XPermission to use, copy, modify, and distribute this software and its 
  398. Xdocumentation for any purpose and without fee is hereby granted, 
  399. Xprovided that the above copyright notice appear in all copies and that
  400. Xboth that copyright notice and this permission notice appear in 
  401. Xsupporting documentation, and that the name of CMU not be
  402. Xused in advertising or publicity pertaining to distribution of the
  403. Xsoftware without specific, written prior permission.  
  404. X
  405. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  406. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  407. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  408. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  409. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  410. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  411. XSOFTWARE.
  412. X******************************************************************/
  413. X#include <sys/types.h>
  414. X#include <netinet/in.h>
  415. X#include <stdio.h>
  416. X
  417. X#include "snmp.h"
  418. X#include "snmp_impl.h"
  419. X#include "asn1.h"
  420. X#include "snmp_client.h"
  421. X#include "snmp_api.h"
  422. X#include "mib.h"
  423. X
  424. Xint    snmp_dump_packet = 0;
  425. X
  426. Xoid    objid_sysDescr[] = {1, 3, 6, 1, 2, 1, 1, 1, 0};
  427. Xint    length_sysDescr = sizeof(objid_sysDescr)/sizeof(oid);
  428. Xoid    objid_sysUpTime[] = {1, 3, 6, 1, 2, 1, 1, 3, 0};
  429. Xint    length_sysUpTime = sizeof(objid_sysUpTime)/sizeof(oid);
  430. Xoid    objid_ifOperStatus[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 8};
  431. Xint    length_ifOperStatus = sizeof(objid_ifOperStatus)/sizeof(oid);
  432. Xoid    objid_ifInUCastPkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 11};
  433. Xint    length_ifInUCastPkts = sizeof(objid_ifInUCastPkts)/sizeof(oid);
  434. Xoid    objid_ifInNUCastPkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 12};
  435. Xint    length_ifInNUCastPkts = sizeof(objid_ifInNUCastPkts)/sizeof(oid);
  436. Xoid    objid_ifOutUCastPkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 17};
  437. Xint    length_ifOutUCastPkts = sizeof(objid_ifOutUCastPkts)/sizeof(oid);
  438. Xoid    objid_ifOutNUCastPkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 18};
  439. Xint    length_ifOutNUCastPkts = sizeof(objid_ifOutNUCastPkts)/sizeof(oid);
  440. Xoid    objid_ipInReceives[] = {1, 3, 6, 1, 2, 1, 4, 3, 0};
  441. Xint    length_ipInReceives = sizeof(objid_ipInReceives)/sizeof(oid);
  442. Xoid    objid_ipOutRequests[] = {1, 3, 6, 1, 2, 1, 4, 10, 0};
  443. Xint    length_ipOutRequests = sizeof(objid_ipOutRequests)/sizeof(oid);
  444. X
  445. Xchar *
  446. Xuptime_string(timeticks, buf)
  447. X    register u_long timeticks;
  448. X    char *buf;
  449. X{
  450. X    int    seconds, minutes, hours, days;
  451. X
  452. X    timeticks /= 100;
  453. X    days = timeticks / (60 * 60 * 24);
  454. X    timeticks %= (60 * 60 * 24);
  455. X
  456. X    hours = timeticks / (60 * 60);
  457. X    timeticks %= (60 * 60);
  458. X
  459. X    minutes = timeticks / 60;
  460. X    seconds = timeticks % 60;
  461. X
  462. X    if (days == 0){
  463. X    sprintf(buf, "%d:%02d:%02d", hours, minutes, seconds);
  464. X    } else if (days == 1) {
  465. X    sprintf(buf, "%d day, %d:%02d:%02d", days, hours, minutes, seconds);
  466. X    } else {
  467. X    sprintf(buf, "%d days, %d:%02d:%02d", days, hours, minutes, seconds);
  468. X    }
  469. X    return buf;
  470. X}
  471. X
  472. Xmain(argc, argv)
  473. X    int        argc;
  474. X    char    *argv[];
  475. X{
  476. X    struct snmp_session session, *ss;
  477. X    struct snmp_pdu *pdu, *response;
  478. X    struct variable_list *vars;
  479. X    int    arg;
  480. X    char *gateway = NULL;
  481. X    char *community = NULL;
  482. X    char    name[256];
  483. X    char    buf[64];
  484. X    int        good_var, index;
  485. X    int        status, count;
  486. X    u_long  ipackets = 0, opackets = 0, down_interfaces = 0;
  487. X    u_long  ipin = 0, ipout = 0;
  488. X    u_long  uptime = 0;
  489. X
  490. X    /*
  491. X     * usage: snmpstatus gateway-name [community-name]
  492. X     */
  493. X    for(arg = 1; arg < argc; arg++){
  494. X    if (argv[arg][0] == '-'){
  495. X        switch(argv[arg][1]){
  496. X        case 'd':
  497. X            snmp_dump_packet++;
  498. X            break;
  499. X        default:
  500. X            printf("invalid option: -%c\n", argv[arg][1]);
  501. X            break;
  502. X        }
  503. X        continue;
  504. X    }
  505. X    if (gateway == NULL){
  506. X        gateway = argv[arg];
  507. X    } else if (community == NULL){
  508. X        community = argv[arg]; 
  509. X    } else {
  510. X        printf("usage: snmpstatus gateway-name [community-name]\n");
  511. X        exit(1);
  512. X    }
  513. X    }
  514. X    if (!(gateway)){
  515. X    printf("usage: snmpstatus gateway-name [community-name]\n");
  516. X    exit(1);
  517. X    }
  518. X
  519. X    bzero((char *)&session, sizeof(struct snmp_session));
  520. X    session.peername = gateway;
  521. X    session.community = (u_char *)community;
  522. X    if (community == NULL){
  523. X    session.community_len = SNMP_DEFAULT_COMMUNITY_LEN;
  524. X    } else {
  525. X    session.community_len = strlen(community);
  526. X    }
  527. X    session.retries = 4;
  528. X    session.timeout = 500000;
  529. X    session.authenticator = NULL;
  530. X    snmp_synch_setup(&session);
  531. X    ss = snmp_open(&session);
  532. X    if (ss == NULL){
  533. X    printf("Couldn't open snmp\n");
  534. X    exit(-1);
  535. X    }
  536. X
  537. X    strcpy(name, "No System Description Available");
  538. X    pdu = snmp_pdu_create(GET_REQ_MSG);
  539. X
  540. X    snmp_add_null_var(pdu, objid_sysDescr, length_sysDescr);
  541. X    snmp_add_null_var(pdu, objid_sysUpTime, length_sysUpTime);
  542. X    snmp_add_null_var(pdu, objid_ipInReceives, length_ipInReceives);
  543. X    snmp_add_null_var(pdu, objid_ipOutRequests, length_ipOutRequests);
  544. X
  545. Xretry:
  546. X    status = snmp_synch_response(ss, pdu, &response);
  547. X    if (status == STAT_SUCCESS){
  548. X    if (response->errstat == SNMP_ERR_NOERROR){
  549. X        for(vars = response->variables; vars; vars = vars->next_variable){
  550. X        if (vars->name_length == length_sysDescr &&
  551. X            !bcmp((char *)objid_sysDescr, (char*)vars->name, sizeof(objid_sysDescr))){
  552. X            bcopy((char *)vars->val.string, name, vars->val_len);
  553. X            name[vars->val_len] = '\0';
  554. X        }
  555. X        if (vars->name_length == length_sysUpTime &&
  556. X            !bcmp((char *)objid_sysUpTime, (char*)vars->name, sizeof(objid_sysUpTime))){
  557. X            uptime = *vars->val.integer;
  558. X        }
  559. X        if (vars->name_length == length_ipInReceives &&
  560. X            !bcmp((char *)objid_ipInReceives, (char*)vars->name, sizeof(objid_ipInReceives))){
  561. X            ipin = *vars->val.integer;
  562. X        }
  563. X        if (vars->name_length == length_ipOutRequests &&
  564. X            !bcmp((char *)objid_ipOutRequests, (char*)vars->name, sizeof(objid_ipOutRequests))){
  565. X            ipout = *vars->val.integer;
  566. X        }
  567. X        }
  568. X    } else {
  569. X        printf("Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
  570. X        if (response->errstat == SNMP_ERR_NOSUCHNAME){
  571. X        printf("This name doesn't exist: ");
  572. X        for(count = 1, vars = response->variables; vars && count != response->errindex;
  573. X            vars = vars->next_variable, count++)
  574. X            ;
  575. X        if (vars)
  576. X            print_objid(vars->name, vars->name_length);
  577. X        printf("\n");
  578. X        }
  579. X        if ((pdu = snmp_fix_pdu(response, GET_REQ_MSG)) != NULL)
  580. X        goto retry;
  581. X    }
  582. X
  583. X    } else if (status == STAT_TIMEOUT){
  584. X    printf("No Response from %s\n", gateway);
  585. X    exit(1);
  586. X    } else {    /* status == STAT_ERROR */
  587. X    printf("An error occurred, Quitting\n");
  588. X    exit(2);
  589. X    }
  590. X
  591. X    printf("[%s]=>[%s] Up: %s\n", inet_ntoa(response->address.sin_addr), name,
  592. X    uptime_string(uptime, buf));
  593. X
  594. X    if (response)
  595. X    snmp_free_pdu(response);
  596. X
  597. X    pdu = snmp_pdu_create(GETNEXT_REQ_MSG);
  598. X
  599. X    snmp_add_null_var(pdu, objid_ifOperStatus, length_ifOperStatus);
  600. X    snmp_add_null_var(pdu, objid_ifInUCastPkts, length_ifInUCastPkts);
  601. X    snmp_add_null_var(pdu, objid_ifInNUCastPkts, length_ifInNUCastPkts);
  602. X    snmp_add_null_var(pdu, objid_ifOutUCastPkts, length_ifOutUCastPkts);
  603. X    snmp_add_null_var(pdu, objid_ifOutNUCastPkts, length_ifOutNUCastPkts);
  604. X
  605. X    good_var = 5;
  606. X    while(good_var == 5){
  607. X    good_var = 0;
  608. X    status = snmp_synch_response(ss, pdu, &response);
  609. X    if (status == STAT_SUCCESS){
  610. X        if (response->errstat == SNMP_ERR_NOERROR){
  611. X        pdu = snmp_pdu_create(GETNEXT_REQ_MSG);
  612. X
  613. X        index = 0;
  614. X        for(vars = response->variables; vars; vars = vars->next_variable){
  615. X            if (index == 0 && vars->name_length >= length_ifOperStatus &&
  616. X            !bcmp((char *)objid_ifOperStatus, (char *)vars->name,
  617. X            sizeof(objid_ifOperStatus))){
  618. X                if (*vars->val.integer != MIB_IFSTATUS_UP)
  619. X                down_interfaces++;
  620. X                snmp_add_null_var(pdu, vars->name, vars->name_length);
  621. X                good_var++;
  622. X            } else if (index == 1 && vars->name_length >= length_ifInUCastPkts &&
  623. X            !bcmp((char *)objid_ifInUCastPkts, (char *)vars->name,
  624. X            sizeof(objid_ifInUCastPkts))){
  625. X                ipackets += *vars->val.integer;
  626. X                snmp_add_null_var(pdu, vars->name, vars->name_length);
  627. X                good_var++;
  628. X            } else if (index == 2 && vars->name_length >= length_ifInNUCastPkts &&
  629. X            !bcmp((char *)objid_ifInNUCastPkts, (char *)vars->name,
  630. X            sizeof(objid_ifInNUCastPkts))){
  631. X                ipackets += *vars->val.integer;
  632. X                snmp_add_null_var(pdu, vars->name, vars->name_length);
  633. X                good_var++;
  634. X            } else if (index == 3 && vars->name_length >= length_ifOutUCastPkts &&
  635. X            !bcmp((char *)objid_ifOutUCastPkts, (char *)vars->name,
  636. X            sizeof(objid_ifOutUCastPkts))){
  637. X                opackets += *vars->val.integer;
  638. X                snmp_add_null_var(pdu, vars->name, vars->name_length);
  639. X                good_var++;
  640. X            } else if (index == 4 && vars->name_length >= length_ifOutNUCastPkts &&
  641. X            !bcmp((char *)objid_ifOutNUCastPkts, (char *)vars->name,
  642. X            sizeof(objid_ifOutNUCastPkts))){
  643. X                opackets += *vars->val.integer;
  644. X                snmp_add_null_var(pdu, vars->name, vars->name_length);
  645. X                good_var++;
  646. X            }
  647. X            index++;
  648. X        }
  649. X        } else {
  650. X        printf("Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
  651. X        if (response->errstat == SNMP_ERR_NOSUCHNAME){
  652. X            printf("This name doesn't exist: ");
  653. X            for(count = 1, vars = response->variables; vars && count != response->errindex;
  654. X            vars = vars->next_variable, count++)
  655. X                ;
  656. X            if (vars)
  657. X            print_objid(vars->name, vars->name_length);
  658. X            printf("\n");
  659. X        }
  660. X        }
  661. X
  662. X    } else if (status == STAT_TIMEOUT){
  663. X        printf("No Response from %s\n", gateway);
  664. X    } else {    /* status == STAT_ERROR */
  665. X        printf("An error occurred, Quitting\n");
  666. X    }
  667. X
  668. X    if (response)
  669. X        snmp_free_pdu(response);
  670. X    }
  671. X    printf("Recv/Trans packets: Interfaces: %d/%d | IP: %d/%d\n", ipackets, opackets, ipin, ipout);
  672. X    if (down_interfaces > 0){
  673. X    printf("%d interface%s down!\n", down_interfaces, down_interfaces > 1 ? "s are": " is" );
  674. X    }
  675. X}
  676. X
  677. END_OF_FILE
  678.   if test 9959 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmpstatus.c'`; then
  679.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmpstatus.c'\" unpacked with wrong size!
  680.   fi
  681.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmpstatus.c'
  682. fi
  683. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmptest.c' -a "${1}" != "-c" ; then 
  684.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmptest.c'\"
  685. else
  686.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmptest.c'\" \(9304 characters\)
  687.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmptest.c' <<'END_OF_FILE'
  688. X/*
  689. X * snmptest.c - send snmp requests to a network entity.
  690. X *
  691. X */
  692. X/***********************************************************
  693. X    Copyright 1988, 1989 by Carnegie Mellon University
  694. X
  695. X                      All Rights Reserved
  696. X
  697. XPermission to use, copy, modify, and distribute this software and its 
  698. Xdocumentation for any purpose and without fee is hereby granted, 
  699. Xprovided that the above copyright notice appear in all copies and that
  700. Xboth that copyright notice and this permission notice appear in 
  701. Xsupporting documentation, and that the name of CMU not be
  702. Xused in advertising or publicity pertaining to distribution of the
  703. Xsoftware without specific, written prior permission.  
  704. X
  705. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  706. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  707. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  708. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  709. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  710. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  711. XSOFTWARE.
  712. X******************************************************************/
  713. X#include <sys/types.h>
  714. X#include <netinet/in.h>
  715. X#include <stdio.h>
  716. X#include <ctype.h>
  717. X#include <errno.h>
  718. X
  719. X#include "snmp.h"
  720. X#include "snmp_impl.h"
  721. X#include "asn1.h"
  722. X#include "snmp_api.h"
  723. X#include "snmp_client.h"
  724. X
  725. Xextern int  errno;
  726. Xint command = GET_REQ_MSG;
  727. Xint    snmp_dump_packet = 0;
  728. X
  729. Xmain(argc, argv)
  730. X    int        argc;
  731. X    char    *argv[];
  732. X{
  733. X    struct snmp_session session, *ss;
  734. X    struct snmp_pdu *pdu, *response;
  735. X    struct variable_list *vars, *vp;
  736. X    int    arg, ret;
  737. X    char *gateway = NULL;
  738. X    char *community = NULL;
  739. X    int        status, count;
  740. X
  741. X    init_mib();
  742. X    /*
  743. X     * usage: snmptest gateway-name community-name
  744. X     */
  745. X    for(arg = 1; arg < argc; arg++){
  746. X    if (argv[arg][0] == '-'){
  747. X        switch(argv[arg][1]){
  748. X        case 'd':
  749. X            snmp_dump_packet++;
  750. X            break;
  751. X        default:
  752. X            fprintf(stderr, "invalid option: -%c\n", argv[arg][1]);
  753. X            break;
  754. X        }
  755. X        continue;
  756. X    }
  757. X    if (gateway == NULL){
  758. X        gateway = argv[arg];
  759. X    } else if (community == NULL){
  760. X        community = argv[arg]; 
  761. X    } else {
  762. X        fprintf(stderr, "usage: snmptest gateway-name community-name\n");
  763. X        exit(1);
  764. X    }
  765. X    }
  766. X    if (community == NULL)
  767. X    community = "public";    /* default to public */
  768. X
  769. X    if (!(gateway && community)){
  770. X    fprintf(stderr, "usage: snmptest gateway-name community-name\n");
  771. X    exit(1);
  772. X    }
  773. X
  774. X    bzero((char *)&session, sizeof(struct snmp_session));
  775. X    session.peername = gateway;
  776. X    session.community = (u_char *)community;
  777. X    session.community_len = strlen((char *)community);
  778. X    session.retries = SNMP_DEFAULT_RETRIES;
  779. X    session.timeout = SNMP_DEFAULT_TIMEOUT;
  780. X    session.authenticator = NULL;
  781. X    snmp_synch_setup(&session);
  782. X    ss = snmp_open(&session);
  783. X    if (ss == NULL){
  784. X    fprintf(stderr, "Couldn't open snmp\n");
  785. X    exit(-1);
  786. X    }
  787. X
  788. X    while(1){
  789. X    vars = NULL;
  790. X    for(ret = 1; ret != 0;){
  791. X        vp = (struct variable_list *)malloc(sizeof(struct variable_list));
  792. X        vp->next_variable = NULL;
  793. X        vp->name = NULL;
  794. X        vp->val.string = NULL;
  795. X
  796. X        while((ret = input_variable(vp)) == -1)
  797. X        ;
  798. X        if (ret == 1){
  799. X        /* add it to the list */
  800. X        if (vars == NULL){
  801. X            /* if first variable */
  802. X            pdu = snmp_pdu_create(command);
  803. X            pdu->variables = vp;
  804. X        } else {
  805. X            vars->next_variable = vp;
  806. X        }
  807. X        vars = vp;
  808. X        } else {
  809. X        /* free the last (unused) variable */
  810. X        if (vp->name)
  811. X            free((char *)vp->name);
  812. X        if (vp->val.string)
  813. X            free((char *)vp->val.string);
  814. X        free((char *)vp);
  815. X        }
  816. X    }
  817. X    status = snmp_synch_response(ss, pdu, &response);
  818. X    if (status == STAT_SUCCESS){
  819. X        switch(response->command){
  820. X        case GET_REQ_MSG:
  821. X            printf("Received GET REQUEST ");
  822. X            break;
  823. X        case GETNEXT_REQ_MSG:
  824. X            printf("Received GETNEXT REQUEST ");
  825. X            break;
  826. X        case GET_RSP_MSG:
  827. X            printf("Received GET RESPONSE ");
  828. X            break;
  829. X        case SET_REQ_MSG:
  830. X            printf("Received SET REQUEST ");
  831. X            break;
  832. X        case TRP_REQ_MSG:
  833. X            printf("Received TRAP REQUEST ");
  834. X            break;
  835. X        }
  836. X        printf("from %s\n", inet_ntoa(response->address.sin_addr));
  837. X        printf("requestid 0x%x errstat 0x%x errindex 0x%x\n",
  838. X        response->reqid, response->errstat, response->errindex);
  839. X        if (response->errstat == SNMP_ERR_NOERROR){
  840. X        for(vars = response->variables; vars; vars = vars->next_variable)
  841. X            print_variable(vars->name, vars->name_length, vars);
  842. X        } else {
  843. X        fprintf(stderr, "Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
  844. X        if (response->errstat == SNMP_ERR_NOSUCHNAME){
  845. X            for(count = 1, vars = response->variables; vars && count != response->errindex;
  846. X            vars = vars->next_variable, count++)
  847. X                ;
  848. X            if (vars){
  849. X            printf("This name doesn't exist: ");
  850. X            print_objid(vars->name, vars->name_length);
  851. X            }
  852. X            printf("\n");
  853. X        }
  854. X        }
  855. X
  856. X    } else if (status == STAT_TIMEOUT){
  857. X        fprintf(stderr, "No Response from %s\n", gateway);
  858. X    } else {    /* status == STAT_ERROR */
  859. X        fprintf(stderr, "An error occurred, Quitting\n");
  860. X    }
  861. X
  862. X    if (response)
  863. X        snmp_free_pdu(response);
  864. X    }
  865. X}
  866. X
  867. Xint
  868. Xascii_to_binary(cp, bufp)
  869. X    u_char  *cp;
  870. X    u_char *bufp;
  871. X{
  872. X    int    subidentifier;
  873. X    u_char *bp = bufp;
  874. X
  875. X    for(; *cp != '\0'; cp++){
  876. X    if (isspace(*cp))
  877. X        continue;
  878. X    if (!isdigit(*cp)){
  879. X        fprintf(stderr, "Input error\n");
  880. X        return -1;
  881. X    }
  882. X    subidentifier = atoi(cp);
  883. X    if (subidentifier > 255){
  884. X        fprintf(stderr, "subidentifier %d is too large ( > 255)\n", subidentifier);
  885. X        return -1;
  886. X    }
  887. X    *bp++ = (u_char)subidentifier;
  888. X    while(isdigit(*cp))
  889. X        cp++;
  890. X    cp--;
  891. X    }
  892. X    return bp - bufp;
  893. X}
  894. X
  895. X
  896. Xint
  897. Xhex_to_binary(cp, bufp)
  898. X    u_char  *cp;
  899. X    u_char *bufp;
  900. X{
  901. X    int    subidentifier;
  902. X    u_char *bp = bufp;
  903. X
  904. X    for(; *cp != '\0'; cp++){
  905. X    if (isspace(*cp))
  906. X        continue;
  907. X    if (!isxdigit(*cp)){
  908. X        fprintf(stderr, "Input error\n");
  909. X        return -1;
  910. X    }
  911. X    sscanf(cp, "%x", &subidentifier);
  912. X    if (subidentifier > 255){
  913. X        fprintf(stderr, "subidentifier %d is too large ( > 255)\n", subidentifier);
  914. X        return -1;
  915. X    }
  916. X    *bp++ = (u_char)subidentifier;
  917. X    while(isxdigit(*cp))
  918. X        cp++;
  919. X    cp--;
  920. X    }
  921. X    return bp - bufp;
  922. X}
  923. X
  924. X
  925. Xinput_variable(vp)
  926. X    struct variable_list    *vp;
  927. X{
  928. X    u_char  buf[256], value[256], ch;
  929. X
  930. X    printf("Please enter the variable name: ");
  931. X    fflush(stdout);
  932. X    gets(buf);
  933. X
  934. X    if (*buf == 0){
  935. X    vp->name_length = 0;
  936. X    return 0;
  937. X    }
  938. X    if (*buf == '$'){
  939. X    switch(buf[1]){
  940. X        case 'G':
  941. X        command = GET_REQ_MSG;
  942. X        printf("Request type is GET REQUEST\n");
  943. X        break;
  944. X        case 'N':
  945. X        command = GETNEXT_REQ_MSG;
  946. X        printf("Request type is GETNEXT REQUEST\n");
  947. X        break;
  948. X        case 'S':
  949. X        command = SET_REQ_MSG;
  950. X        printf("Request type is SET REQUEST\n");
  951. X        break;
  952. X        case 'D':
  953. X        if (snmp_dump_packet){
  954. X            snmp_dump_packet = 0;
  955. X            printf("Turned packet dump off\n");
  956. X        } else {
  957. X            snmp_dump_packet = 1;
  958. X            printf("Turned packet dump on\n");
  959. X        }
  960. X        break;
  961. X        case 'Q':
  962. X        printf("Quitting,  Goodbye\n");
  963. X        exit(0);
  964. X        break;
  965. X        default:
  966. X        fprintf(stderr, "Bad command\n");
  967. X    }
  968. X    return -1;
  969. X    }
  970. X    vp->name_length = MAX_NAME_LEN;
  971. X    if (!read_objid(buf, value, &vp->name_length))
  972. X    return -1;
  973. X    vp->name = (oid *)malloc(vp->name_length * sizeof(oid));
  974. X    bcopy((char *)value, (char *)vp->name, vp->name_length * sizeof(oid));
  975. X
  976. X    if (command == SET_REQ_MSG){
  977. X    printf("Please enter variable type [i|s|x|d|n|o|t|a]: ");
  978. X    fflush(stdout);
  979. X    gets(buf);
  980. X    ch = *buf;
  981. X    switch(ch){
  982. X        case 'i':
  983. X        vp->type = INTEGER;
  984. X        break;
  985. X        case 's':
  986. X        vp->type = STRING;
  987. X        break;
  988. X        case 'x':
  989. X        vp->type = STRING;
  990. X        break;
  991. X        case 'd':
  992. X        vp->type = STRING;
  993. X        break;
  994. X        case 'n':
  995. X        vp->type = NULLOBJ;
  996. X        break;
  997. X        case 'o':
  998. X        vp->type = OBJID;
  999. X        break;
  1000. X        case 't':
  1001. X        vp->type = TIMETICKS;
  1002. X        break;
  1003. X        case 'a':
  1004. X        vp->type = IPADDRESS;
  1005. X        break;
  1006. X        default:
  1007. X        fprintf(stderr, "bad type \"%c\", use \"i\", \"s\", \"x\", \"d\", \"n\", \"o\", \"t\", or \"a\".\n", *buf);
  1008. X        return -1;
  1009. X    }
  1010. X    printf("Please enter new value: "); fflush(stdout);
  1011. X    gets(buf);
  1012. X    switch(vp->type){
  1013. X        case INTEGER:
  1014. X        vp->val.integer = (long *)malloc(sizeof(long));
  1015. X        *(vp->val.integer) = atoi(buf);
  1016. X        vp->val_len = sizeof(long);
  1017. X        break;
  1018. X        case STRING:
  1019. X        if (ch == 'd'){
  1020. X            vp->val_len = ascii_to_binary(buf, value);
  1021. X        } else if (ch == 's'){
  1022. X            strcpy(value, buf);
  1023. X            vp->val_len = strlen(buf);
  1024. X        } else if (ch == 'x'){
  1025. X            vp->val_len = hex_to_binary(buf, value);
  1026. X        }
  1027. X        vp->val.string = (u_char *)malloc(vp->val_len);
  1028. X        bcopy((char *)value, (char *)vp->val.string, vp->val_len);
  1029. X        break;
  1030. X        case NULLOBJ:
  1031. X        vp->val_len = 0;
  1032. X        vp->val.string = NULL;
  1033. X        break;
  1034. X        case OBJID:
  1035. X        vp->val_len = MAX_NAME_LEN;;
  1036. X        read_objid(buf, value, &vp->val_len);
  1037. X        vp->val_len *= sizeof(oid);
  1038. X        vp->val.objid = (oid *)malloc(vp->val_len);
  1039. X        bcopy((char *)value, (char *)vp->val.objid, vp->val_len);
  1040. X        break;
  1041. X        case TIMETICKS:
  1042. X        vp->val.integer = (long *)malloc(sizeof(long));
  1043. X        *(vp->val.integer) = atoi(buf);
  1044. X        vp->val_len = sizeof(long);
  1045. X        break;
  1046. X        case IPADDRESS:
  1047. X        vp->val.integer = (long *)malloc(sizeof(long));
  1048. X        *(vp->val.integer) = inet_addr(buf);
  1049. X        vp->val_len = sizeof(long);
  1050. X        break;
  1051. X        default:
  1052. X        fprintf(stderr, "Internal error\n");
  1053. X        break;
  1054. X    }
  1055. X    } else {    /* some form of get message */
  1056. X    vp->type = NULLOBJ;
  1057. X    vp->val_len = 0;
  1058. X    }
  1059. X    return 1;
  1060. X}
  1061. X
  1062. END_OF_FILE
  1063.   if test 9304 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmptest.c'`; then
  1064.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmptest.c'\" unpacked with wrong size!
  1065.   fi
  1066.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmptest.c'
  1067. fi
  1068. if test -f 'nocol-3.0/src/cmu-snmp/include/snmp_client.c' -a "${1}" != "-c" ; then 
  1069.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/include/snmp_client.c'\"
  1070. else
  1071.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/include/snmp_client.c'\" \(9573 characters\)
  1072.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/include/snmp_client.c' <<'END_OF_FILE'
  1073. X/*
  1074. X * snmp_client.c - a toolkit of common functions for an SNMP client.
  1075. X *
  1076. X */
  1077. X/***********************************************************
  1078. X    Copyright 1988, 1989 by Carnegie Mellon University
  1079. X
  1080. X                      All Rights Reserved
  1081. X
  1082. XPermission to use, copy, modify, and distribute this software and its 
  1083. Xdocumentation for any purpose and without fee is hereby granted, 
  1084. Xprovided that the above copyright notice appear in all copies and that
  1085. Xboth that copyright notice and this permission notice appear in 
  1086. Xsupporting documentation, and that the name of CMU not be
  1087. Xused in advertising or publicity pertaining to distribution of the
  1088. Xsoftware without specific, written prior permission.  
  1089. X
  1090. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1091. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  1092. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  1093. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1094. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1095. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1096. XSOFTWARE.
  1097. X******************************************************************/
  1098. X#include <sys/types.h>
  1099. X#include <sys/param.h>
  1100. X#include <stdio.h>
  1101. X#include <netinet/in.h>
  1102. X#include <sys/time.h>
  1103. X#include <errno.h>
  1104. X
  1105. X#include "asn1.h"
  1106. X#include "snmp.h"
  1107. X#include "snmp_impl.h"
  1108. X#include "snmp_api.h"
  1109. X#include "snmp_client.h"
  1110. X
  1111. X#ifndef BSD4_3
  1112. X#define BSD4_2
  1113. X#endif
  1114. X
  1115. X#ifndef BSD4_3
  1116. X
  1117. Xtypedef long    fd_mask;
  1118. X#define NFDBITS    (sizeof(fd_mask) * NBBY)    /* bits per mask */
  1119. X
  1120. X#define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  1121. X#define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  1122. X#define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  1123. X#define FD_ZERO(p)    bzero((char *)(p), sizeof(*(p)))
  1124. X#endif
  1125. X
  1126. X
  1127. Xextern int errno;
  1128. Xstruct synch_state snmp_synch_state;
  1129. X
  1130. Xstruct snmp_pdu *
  1131. Xsnmp_pdu_create(command)
  1132. X    int command;
  1133. X{
  1134. X    struct snmp_pdu *pdu;
  1135. X
  1136. X    pdu = (struct snmp_pdu *)malloc(sizeof(struct snmp_pdu));
  1137. X    bzero((char *)pdu, sizeof(struct snmp_pdu));
  1138. X    pdu->command = command;
  1139. X    pdu->errstat = SNMP_DEFAULT_ERRSTAT;
  1140. X    pdu->errindex = SNMP_DEFAULT_ERRINDEX;
  1141. X    pdu->address.sin_addr.s_addr = SNMP_DEFAULT_ADDRESS;
  1142. X    pdu->enterprise = NULL;
  1143. X    pdu->enterprise_length = 0;
  1144. X    pdu->variables = NULL;
  1145. X    return pdu;
  1146. X}
  1147. X
  1148. X/*
  1149. X * Add a null variable with the requested name to the end of the list of
  1150. X * variables for this pdu.
  1151. X */
  1152. Xsnmp_add_null_var(pdu, name, name_length)
  1153. X    struct snmp_pdu *pdu;
  1154. X    oid *name;
  1155. X    int name_length;
  1156. X{
  1157. X    struct variable_list *vars;
  1158. X
  1159. X    if (pdu->variables == NULL){
  1160. X    pdu->variables = vars = (struct variable_list *)malloc(sizeof(struct variable_list));
  1161. X    } else {
  1162. X    for(vars = pdu->variables; vars->next_variable; vars = vars->next_variable)
  1163. X        ;
  1164. X    vars->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
  1165. X    vars = vars->next_variable;
  1166. X    }
  1167. X
  1168. X    vars->next_variable = NULL;
  1169. X    vars->name = (oid *)malloc(name_length * sizeof(oid));
  1170. X    bcopy((char *)name, (char *)vars->name, name_length * sizeof(oid));
  1171. X    vars->name_length = name_length;
  1172. X    vars->type = ASN_NULL;
  1173. X    vars->val.string = NULL;
  1174. X    vars->val_len = 0;
  1175. X}
  1176. X
  1177. Xsnmp_synch_input(op, session, reqid, pdu, magic)
  1178. X    int op;
  1179. X    struct snmp_session *session;
  1180. X    int reqid;
  1181. X    struct snmp_pdu *pdu;
  1182. X    void *magic;
  1183. X{
  1184. X    struct variable_list *var, *newvar;
  1185. X    struct synch_state *state = (struct synch_state *)magic;
  1186. X    struct snmp_pdu *newpdu;
  1187. X
  1188. X    if (reqid != state->reqid)
  1189. X    return 0;
  1190. X    state->waiting = 0;
  1191. X    if (op == RECEIVED_MESSAGE && pdu->command == GET_RSP_MSG){
  1192. X    /* clone the pdu */
  1193. X    state->pdu = newpdu = (struct snmp_pdu *)malloc(sizeof(struct snmp_pdu));
  1194. X    bcopy((char *)pdu, (char *)newpdu, sizeof(struct snmp_pdu));
  1195. X    newpdu->variables = 0;
  1196. X    var = pdu->variables;
  1197. X    if (var != NULL){
  1198. X        newpdu->variables = newvar = (struct variable_list *)malloc(sizeof(struct variable_list));
  1199. X        bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1200. X        if (var->name != NULL){
  1201. X        newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1202. X        bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1203. X        }
  1204. X        if (var->val.string != NULL){
  1205. X        newvar->val.string = (u_char *)malloc(var->val_len);
  1206. X        bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1207. X        }
  1208. X        newvar->next_variable = 0;
  1209. X        while(var->next_variable){
  1210. X        newvar->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
  1211. X        var = var->next_variable;
  1212. X        newvar = newvar->next_variable;
  1213. X        bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1214. X        if (var->name != NULL){
  1215. X            newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1216. X            bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1217. X        }
  1218. X        if (var->val.string != NULL){
  1219. X            newvar->val.string = (u_char *)malloc(var->val_len);
  1220. X            bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1221. X        }
  1222. X        newvar->next_variable = 0;
  1223. X        }
  1224. X    }
  1225. X    state->status = STAT_SUCCESS;
  1226. X    } else if (op == TIMED_OUT){
  1227. X    state->status = STAT_TIMEOUT;
  1228. X    }
  1229. X    return 1;
  1230. X}
  1231. X
  1232. X
  1233. X/*
  1234. X * If there was an error in the input pdu, creates a clone of the pdu
  1235. X * that includes all the variables except the one marked by the errindex.
  1236. X * The command is set to the input command and the reqid, errstat, and
  1237. X * errindex are set to default values.
  1238. X * If the error status didn't indicate an error, the error index didn't
  1239. X * indicate a variable, the pdu wasn't a get response message, or there
  1240. X * would be no remaining variables, this function will return NULL.
  1241. X * If everything was successful, a pointer to the fixed cloned pdu will
  1242. X * be returned.
  1243. X */
  1244. Xstruct snmp_pdu *
  1245. Xsnmp_fix_pdu(pdu, command)
  1246. X    struct snmp_pdu *pdu;
  1247. X    int command;
  1248. X{
  1249. X    struct variable_list *var, *newvar;
  1250. X    struct snmp_pdu *newpdu;
  1251. X    int index, copied = 0;
  1252. X
  1253. X    if (pdu->command != GET_RSP_MSG || pdu->errstat == SNMP_ERR_NOERROR || pdu->errindex <= 0)
  1254. X    return NULL;
  1255. X    /* clone the pdu */
  1256. X    newpdu = (struct snmp_pdu *)malloc(sizeof(struct snmp_pdu));
  1257. X    bcopy((char *)pdu, (char *)newpdu, sizeof(struct snmp_pdu));
  1258. X    newpdu->variables = 0;
  1259. X    newpdu->command = command;
  1260. X    newpdu->reqid = SNMP_DEFAULT_REQID;
  1261. X    newpdu->errstat = SNMP_DEFAULT_ERRSTAT;
  1262. X    newpdu->errindex = SNMP_DEFAULT_ERRINDEX;
  1263. X    var = pdu->variables;
  1264. X    index = 1;
  1265. X    if (pdu->errindex == index){    /* skip first variable */
  1266. X    var = var->next_variable;
  1267. X    index++;
  1268. X    }
  1269. X    if (var != NULL){
  1270. X    newpdu->variables = newvar = (struct variable_list *)malloc(sizeof(struct variable_list));
  1271. X    bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1272. X    if (var->name != NULL){
  1273. X        newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1274. X        bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1275. X    }
  1276. X    if (var->val.string != NULL){
  1277. X        newvar->val.string = (u_char *)malloc(var->val_len);
  1278. X        bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1279. X    }
  1280. X    newvar->next_variable = 0;
  1281. X    copied++;
  1282. X
  1283. X    while(var->next_variable){
  1284. X        var = var->next_variable;
  1285. X        if (++index == pdu->errindex)
  1286. X        continue;
  1287. X        newvar->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
  1288. X        newvar = newvar->next_variable;
  1289. X        bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1290. X        if (var->name != NULL){
  1291. X        newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1292. X        bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1293. X        }
  1294. X        if (var->val.string != NULL){
  1295. X        newvar->val.string = (u_char *)malloc(var->val_len);
  1296. X        bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1297. X        }
  1298. X        newvar->next_variable = 0;
  1299. X        copied++;
  1300. X    }
  1301. X    }
  1302. X    if (index < pdu->errindex || copied == 0){
  1303. X    snmp_free_pdu(newpdu);
  1304. X    return NULL;
  1305. X    }
  1306. X    return newpdu;
  1307. X}
  1308. X
  1309. X
  1310. Xint
  1311. Xsnmp_synch_response(ss, pdu, response)
  1312. X    struct snmp_session *ss;
  1313. X    struct snmp_pdu *pdu;
  1314. X    struct snmp_pdu **response;
  1315. X{
  1316. X    struct synch_state *state = &snmp_synch_state;
  1317. X    int numfds, count;
  1318. X    fd_set fdset;
  1319. X    struct timeval timeout, *tvp;
  1320. X    int block;
  1321. X
  1322. X
  1323. X    if ((state->reqid = snmp_send(ss, pdu)) == 0){
  1324. X    *response = NULL;
  1325. X    snmp_free_pdu(pdu);
  1326. X    return STAT_ERROR;
  1327. X    }
  1328. X    state->waiting = 1;
  1329. X
  1330. X    while(state->waiting){
  1331. X    numfds = 0;
  1332. X    FD_ZERO(&fdset);
  1333. X    block = 1;
  1334. X    tvp = &timeout;
  1335. X    timerclear(tvp);
  1336. X    snmp_select_info(&numfds, &fdset, tvp, &block);
  1337. X    if (block == 1)
  1338. X        tvp = NULL;    /* block without timeout */
  1339. X    count = select(numfds, &fdset, 0, 0, tvp);
  1340. X    if (count > 0){
  1341. X        snmp_read(&fdset);
  1342. X    } else switch(count){
  1343. X        case 0:
  1344. X        snmp_timeout();
  1345. X        break;
  1346. X        case -1:
  1347. X        if (errno == EINTR){
  1348. X            continue;
  1349. X        } else {
  1350. X            perror("select");
  1351. X        }
  1352. X        /* FALLTHRU */
  1353. X        default:
  1354. X        return STAT_ERROR;
  1355. X    }
  1356. X    }
  1357. X    *response = state->pdu;
  1358. X    return state->status;
  1359. X}
  1360. X
  1361. Xsnmp_synch_setup(session)
  1362. X    struct snmp_session *session;
  1363. X{
  1364. X    session->callback = snmp_synch_input;
  1365. X    session->callback_magic = (void *)&snmp_synch_state;
  1366. X}
  1367. X
  1368. Xchar    *error_string[6] = {
  1369. X    "No Error",
  1370. X    "Response message would have been too large.",
  1371. X    "There is no such variable name in this MIB.",
  1372. X    "The value given has the wrong type or length",
  1373. X    "This variable is read only",
  1374. X    "A general failure occured"
  1375. X};
  1376. X
  1377. Xchar *
  1378. Xsnmp_errstring(errstat)
  1379. X    int    errstat;
  1380. X{
  1381. X    if (errstat <= SNMP_ERR_GENERR && errstat >= SNMP_ERR_NOERROR){
  1382. X    return error_string[errstat];
  1383. X    } else {
  1384. X    return "Unknown Error";
  1385. X    }
  1386. X}
  1387. END_OF_FILE
  1388.   if test 9573 -ne `wc -c <'nocol-3.0/src/cmu-snmp/include/snmp_client.c'`; then
  1389.     echo shar: \"'nocol-3.0/src/cmu-snmp/include/snmp_client.c'\" unpacked with wrong size!
  1390.   fi
  1391.   # end of 'nocol-3.0/src/cmu-snmp/include/snmp_client.c'
  1392. fi
  1393. if test -f 'nocol-3.0/src/cmu-snmp/snmplib/snmp_client.c' -a "${1}" != "-c" ; then 
  1394.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/snmplib/snmp_client.c'\"
  1395. else
  1396.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/snmplib/snmp_client.c'\" \(9675 characters\)
  1397.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/snmplib/snmp_client.c' <<'END_OF_FILE'
  1398. X/*
  1399. X * snmp_client.c - a toolkit of common functions for an SNMP client.
  1400. X *
  1401. X */
  1402. X/***********************************************************
  1403. X    Copyright 1988, 1989 by Carnegie Mellon University
  1404. X
  1405. X                      All Rights Reserved
  1406. X
  1407. XPermission to use, copy, modify, and distribute this software and its 
  1408. Xdocumentation for any purpose and without fee is hereby granted, 
  1409. Xprovided that the above copyright notice appear in all copies and that
  1410. Xboth that copyright notice and this permission notice appear in 
  1411. Xsupporting documentation, and that the name of CMU not be
  1412. Xused in advertising or publicity pertaining to distribution of the
  1413. Xsoftware without specific, written prior permission.  
  1414. X
  1415. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1416. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  1417. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  1418. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1419. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1420. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1421. XSOFTWARE.
  1422. X******************************************************************/
  1423. X#include <sys/types.h>
  1424. X#include <sys/param.h>
  1425. X#include <stdio.h>
  1426. X#include <netinet/in.h>
  1427. X#include <sys/time.h>
  1428. X#include <errno.h>
  1429. X
  1430. X#include "asn1.h"
  1431. X#include "snmp.h"
  1432. X#include "snmp_impl.h"
  1433. X#include "snmp_api.h"
  1434. X#include "snmp_client.h"
  1435. X
  1436. X#ifndef BSD4_3
  1437. X#define BSD4_2
  1438. X#endif
  1439. X
  1440. X#if defined(FD_SET)  ||  defined(BSD4_3)
  1441. X# define HAVE_FD_MACROS
  1442. X#endif
  1443. X
  1444. X#ifndef HAVE_FD_MACROS
  1445. X
  1446. Xtypedef long    fd_mask;
  1447. X#define NFDBITS    (sizeof(fd_mask) * NBBY)    /* bits per mask */
  1448. X
  1449. X#define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  1450. X#define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  1451. X#define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  1452. X#define FD_ZERO(p)    bzero((char *)(p), sizeof(*(p)))
  1453. X#endif    /* HAVE_FD_MACROS */
  1454. X
  1455. X
  1456. Xextern int errno;
  1457. Xstruct synch_state snmp_synch_state;
  1458. X
  1459. Xstruct snmp_pdu *
  1460. Xsnmp_pdu_create(command)
  1461. X    int command;
  1462. X{
  1463. X    struct snmp_pdu *pdu;
  1464. X
  1465. X    pdu = (struct snmp_pdu *)malloc(sizeof(struct snmp_pdu));
  1466. X    bzero((char *)pdu, sizeof(struct snmp_pdu));
  1467. X    pdu->command = command;
  1468. X    pdu->errstat = SNMP_DEFAULT_ERRSTAT;
  1469. X    pdu->errindex = SNMP_DEFAULT_ERRINDEX;
  1470. X    pdu->address.sin_addr.s_addr = SNMP_DEFAULT_ADDRESS;
  1471. X    pdu->enterprise = NULL;
  1472. X    pdu->enterprise_length = 0;
  1473. X    pdu->variables = NULL;
  1474. X    return pdu;
  1475. X}
  1476. X
  1477. X/*
  1478. X * Add a null variable with the requested name to the end of the list of
  1479. X * variables for this pdu.
  1480. X */
  1481. Xsnmp_add_null_var(pdu, name, name_length)
  1482. X    struct snmp_pdu *pdu;
  1483. X    oid *name;
  1484. X    int name_length;
  1485. X{
  1486. X    struct variable_list *vars;
  1487. X
  1488. X    if (pdu->variables == NULL){
  1489. X    pdu->variables = vars = (struct variable_list *)malloc(sizeof(struct variable_list));
  1490. X    } else {
  1491. X    for(vars = pdu->variables; vars->next_variable; vars = vars->next_variable)
  1492. X        ;
  1493. X    vars->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
  1494. X    vars = vars->next_variable;
  1495. X    }
  1496. X
  1497. X    vars->next_variable = NULL;
  1498. X    vars->name = (oid *)malloc(name_length * sizeof(oid));
  1499. X    bcopy((char *)name, (char *)vars->name, name_length * sizeof(oid));
  1500. X    vars->name_length = name_length;
  1501. X    vars->type = ASN_NULL;
  1502. X    vars->val.string = NULL;
  1503. X    vars->val_len = 0;
  1504. X}
  1505. X
  1506. Xsnmp_synch_input(op, session, reqid, pdu, magic)
  1507. X    int op;
  1508. X    struct snmp_session *session;
  1509. X    int reqid;
  1510. X    struct snmp_pdu *pdu;
  1511. X    void *magic;
  1512. X{
  1513. X    struct variable_list *var, *newvar;
  1514. X    struct synch_state *state = (struct synch_state *)magic;
  1515. X    struct snmp_pdu *newpdu;
  1516. X
  1517. X    if (reqid != state->reqid)
  1518. X    return 0;
  1519. X    state->waiting = 0;
  1520. X    if (op == RECEIVED_MESSAGE && pdu->command == GET_RSP_MSG){
  1521. X    /* clone the pdu */
  1522. X    state->pdu = newpdu = (struct snmp_pdu *)malloc(sizeof(struct snmp_pdu));
  1523. X    bcopy((char *)pdu, (char *)newpdu, sizeof(struct snmp_pdu));
  1524. X    newpdu->variables = 0;
  1525. X    var = pdu->variables;
  1526. X    if (var != NULL){
  1527. X        newpdu->variables = newvar = (struct variable_list *)malloc(sizeof(struct variable_list));
  1528. X        bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1529. X        if (var->name != NULL){
  1530. X        newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1531. X        bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1532. X        }
  1533. X        if (var->val.string != NULL){
  1534. X        newvar->val.string = (u_char *)malloc(var->val_len);
  1535. X        bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1536. X        }
  1537. X        newvar->next_variable = 0;
  1538. X        while(var->next_variable){
  1539. X        newvar->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
  1540. X        var = var->next_variable;
  1541. X        newvar = newvar->next_variable;
  1542. X        bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1543. X        if (var->name != NULL){
  1544. X            newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1545. X            bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1546. X        }
  1547. X        if (var->val.string != NULL){
  1548. X            newvar->val.string = (u_char *)malloc(var->val_len);
  1549. X            bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1550. X        }
  1551. X        newvar->next_variable = 0;
  1552. X        }
  1553. X    }
  1554. X    state->status = STAT_SUCCESS;
  1555. X    } else if (op == TIMED_OUT){
  1556. X    state->status = STAT_TIMEOUT;
  1557. X    }
  1558. X    return 1;
  1559. X}
  1560. X
  1561. X
  1562. X/*
  1563. X * If there was an error in the input pdu, creates a clone of the pdu
  1564. X * that includes all the variables except the one marked by the errindex.
  1565. X * The command is set to the input command and the reqid, errstat, and
  1566. X * errindex are set to default values.
  1567. X * If the error status didn't indicate an error, the error index didn't
  1568. X * indicate a variable, the pdu wasn't a get response message, or there
  1569. X * would be no remaining variables, this function will return NULL.
  1570. X * If everything was successful, a pointer to the fixed cloned pdu will
  1571. X * be returned.
  1572. X */
  1573. Xstruct snmp_pdu *
  1574. Xsnmp_fix_pdu(pdu, command)
  1575. X    struct snmp_pdu *pdu;
  1576. X    int command;
  1577. X{
  1578. X    struct variable_list *var, *newvar;
  1579. X    struct snmp_pdu *newpdu;
  1580. X    int index, copied = 0;
  1581. X
  1582. X    if (pdu->command != GET_RSP_MSG || pdu->errstat == SNMP_ERR_NOERROR || pdu->errindex <= 0)
  1583. X    return NULL;
  1584. X    /* clone the pdu */
  1585. X    newpdu = (struct snmp_pdu *)malloc(sizeof(struct snmp_pdu));
  1586. X    bcopy((char *)pdu, (char *)newpdu, sizeof(struct snmp_pdu));
  1587. X    newpdu->variables = 0;
  1588. X    newpdu->command = command;
  1589. X    newpdu->reqid = SNMP_DEFAULT_REQID;
  1590. X    newpdu->errstat = SNMP_DEFAULT_ERRSTAT;
  1591. X    newpdu->errindex = SNMP_DEFAULT_ERRINDEX;
  1592. X    var = pdu->variables;
  1593. X    index = 1;
  1594. X    if (pdu->errindex == index){    /* skip first variable */
  1595. X    var = var->next_variable;
  1596. X    index++;
  1597. X    }
  1598. X    if (var != NULL){
  1599. X    newpdu->variables = newvar = (struct variable_list *)malloc(sizeof(struct variable_list));
  1600. X    bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1601. X    if (var->name != NULL){
  1602. X        newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1603. X        bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1604. X    }
  1605. X    if (var->val.string != NULL){
  1606. X        newvar->val.string = (u_char *)malloc(var->val_len);
  1607. X        bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1608. X    }
  1609. X    newvar->next_variable = 0;
  1610. X    copied++;
  1611. X
  1612. X    while(var->next_variable){
  1613. X        var = var->next_variable;
  1614. X        if (++index == pdu->errindex)
  1615. X        continue;
  1616. X        newvar->next_variable = (struct variable_list *)malloc(sizeof(struct variable_list));
  1617. X        newvar = newvar->next_variable;
  1618. X        bcopy((char *)var, (char *)newvar, sizeof(struct variable_list));
  1619. X        if (var->name != NULL){
  1620. X        newvar->name = (oid *)malloc(var->name_length * sizeof(oid));
  1621. X        bcopy((char *)var->name, (char *)newvar->name, var->name_length * sizeof(oid));
  1622. X        }
  1623. X        if (var->val.string != NULL){
  1624. X        newvar->val.string = (u_char *)malloc(var->val_len);
  1625. X        bcopy((char *)var->val.string, (char *)newvar->val.string, var->val_len);
  1626. X        }
  1627. X        newvar->next_variable = 0;
  1628. X        copied++;
  1629. X    }
  1630. X    }
  1631. X    if (index < pdu->errindex || copied == 0){
  1632. X    snmp_free_pdu(newpdu);
  1633. X    return NULL;
  1634. X    }
  1635. X    return newpdu;
  1636. X}
  1637. X
  1638. X
  1639. Xint
  1640. Xsnmp_synch_response(ss, pdu, response)
  1641. X    struct snmp_session *ss;
  1642. X    struct snmp_pdu *pdu;
  1643. X    struct snmp_pdu **response;
  1644. X{
  1645. X    struct synch_state *state = &snmp_synch_state;
  1646. X    int numfds, count;
  1647. X    fd_set fdset;
  1648. X    struct timeval timeout, *tvp;
  1649. X    int block;
  1650. X
  1651. X
  1652. X    if ((state->reqid = snmp_send(ss, pdu)) == 0){
  1653. X    *response = NULL;
  1654. X    snmp_free_pdu(pdu);
  1655. X    return STAT_ERROR;
  1656. X    }
  1657. X    state->waiting = 1;
  1658. X
  1659. X    while(state->waiting){
  1660. X    numfds = 0;
  1661. X    FD_ZERO(&fdset);
  1662. X    block = 1;
  1663. X    tvp = &timeout;
  1664. X    timerclear(tvp);
  1665. X    snmp_select_info(&numfds, &fdset, tvp, &block);
  1666. X    if (block == 1)
  1667. X        tvp = NULL;    /* block without timeout */
  1668. X    count = select(numfds, &fdset, 0, 0, tvp);
  1669. X    if (count > 0){
  1670. X        snmp_read(&fdset);
  1671. X    } else switch(count){
  1672. X        case 0:
  1673. X        snmp_timeout();
  1674. X        break;
  1675. X        case -1:
  1676. X        if (errno == EINTR){
  1677. X            continue;
  1678. X        } else {
  1679. X            perror("select");
  1680. X        }
  1681. X        /* FALLTHRU */
  1682. X        default:
  1683. X        return STAT_ERROR;
  1684. X    }
  1685. X    }
  1686. X    *response = state->pdu;
  1687. X    return state->status;
  1688. X}
  1689. X
  1690. Xsnmp_synch_setup(session)
  1691. X    struct snmp_session *session;
  1692. X{
  1693. X    session->callback = snmp_synch_input;
  1694. X    session->callback_magic = (void *)&snmp_synch_state;
  1695. X}
  1696. X
  1697. Xchar    *error_string[6] = {
  1698. X    "No Error",
  1699. X    "Response message would have been too large.",
  1700. X    "There is no such variable name in this MIB.",
  1701. X    "The value given has the wrong type or length",
  1702. X    "This variable is read only",
  1703. X    "A general failure occured"
  1704. X};
  1705. X
  1706. Xchar *
  1707. Xsnmp_errstring(errstat)
  1708. X    int    errstat;
  1709. X{
  1710. X    if (errstat <= SNMP_ERR_GENERR && errstat >= SNMP_ERR_NOERROR){
  1711. X    return error_string[errstat];
  1712. X    } else {
  1713. X    return "Unknown Error";
  1714. X    }
  1715. X}
  1716. END_OF_FILE
  1717.   if test 9675 -ne `wc -c <'nocol-3.0/src/cmu-snmp/snmplib/snmp_client.c'`; then
  1718.     echo shar: \"'nocol-3.0/src/cmu-snmp/snmplib/snmp_client.c'\" unpacked with wrong size!
  1719.   fi
  1720.   # end of 'nocol-3.0/src/cmu-snmp/snmplib/snmp_client.c'
  1721. fi
  1722. if test -f 'nocol-3.0/src/netmon/filter.c' -a "${1}" != "-c" ; then 
  1723.   echo shar: Will not clobber existing file \"'nocol-3.0/src/netmon/filter.c'\"
  1724. else
  1725.   echo shar: Extracting \"'nocol-3.0/src/netmon/filter.c'\" \(9886 characters\)
  1726.   sed "s/^X//" >'nocol-3.0/src/netmon/filter.c' <<'END_OF_FILE'
  1727. X/*
  1728. X * $Header: /home/aggarwal/lsrc/nocol/src/netmon/RCS/filter.c,v 1.2 1993/10/30 03:51:36 aggarwal Exp $
  1729. X */
  1730. X
  1731. X/* Copyright 1992 JvNCnet, Princeton */
  1732. X
  1733. X/*+
  1734. X ** The functions 'compile_pattern' and 'filter' allow NETMON to filter 
  1735. X ** out only the information that the user desires.  Logical AND and OR 
  1736. X ** is also incorporated in this feature, allowing input such as:
  1737. X **
  1738. X ** airport | 13:27 & Error (prints status of the 'airport' sites as well
  1739. X **                          any errors that occurred at 13:27)
  1740. X ** 
  1741. X ** 'compile_pattern' works like this:
  1742. X **
  1743. X ** A new argument is started every time an AND (&) operator is
  1744. X ** encountered.
  1745. X ** 
  1746. X ** A new row of arguments is started every time an OR (|) operator is
  1747. X ** encountered.
  1748. X **
  1749. X ** So, if the input is: THIS & THAT | YOU & ME | WHATEVER | A & B & C
  1750. X ** The pointers would be assigned as follows:
  1751. X **
  1752. X ** compiled[0][0] = "THIS"        compiled[0][1] = "THAT"
  1753. X ** compiled[1][0] = "YOU"        compiled[1][1] = "ME"
  1754. X ** compiled[2][0] = "WHATEVER"
  1755. X ** compiled[3][0] = "A"        compiled[3][1] = "B"    compiled[3][2] = "C"
  1756. X **
  1757. X ** 'filter' filters out the desired information by comparing the
  1758. X ** EVENT data structure against the arguments row by row, argument by
  1759. X ** argument.
  1760. X **
  1761. X ** Given the data above, 'filter' would first check arguments of
  1762. X ** row 0.  If THIS (args[0][0]) was not in the data, the whole row can
  1763. X ** be skipped because we know that (THIS & THAT) will be FALSE. 
  1764. X **
  1765. X ** 'filter' returns 1 if any of the rows of arguments match,
  1766. X ** otherwise it returns 0.
  1767. X**/
  1768. X
  1769. X/*
  1770. X * $Log: filter.c,v $
  1771. X * Revision 1.2  1993/10/30  03:51:36  aggarwal
  1772. X * Changed the name from filter() to nocolfilter()
  1773. X *
  1774. X * Revision 1.1  1992/06/18  21:03:49  aggarwal
  1775. X * Initial revision
  1776. X *
  1777. X */
  1778. X
  1779. X#include "netmon.h"
  1780. X#include <string.h>
  1781. X
  1782. X#define MAXARGS        20            /* Max # of search words */
  1783. X#define MAXTEXTLEN    10000            /* Max length of pattern */
  1784. X
  1785. Xvoid compile_pattern();
  1786. Xint nocolfilter();
  1787. X
  1788. Xstatic char *(compiled[MAXARGS][MAXARGS]);    /* Compiled pattern */
  1789. Xstatic char pattern_defined=0;            /* Is a pattern specified? */
  1790. X
  1791. X#ifdef FILTERMAIN
  1792. X
  1793. X#include <stdio.h>
  1794. X#include <sys/file.h>
  1795. X#include <arpa/inet.h>
  1796. X
  1797. X#define    MAXFILTERLEN     1024
  1798. X#define FILENAME  "/nocol/data/ippingmon-data"    /* nocol data file */
  1799. X
  1800. X
  1801. Xint main(argc,argv)
  1802. X     int argc;
  1803. X     char *argv[];
  1804. X{
  1805. X    int i, j, fd;
  1806. X    EVENT v;                                    /* defined in nocol.h        */
  1807. X    char *p;
  1808. X    char argline[MAXFILTERLEN];
  1809. X
  1810. X    *argline = '\0';                /* Start argline[] off fresh */
  1811. X
  1812. X    /* Let's get the arguments that we are going to search for */
  1813. X    if (argc > 1)
  1814. X      /* The arguments we need are on the command line - use them */
  1815. X      for (i=1; i < argc; i++) {
  1816. X      /* Throw the entire command line into argline[] */
  1817. X      strncat(argline, argv[i], MAXFILTERLEN);
  1818. X      strncat(argline, " ", MAXFILTERLEN);
  1819. X      } /* end of for */
  1820. X    else {                    /* Nothing useful in argv[] */
  1821. X     printf("arguments> ");            /* Prompt for arguments */
  1822. X
  1823. X    for (i=0; i < MAXFILTERLEN; ) {        /* Build argline[] */
  1824. X        /*
  1825. X        ** Read one line & append it to argline[]
  1826. X        ** Don't forget to replace the NUL terminator ('\0')
  1827. X        ** with a space!
  1828. X        */
  1829. X        if (gets( &(argline[i]) ) == NULL)
  1830. X          break;
  1831. X        i = strlen(argline);
  1832. X        argline[i++] = ' ';
  1833. X    }
  1834. X
  1835. X    /* Now, we killed the last NUL terminator - put it back */
  1836. X    argline[i] = '\0';
  1837. X    }
  1838. X
  1839. X    /* If "DISABLE" is one of the arguments, quit */
  1840. X    if (strstr(argline,"DISABLE")) {
  1841. X    printf("SEARCH DISABLED\n");
  1842. X    exit(1);
  1843. X    }
  1844. X
  1845. X    compile_pattern(argline);            /* Parse argline[] */
  1846. X
  1847. X    /* Open the file - if it doesn't exist, give error and exit */
  1848. X    if ((fd = open(FILENAME, O_RDONLY)) == -1) {
  1849. X    fprintf(stderr,"Error: main unable to open file %s\n", FILENAME);
  1850. X    exit(1);
  1851. X    }
  1852. X
  1853. X    /* Read each EVENT structure in, one by one */
  1854. X    while (read(fd, (char *) &v, sizeof(v)) == sizeof(v)) {
  1855. X    /* Does this EVENT structure match the arguments? */
  1856. X    if (nocolfilter(&v))    {
  1857. X        /*
  1858. X        ** It does!  Print it out
  1859. X        ** But do we want the extended format or the short format?
  1860. X        */
  1861. X        if (options & emode)
  1862. X          /* Extended format - EFMT, EFIELDS are defined in netmon.h */
  1863. X          printf(EFMT, EFIELDS);
  1864. X        else
  1865. X          /* Short format - SFTM, SFIELDS are defined in netmon.h */
  1866. X          printf(SFMT, SFIELDS);
  1867. X
  1868. X        printf("\n");            /* Don't forget the newline! */
  1869. X    } /* end of if */
  1870. X    } /* end of while */
  1871. X
  1872. X    close(FILENAME);                /* All done, so close it */
  1873. X} /* end of main */
  1874. X
  1875. X#endif /* end of #ifdef FILTERMAIN */
  1876. X
  1877. X    
  1878. X/*+ 
  1879. X** FUNCTION: compile_pattern  
  1880. X**
  1881. X** Copies the string of arguments 'pattern' to a temporary string,
  1882. X** eliminating invalid characters and converting valid characters to
  1883. X** lowercase.
  1884. X**
  1885. X** The locations of the arguments within 'pattern' are stored in the
  1886. X** global static two-dimensional array of pointers 'compiled[row][col]'.  
  1887. X**
  1888. X** If an AND (&) is encountered, it is interpreted as a logical AND,
  1889. X** and means that the argument to follow is to included in the current
  1890. X** row (or group) of arguments.  Therefore, 'col' is increased by
  1891. X** 1, while 'row' remains unchanged.
  1892. X**
  1893. X** If an OR (|) is encountered, it is interpreted as a logical OR,
  1894. X** and means that the argument to follow is to be included in a new
  1895. X** row (or group) of arguments.  Therefore, 'row' is increased by 1,
  1896. X** and 'col' is set to zero (to start at the beginning of the row).
  1897. X**
  1898. X** Spaces and tabs are ignored, and any other characters are added to
  1899. X** the end of the current argument.
  1900. X**/
  1901. X
  1902. X
  1903. Xvoid compile_pattern(pattern)
  1904. X     char *pattern;
  1905. X{
  1906. X    static char text[MAXTEXTLEN];        /* Cooked form of pattern */
  1907. X    char *s, *t;
  1908. X    int row, col;
  1909. X    int was_conjunction;            /* Was previous word AND/OR? */
  1910. X
  1911. X    if (strlen(pattern) > 0)
  1912. X      pattern_defined = 1;            /* Enable filtering */
  1913. X    else
  1914. X      pattern_defined = 0;            /* Disable filtering */
  1915. X
  1916. X    /*
  1917. X    ** We don't want to see a conjunction right off the bat,
  1918. X    ** so pretend we just saw one...  then we'll ignore any
  1919. X    ** conjunctions that come before normal arguments
  1920. X    */
  1921. X    was_conjunction = 1;
  1922. X
  1923. X    /* Run through the pattern one character at a time */
  1924. X    t = text;
  1925. X    s = pattern;
  1926. X    row = col = 0;
  1927. X    while (*s != '\0')
  1928. X    switch(*s) {
  1929. X     case ' ': case '\t':             /* skip white space */
  1930. X        s++; break;       
  1931. X
  1932. X     case '|' :                /* OR */
  1933. X       /* If the last thing was a conjunction, ignore this one */
  1934. X       if (! was_conjunction) {        /* Begin a new row */
  1935. X           *t++ = '\0';
  1936. X           compiled[++row][0] = ++t;
  1937. X           col = 0;
  1938. X
  1939. X           was_conjunction = 1;           /* Remember we saw a conj. */
  1940. X       }
  1941. X        s++; break;
  1942. X          
  1943. X     case '&' :                /* AND */
  1944. X       /* If the last thing was a conjunction, ignore this one */
  1945. X       if (! was_conjunction) {
  1946. X           *t++ = '\0';            /* Goto next column */
  1947. X           compiled[row][++col] = t;
  1948. X
  1949. X           was_conjunction = 1;        /* Remember we saw a conj. */
  1950. X       }
  1951. X        s++; break;
  1952. X
  1953. X     default:                /* any normal character */
  1954. X        *t = tolower(*s);            /* Make everything lowercase */
  1955. X
  1956. X        /*
  1957. X        ** If the last thing was a conjunction, then this must
  1958. X        ** be the start of a normal argument - so save a pointer
  1959. X        ** to the beginning of this word in sargs[][]
  1960. X        **
  1961. X        ** Then, t will just skip over the rest of the characters
  1962. X        ** in the word
  1963. X        */
  1964. X        if (was_conjunction)
  1965. X          compiled[row][col] = t;
  1966. X        t++;
  1967. X        s++;
  1968. X
  1969. X        /* Remember this wasn't a conjunction */
  1970. X        was_conjunction = 0;
  1971. X        break;
  1972. X    } /* end of switch */
  1973. X
  1974. X    /* By the way, we're NOT in the while loop anymore */
  1975. X
  1976. X    *t='\0';                /* Don't forget the NUL terminator */
  1977. X
  1978. X    /* Deal with the case where the last thing we saw was a conjunction */
  1979. X    if (was_conjunction)
  1980. X      compiled[row][col]=NULL;
  1981. X
  1982. X    /*
  1983. X    ** Add a NULL terminator to our list of rows so we know
  1984. X    ** where the end is (remember, the arguments are global)
  1985. X    */
  1986. X    compiled[++row][col]=NULL;
  1987. X} /* end of compile_pattern */
  1988. X
  1989. X
  1990. X
  1991. X
  1992. X
  1993. X/*+ 
  1994. X** FUNCTION: nocolfilter
  1995. X**
  1996. X** Searches for arguments in the data structure 'v' by their
  1997. X** respective groups as stored in 'args[row][argnum]'.
  1998. X**
  1999. X** Searching begins with the first row, argument by argument.  If an
  2000. X** argument is not found in 'v' then searching stops in that row and
  2001. X** moves to the next.
  2002. X**
  2003. X** If all arguments in a row are found in 'v' then this EVENT structure
  2004. X** matches are filter condition and we may return TRUE immediately.
  2005. X**/
  2006. X
  2007. X
  2008. Xint nocolfilter(vptr)
  2009. X     EVENT *vptr;
  2010. X{
  2011. X    EVENT v;
  2012. X    char line[1024];
  2013. X    char *p;
  2014. X    int row, col;
  2015. X
  2016. X    if (!pattern_defined)            /* If no pattern specified, */
  2017. X    return (1);                /* then don't filter anything */
  2018. X    /*
  2019. X    ** Copy the EVENT structure pointed by vptr into v
  2020. X    ** This is done because the EFIELDS and SFIELDS #define's
  2021. X    ** were set up assuming v would be a EVENT structure,
  2022. X    ** not a pointer to one
  2023. X    ** Yes, I know this qualifies as an ugly hack...
  2024. X    */
  2025. X    bcopy((char *) vptr, (char *) &v, sizeof(v));
  2026. X
  2027. X    /*
  2028. X    ** Throw everything in v into one big formatted line
  2029. X    ** This make searching a lot easier
  2030. X    */
  2031. X    if (options & emode)
  2032. X      /* Extended format - EFMT, EFIELDS are defined in netmon.h */
  2033. X      sprintf(line, EFMT, EFIELDS);
  2034. X    else
  2035. X      /* Short format - SFMT, SFIELDS are defined in netmon.h */
  2036. X      sprintf(line, SFMT, SFIELDS);
  2037. X
  2038. X    for (p=line; *p != '\0'; p++)        /* Make everything lowercase */
  2039. X      *p = tolower(*p);
  2040. X
  2041. X    /* Loop through the rows one by one... */
  2042. X    for (row=0; compiled[row][0] != NULL; row++) {
  2043. X    /*
  2044. X    ** If all the arguments on this row match line[],
  2045. X    ** then return TRUE right away - this EVENT structure
  2046. X    ** should pass through the filter
  2047. X    */
  2048. X    for (col=0; compiled[row][col] != NULL; col++)
  2049. X      if (! strstr(line, compiled[row][col]))
  2050. X        break;
  2051. X
  2052. X    if (compiled[row][col] == NULL)
  2053. X      return(1);                /* Match found */
  2054. X
  2055. X    /*
  2056. X    ** There were still arguments left on this row.
  2057. X    ** I guess line[] doesn't match this row - so let's try another!
  2058. X    */
  2059. X    }
  2060. X
  2061. X    return(0);                    /* Match not found */
  2062. X} /* end of filter */
  2063. END_OF_FILE
  2064.   if test 9886 -ne `wc -c <'nocol-3.0/src/netmon/filter.c'`; then
  2065.     echo shar: \"'nocol-3.0/src/netmon/filter.c'\" unpacked with wrong size!
  2066.   fi
  2067.   # end of 'nocol-3.0/src/netmon/filter.c'
  2068. fi
  2069. if test -f 'nocol-3.0/src/perlnocol/nrmon' -a "${1}" != "-c" ; then 
  2070.   echo shar: Will not clobber existing file \"'nocol-3.0/src/perlnocol/nrmon'\"
  2071. else
  2072.   echo shar: Extracting \"'nocol-3.0/src/perlnocol/nrmon'\" \(9574 characters\)
  2073.   sed "s/^X//" >'nocol-3.0/src/perlnocol/nrmon' <<'END_OF_FILE'
  2074. X#!/usr/local/bin/perl 
  2075. X#
  2076. X# $Header: /home/aggarwal/lsrc/nocol/src/perlnocol/RCS/nrmon,v 1.3 1993/11/02 04:05:48 aggarwal Exp $
  2077. X#
  2078. X#     nrmon - perl nocol NOVELL route monitor
  2079. X#
  2080. X# Date: September 21, 1993
  2081. X# Programmer: John Wobus, jmwobus@mailbox.syr.edu
  2082. X#  Modifications:  vikas@jvnc.net
  2083. X#
  2084. X#    (c) Syracuse University Computing & Network Services 1993
  2085. X#
  2086. X# No warranty is expressed or implied.  Permission to copy and use is
  2087. X# extended to all.  Permission to redistribute is granted under the
  2088. X# following conditions: it is not sold for profit; this copyright
  2089. X# notice remains intact; the same permissions extend to the recipient;
  2090. X# and if any changes are made, a notice is added so stating.
  2091. X#
  2092. X#####################
  2093. X#
  2094. X# Command Format:
  2095. X#
  2096. X#  nrmon
  2097. X#
  2098. X#    Automatically kills old process and forks a new one, reading
  2099. X#    the configuration file in the process.
  2100. X#
  2101. X# What it does:
  2102. X#
  2103. X#    nrmon reads the NOVELL routing table from a Cisco router and compares
  2104. X#    it with its own configuration file and reports the differences
  2105. X#    through nocol.  Nocol reports two kinds of problems:
  2106. X
  2107. X#    Site      Address      Time   +-Variable-+ +-Value-+  Condition
  2108. X#   Net 501  e16 1b038cc5    14:43  Novell Route        1    Critical
  2109. X#   Net 43   e9 04000118     16:10   Unrg NRoute        0    Critical
  2110. X#
  2111. X#    The first line states that a route to the IPX network with network
  2112. X#    number 501 through the router's interface Ethernet 16 to a router
  2113. X#    with mac address "????1b038cc5" is missing.
  2114. X#    The second line states that a route has appeared to Net 43, through
  2115. X#    the router's interface Ethernet 16 to "????04000118" but
  2116. X#    this route is not listed in nrmon's configuration file.
  2117. X#
  2118. X#    It is important to remember that nrmon monitors the network as
  2119. X#    it appears from one Cisco router in the network.  It will notice
  2120. X#    and report many kinds of changes, but even so, its view is restricted.
  2121. X#
  2122. X# Files used:
  2123. X#
  2124. X#   rcisco                      perl program to do a Cisco router
  2125. X#                               command remotely.
  2126. X#   nocol/data/armon-output     path to which to write nocol events.
  2127. X#   armon-confg                 configuration file.
  2128. X#   armon.pid                   file holding armon's current process id.
  2129. X#
  2130. X# Nocol event elements used:
  2131. X#   sender                     "nrmon"
  2132. X#   severity                   up: 4; down: 3,2,1;
  2133. X#   nocop                      up, down, unknown, test
  2134. X#   site
  2135. X#     name                     "Net " followed by the hex IPX network number
  2136. X#     addr                      The last 8 digits of the route's next
  2137. X#                               hop's Ethernet address followed by space and
  2138. X#                               the Router's ethernet port (e0, e1, etc).
  2139. X#                               Example: "1b038cc5" e8"
  2140. X#   var                       
  2141. X#     name                      either "Reg_NovellRoute" or "Unrg_NovellRoute"
  2142. X#     value                     0 if missing, 1 if present
  2143. X#     threshold                 always 0
  2144. X#     units                     always "Entry"
  2145. X#
  2146. X# To install this:
  2147. X#   (1) Choose where to put this file and the above 4 files and
  2148. X#       assign the perl variables below appropriately.
  2149. X#   (2) Create your armon-confg file in its chosen place.
  2150. X#   (3) Edit rcisco to include your Cisco router's password and put
  2151. X#       rcisco in its chosen place. Preferably in 'rcisco' and not
  2152. X#    in this file since otherwise a 'ps' will show the password.
  2153. X#   (4) Put this file in its chosen place.
  2154. X#   (5) Add appropriate code to rc.local to start this monitor.
  2155. X#
  2156. X# Configuration file format:
  2157. X#    #<text>                                   Comment line.
  2158. X#    router=<router>                           Name of Cisco router.
  2159. X#    <netnum> e<intnum> <next-hop>             Route via ethernet interface.
  2160. X#    test= <netnum> s<intnum> <next-hop>
  2161. X#
  2162. X# Sample configuration file:
  2163. X#    # nrmon configuration
  2164. X#    router=mycisco.excellent.edu
  2165. X#     # Route that is through another router:
  2166. X#     2 e9 D2.aa00.0400.0118
  2167. X#     # Directly-connected network:
  2168. X#     4 e22
  2169. X#    test=3  s1 D2.aa00.0400.1234
  2170. X#
  2171. X## 
  2172. X##
  2173. X#
  2174. X#
  2175. X############################
  2176. X## Variables customization #  overrides values in the nocollib.pl library
  2177. X############################
  2178. X$rprog="./rcisco";            # Path for rcisco.
  2179. X$rpasswd="";                # if NULL, uses the default in rcisco
  2180. X$rcommand="show novell route";
  2181. X$varname="Reg_NovellRoute";        # Registered appletalk route
  2182. X$varname_unreg="Unrg_NovellRoute";    # Unregistered route
  2183. X$varunits="Entry" ;            # the var.units field in EVENT struct
  2184. X$sleepint=60*5;                   # Seconds to sleep between tries.
  2185. X############################
  2186. X$debug = 0;                # set to 1 for debugging output
  2187. X$libdebug = 0;                # set to 1 for debugging output
  2188. X
  2189. Xrequire  "nocollib.pl" ;
  2190. X
  2191. X-x $rprog || die("Could not find executable $rprog, exiting");
  2192. X
  2193. X@me=split(/\//,$0); $me=pop(@me);
  2194. X# $piddir=join("/",@me); if ($piddir eq "") {$piddir=$etcdir;}
  2195. X$piddir=$etcdir;
  2196. X$cfile="$etcdir/$me-confg";
  2197. X$datafile="$datadir/$me-output";
  2198. X
  2199. X$sender= $me ;                # filled in the EVENT sender
  2200. X$maxseverity = $E_ERROR ;        # max severity of events
  2201. X    
  2202. X##
  2203. X# Read the config file. Use '\t' as a separator (since we are allowing
  2204. X# spaces in the names). Also define the regular expression as
  2205. X# a string to make it easier to modify, etc.
  2206. X
  2207. Xsub readconf {
  2208. X    local ($nets, $interface, $nhop) ;
  2209. X    local ($line_re)= '^\s*([\dABCDEF]+)\s+((e|s)\d+)\s+(\S+)?$' ;
  2210. X    open(CONFIG,"<$cfile")||die("Couldn't find $cfile, exiting");
  2211. X    while(<CONFIG>)
  2212. X    {
  2213. X    chop;
  2214. X    if(/^\s*#/) {next;}   # skip comments
  2215. X    if(/^\s*$/) {next;}   # skip blank lines
  2216. X
  2217. X    if(/^\s*router\s*=\s*(\S+)(\s.*)?$/)  {$router=$1;}
  2218. X        elsif(/^\s*test\s*=\s*([\dABCDEF]+)\s+((e|s)\d+)\s+(\S+)?$/){
  2219. X        $nets=$1; $interface=$2; $nhop=$4;
  2220. X        $nhop=~tr/a-z/A-Z/;            # to lowercase
  2221. X        $item="$nets\t$interface\t$nhop"; # tabs as separators
  2222. X        push(@items,$item);
  2223. X        $nocop{$item} = $nocop{$item} | $n_TEST;
  2224. X    }
  2225. X    elsif(/^$line_re/){
  2226. X            $nets=$1; $interface=$2; $nhop=$4;
  2227. X        $nhop=~tr/a-z/A-Z/;
  2228. X            $item="$nets\t$interface\t$nhop";
  2229. X        push(@items,$item);
  2230. X    }
  2231. X    }            # end while(CONFIG)
  2232. X    close(CONFIG);
  2233. X    if(!$router){die("No router specified in $cfile, exiting")};
  2234. X    if(0>$#items){die("Nothing to monitor in $cfile, exiting")};
  2235. X    if ($debug)
  2236. X    {
  2237. X    print "\n(debug) Router= $router\n";
  2238. X    print "Items are:\n"; foreach (@items) { print "\t$_\n" } ;
  2239. X    }
  2240. X    ;        #end readconf
  2241. X    
  2242. X}
  2243. X
  2244. X## Check the current state of the router
  2245. X#
  2246. Xsub dotest
  2247. X{
  2248. X    local ($loginok) = 0;
  2249. X    foreach(@items){$found{$_}=0;}
  2250. X    
  2251. X    $command="$rprog $router ".' "'."$rpasswd".'" '.'"'."$rcommand".'"';
  2252. X    if ($debug) {print "(debug) dotest: running command $command\n" ;}
  2253. X    
  2254. X    open(ROUTER,"$command |");
  2255. X    
  2256. X    $line=""; $ready="";
  2257. X    while(<ROUTER>)
  2258. X    {
  2259. X    tr/\r\n//d;
  2260. X    if ( />/ ) {$loginok = 1 ;} # got the 'Router>' prompt
  2261. X    if(/^\s/){    # Lines starting with space are continuation lines.
  2262. X        $line.=$_;
  2263. X    }
  2264. X    else {$ready=$line; $line=$_;}
  2265. X    if($ready ne ""){&doline; $ready="";}
  2266. X    }
  2267. X    
  2268. X    if($ready ne ""){&doline; $ready="";}
  2269. X    close(ROUTER);
  2270. X    if ($loginok == 0) { print "Login into remote host failed\n" ;}
  2271. X}
  2272. X
  2273. X## The output of 'show novell route' on a cisco is:
  2274. X#    R Net 27 in [1] hops via D2.aa00.0400.0118,  18 sec, 0 uses, Ethernet9
  2275. X#    C Net 31 is directly connected, 29924 uses, Ethernet15
  2276. X##    
  2277. Xsub doline
  2278. X{
  2279. X    local ($nets, $interface, $nhop) ;# $ready has the line to process.
  2280. X    if($ready =~ /^[RC] Net ([\dABCDEF]+) ((in.*via (\S+),)|(is)).*((Ethernet|Serial)\d+)$/)
  2281. X    {
  2282. X    $nets=$1;
  2283. X    $interface = $6;
  2284. X    $nhop=$4; $nhop=~tr/a-z/A-Z/; # set case-insensitive
  2285. X    $interface =~ s/Ethernet/e/ ;  $interface =~ s/Serial/s/ ;
  2286. X    $item="$nets\t$interface\t$nhop";
  2287. X    if ($debug) {print "(debug) doline: Found item $item\n" ;}
  2288. X    $found{$item}=1;
  2289. X    if(!$isitem{$item})        # determine if to be inserted into list
  2290. X    {
  2291. X        $isitem{$item}=1;
  2292. X        push(@items,$item);
  2293. X    }
  2294. X    }
  2295. X    else
  2296. X    {
  2297. X#    if ($debug) {print "(debug) doline: Router output skipped- $ready\n";}
  2298. X    }
  2299. X}
  2300. X   
  2301. X
  2302. X
  2303. X###
  2304. X### Main program:
  2305. X###
  2306. X
  2307. X# Fork and get rid of old process.
  2308. Xif($p=fork){print "$p\n";exit;}
  2309. X&standalone($me,$piddir);
  2310. X
  2311. X&readconf;
  2312. X# $item  is an index into the arrays. Note the sitename and the siteaddr
  2313. X# values.
  2314. Xforeach $item (@items) {
  2315. X    local ($nets, $interface, $nhop) = split(/\t/, $item) ;
  2316. X
  2317. X    &init_event("$nhop", "$nets/$interface", $item);
  2318. X    $registered{$item}=1;    # exists in the config file
  2319. X    $isitem{$item}=1;        # easy index to each item found.
  2320. X}
  2321. X
  2322. X
  2323. Xwhile (1)
  2324. X{
  2325. X    &dotest;
  2326. X    foreach $item (@items)
  2327. X    {
  2328. X    local ($nets, $interface, $nhop) = split(/\t/, $item) ;
  2329. X    local($status,$value);
  2330. X    
  2331. X    if (!$registered{$item})
  2332. X    {
  2333. X        if ($found{$item})    # unexpected route found (not in config)
  2334. X        {
  2335. X        ($nets, $interface, $nhop) = split(/\t/, $item) ;
  2336. X        &init_event("$nhop", "$nets/$interface", $item);
  2337. X                # stuff in initial kind of values
  2338. X        $varname{$item}=$varname_unreg;
  2339. X        $forget{$item}=0;    # remember to check the next time
  2340. X        $status = 0; $value = 1;
  2341. X        }
  2342. X        else            # earlier unknown route has gone away.
  2343. X        {
  2344. X        $forget{$item}=1;
  2345. X        $status = 1 ; $value = 0;
  2346. X        }
  2347. X    }
  2348. X    elsif ($found{$item})    # valid route is present
  2349. X    { $status = 1; $value = 1; }
  2350. X    else {$status = 0; $value = 0; }        # configured route missing
  2351. X
  2352. X    ; ## Now update the event arrays for each item.
  2353. X    if(!$forget{$item})
  2354. X    {
  2355. X        &update_event($item, $status, $value, $maxseverity);
  2356. X    }
  2357. X    }  # end foreach()
  2358. X
  2359. X    ; ## Note: we want to write the file quickly.
  2360. X
  2361. X    open(OEVENTS,">$datafile");
  2362. X    foreach $item (@items)
  2363. X    {
  2364. X    if(!$forget{$item})
  2365. X    {
  2366. X        &writeevent($item);
  2367. X    }
  2368. X    }
  2369. X    close(OEVENTS);
  2370. X    sleep($sleepint);
  2371. X
  2372. X}            # end while(forever)
  2373. END_OF_FILE
  2374.   if test 9574 -ne `wc -c <'nocol-3.0/src/perlnocol/nrmon'`; then
  2375.     echo shar: \"'nocol-3.0/src/perlnocol/nrmon'\" unpacked with wrong size!
  2376.   fi
  2377.   chmod +x 'nocol-3.0/src/perlnocol/nrmon'
  2378.   # end of 'nocol-3.0/src/perlnocol/nrmon'
  2379. fi
  2380. if test -f 'nocol-3.0/src/utility/log-maint' -a "${1}" != "-c" ; then 
  2381.   echo shar: Will not clobber existing file \"'nocol-3.0/src/utility/log-maint'\"
  2382. else
  2383.   echo shar: Extracting \"'nocol-3.0/src/utility/log-maint'\" \(558 characters\)
  2384.   sed "s/^X//" >'nocol-3.0/src/utility/log-maint' <<'END_OF_FILE'
  2385. X#!/bin/sh 
  2386. X#
  2387. X# daily maintenance for nocol log files. Move old logs and then sighup
  2388. X# the noclogd process.
  2389. X#
  2390. X#
  2391. XOLD=/nocol/logs/old
  2392. XLOGDIR=/nocol/logs
  2393. XPIDFILE=/nocol/etc/noclogd.pid
  2394. X
  2395. Xtest -d $LOGDIR  || exit 1
  2396. Xtest -d $OLD     || mkdir $OLD
  2397. Xtest -d $OLD     || exit 1
  2398. X
  2399. Xcd $LOGDIR
  2400. X
  2401. Xfor f in *
  2402. Xdo
  2403. X  if test -f $f ; then
  2404. X      test -f $OLD/$f.2.Z && mv $OLD/$f.2.Z $OLD/$f.3.Z
  2405. X      test -f $OLD/$f.1.Z && mv $OLD/$f.1.Z $OLD/$f.2.Z
  2406. X      test -f $OLD/$f.0.Z && mv $OLD/$f.0.Z $OLD/$f.1.Z
  2407. X      mv $f $OLD/$f.0 ; compress $OLD/$f.0
  2408. X  fi
  2409. Xdone
  2410. X
  2411. X#
  2412. Xkill -HUP `head -1 $PIDFILE`
  2413. END_OF_FILE
  2414.   if test 558 -ne `wc -c <'nocol-3.0/src/utility/log-maint'`; then
  2415.     echo shar: \"'nocol-3.0/src/utility/log-maint'\" unpacked with wrong size!
  2416.   fi
  2417.   chmod +x 'nocol-3.0/src/utility/log-maint'
  2418.   # end of 'nocol-3.0/src/utility/log-maint'
  2419. fi
  2420. echo shar: End of archive 18 \(of 26\).
  2421. cp /dev/null ark18isdone
  2422. MISSING=""
  2423. 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 26 ; do
  2424.     if test ! -f ark${I}isdone ; then
  2425.     MISSING="${MISSING} ${I}"
  2426.     fi
  2427. done
  2428. if test "${MISSING}" = "" ; then
  2429.     echo You have unpacked all 26 archives.
  2430.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2431. else
  2432.     echo You still must unpack the following archives:
  2433.     echo "        " ${MISSING}
  2434. fi
  2435. exit 0
  2436. exit 0 # Just in case...
  2437.