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

  1. Newsgroups: comp.sources.misc
  2. From: vikas@jvnc.net (Vikas Aggarwal)
  3. Subject: v40i151:  nocol - Network Monitoring System, Part21/26
  4. Message-ID: <1993Nov24.163804.1812@sparky.sterling.com>
  5. X-Md4-Signature: 8f2dd9dd5f4c5908d8a81f0f4a052f37
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Wed, 24 Nov 1993 16:38:04 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: vikas@jvnc.net (Vikas Aggarwal)
  12. Posting-number: Volume 40, Issue 151
  13. Archive-name: nocol/part21
  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/main.c
  21. #   nocol-3.0/src/cmu-snmp/apps/snmptrap.c
  22. #   nocol-3.0/src/cmu-snmp/apps/snmptrapd.c.cmu
  23. #   nocol-3.0/src/cmu-snmp/apps/snmpwalk_asy.c
  24. #   nocol-3.0/src/cmu-snmp/man/snmpnetstat.1
  25. #   nocol-3.0/src/cmu-snmp/man/snmpwalk.1 nocol-3.0/src/doc/nocol.1
  26. #   nocol-3.0/src/lib/eventlog.c nocol-3.0/src/netmon/event_dpy.c
  27. #   nocol-3.0/src/netmon/utils.c nocol-3.0/src/perlnocol/bpmon
  28. # Wrapped by kent@sparky on Tue Nov  9 22:22:25 1993
  29. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  30. echo If this archive is complete, you will see the following message:
  31. echo '          "shar: End of archive 21 (of 26)."'
  32. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/main.c' -a "${1}" != "-c" ; then 
  33.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/main.c'\"
  34. else
  35.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/main.c'\" \(6346 characters\)
  36.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/main.c' <<'END_OF_FILE'
  37. X/***********************************************************
  38. X    Copyright 1989 by Carnegie Mellon University
  39. X
  40. X                      All Rights Reserved
  41. X
  42. XPermission to use, copy, modify, and distribute this software and its 
  43. Xdocumentation for any purpose and without fee is hereby granted, 
  44. Xprovided that the above copyright notice appear in all copies and that
  45. Xboth that copyright notice and this permission notice appear in 
  46. Xsupporting documentation, and that the name of CMU not be
  47. Xused in advertising or publicity pertaining to distribution of the
  48. Xsoftware without specific, written prior permission.  
  49. X
  50. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  51. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  52. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  53. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  54. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  55. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  56. XSOFTWARE.
  57. X******************************************************************/
  58. X/*
  59. X * Copyright (c) 1983,1988 Regents of the University of California.
  60. X * All rights reserved.
  61. X *
  62. X * Redistribution and use in source and binary forms are permitted
  63. X * provided that this notice is preserved and that due credit is given
  64. X * to the University of California at Berkeley. The name of the University
  65. X * may not be used to endorse or promote products derived from this
  66. X * software without specific prior written permission. This software
  67. X * is provided ``as is'' without express or implied warranty.
  68. X */
  69. X
  70. X#ifndef lint
  71. Xchar copyright[] =
  72. X"@(#) Copyright (c) 1983 Regents of the University of California.\n\
  73. X All rights reserved.\n";
  74. X#endif not lint
  75. X
  76. X#include <sys/types.h>
  77. X#include <sys/param.h>
  78. X
  79. X#include <sys/socket.h>
  80. X#include <sys/time.h>
  81. X
  82. X#include <ctype.h>
  83. X#include <errno.h>
  84. X#include <netdb.h>
  85. X#include <stdio.h>
  86. X#include <netinet/in.h>
  87. X#include "asn1.h"
  88. X#include "snmp.h"
  89. X#include "snmp_api.h"
  90. X
  91. X/* internet protocols */
  92. Xextern    int protopr();
  93. Xextern    int tcp_stats(), udp_stats(), ip_stats(), icmp_stats();
  94. X
  95. X#define NULLPROTOX    ((struct protox *) 0)
  96. Xstruct protox {
  97. X    u_char    pr_wanted;        /* 1 if wanted, 0 otherwise */
  98. X    int    (*pr_cblocks)();    /* control blocks printing routine */
  99. X    int    (*pr_stats)();        /* statistics printing routine */
  100. X    char    *pr_name;        /* well-known name */
  101. X} protox[] = {
  102. X    { 1,    protopr,    tcp_stats,    "tcp" },
  103. X    { 1,    0,        udp_stats,    "udp" },
  104. X    { 1,    0,        ip_stats,    "ip" },
  105. X    { 1,    0,        icmp_stats,    "icmp" },
  106. X    { 0,    0,        0,        0 }
  107. X};
  108. X
  109. Xint    aflag;
  110. Xint    iflag;
  111. Xint    nflag;
  112. Xint    pflag;
  113. Xint    rflag;
  114. Xint    sflag;
  115. Xint    interval;
  116. Xchar    *interface;
  117. Xchar    usage[] = "host community [ -ainrs ] [-p proto] [-I interface] [ interval ]";
  118. X
  119. Xint debug = 0;
  120. X
  121. X
  122. Xextern    char *malloc();
  123. X
  124. Xstruct snmp_session *Session;
  125. Xint snmp_dump_packet = 0;
  126. Xint print_errors = 0;
  127. X
  128. Xmain(argc, argv)
  129. X    int argc;
  130. X    char *argv[];
  131. X{
  132. X    char *cp, *name;
  133. X    char *host;
  134. X    register struct protoent *p;
  135. X    register struct protox *tp;    /* for printing cblocks & stats */
  136. X    struct protox *name2protox();    /* for -p */
  137. X    char *community;
  138. X    struct snmp_session session;
  139. X    
  140. X    name = argv[0];
  141. X    argc--, argv++;
  142. X    if (argc--)
  143. X        host = *argv++;
  144. X    if (argc--)
  145. X        community = *argv++;
  146. X    else
  147. X        goto use;
  148. X      while (argc > 0 && **argv == '-') {
  149. X        for (cp = &argv[0][1]; *cp; cp++)
  150. X        switch(*cp) {
  151. X
  152. X        case 'a':
  153. X            aflag++;
  154. X            break;
  155. X
  156. X        case 'i':
  157. X            iflag++;
  158. X            break;
  159. X
  160. X        case 'n':
  161. X            nflag++;
  162. X            break;
  163. X
  164. X        case 'r':
  165. X            rflag++;
  166. X            break;
  167. X
  168. X        case 's':
  169. X            sflag++;
  170. X            break;
  171. X
  172. X        case 'p':
  173. X            argv++;
  174. X            argc--;
  175. X            if (argc == 0)
  176. X                goto use;
  177. X            if ((tp = name2protox(*argv)) == NULLPROTOX) {
  178. X                fprintf(stderr, "%s: unknown or uninstrumented protocol\n",
  179. X                    *argv);
  180. X                exit(10);
  181. X            }
  182. X            pflag++;
  183. X            break;
  184. X
  185. X        case 'I':
  186. X            iflag++;
  187. X            if (*(interface = cp + 1) == 0) {
  188. X                if ((interface = argv[1]) == 0)
  189. X                    break;
  190. X                argv++;
  191. X                argc--;
  192. X            }
  193. X            for (cp = interface; *cp; cp++)
  194. X                ;
  195. X            cp--;
  196. X            break;
  197. X
  198. X        default:
  199. Xuse:
  200. X            printf("usage: %s %s\n", name, usage);
  201. X            exit(1);
  202. X        }
  203. X        argv++, argc--;
  204. X    }
  205. X    if (argc > 0 && isdigit(argv[0][0])) {
  206. X        interval = atoi(argv[0]);
  207. X        if (interval <= 0)
  208. X            goto use;
  209. X        argv++, argc--;
  210. X        iflag++;
  211. X    }
  212. X
  213. X    bzero((char *)&session, sizeof(struct snmp_session));
  214. X    session.peername = host;
  215. X    session.community = (u_char *)community;
  216. X    session.community_len = strlen((char *)community);
  217. X    session.retries = SNMP_DEFAULT_RETRIES;
  218. X    session.timeout = SNMP_DEFAULT_TIMEOUT;
  219. X    session.authenticator = NULL;
  220. X    snmp_synch_setup(&session);
  221. X    Session = snmp_open(&session);
  222. X    if (Session == NULL){
  223. X        printf("Couldn't open snmp\n");
  224. X        exit(-1);
  225. X    }
  226. X    if (pflag) {
  227. X        if (tp->pr_stats)
  228. X            (*tp->pr_stats)();
  229. X        else
  230. X            printf("%s: no stats routine\n", tp->pr_name);
  231. X        exit(0);
  232. X    }
  233. X    /*
  234. X     * Keep file descriptors open to avoid overhead
  235. X     * of open/close on each call to get* routines.
  236. X     */
  237. X    sethostent(1);
  238. X    setnetent(1);
  239. X    if (iflag) {
  240. X        intpr(interval);
  241. X        exit(0);
  242. X    }
  243. X    if (rflag) {
  244. X        if (sflag)
  245. X            rt_stats();
  246. X        else
  247. X            routepr();
  248. X        exit(0);
  249. X    }
  250. X
  251. X    setprotoent(1);
  252. X    setservent(1);
  253. X    while (p = getprotoent()) {
  254. X
  255. X        for (tp = protox; tp->pr_name; tp++)
  256. X            if (strcmp(tp->pr_name, p->p_name) == 0)
  257. X                break;
  258. X        if (tp->pr_name == 0 || tp->pr_wanted == 0)
  259. X            continue;
  260. X        if (sflag) {
  261. X            if (tp->pr_stats)
  262. X                (*tp->pr_stats)();
  263. X        } else
  264. X            if (tp->pr_cblocks)
  265. X                (*tp->pr_cblocks)();
  266. X    }
  267. X    endprotoent();
  268. X    exit(0);
  269. X}
  270. X
  271. Xchar *
  272. Xplural(n)
  273. X    int n;
  274. X{
  275. X
  276. X    return (n != 1 ? "s" : "");
  277. X}
  278. X
  279. X/*
  280. X * Find the protox for the given "well-known" name.
  281. X */
  282. Xstruct protox *
  283. Xknownname(name)
  284. X    char *name;
  285. X{
  286. X    struct protox *tp;
  287. X    
  288. X    for (tp = protox; tp->pr_name; tp++)
  289. X        if (strcmp(tp->pr_name, name) == 0)
  290. X            return(tp);
  291. X    return(NULLPROTOX);
  292. X}
  293. X
  294. X/*
  295. X * Find the protox corresponding to name.
  296. X */
  297. Xstruct protox *
  298. Xname2protox(name)
  299. X    char *name;
  300. X{
  301. X    struct protox *tp;
  302. X    char **alias;            /* alias from p->aliases */
  303. X    struct protoent *p;
  304. X    
  305. X    /*
  306. X     * Try to find the name in the list of "well-known" names. If that
  307. X     * fails, check if name is an alias for an Internet protocol.
  308. X     */
  309. X    if (tp = knownname(name))
  310. X        return(tp);
  311. X        
  312. X    setprotoent(1);            /* make protocol lookup cheaper */
  313. X    while (p = getprotoent()) {
  314. X        /* assert: name not same as p->name */
  315. X        for (alias = p->p_aliases; *alias; alias++)
  316. X            if (strcmp(name, *alias) == 0) {
  317. X                endprotoent();
  318. X                return(knownname(p->p_name));
  319. X            }
  320. X    }
  321. X    endprotoent();
  322. X    return(NULLPROTOX);
  323. X}
  324. END_OF_FILE
  325.   if test 6346 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/main.c'`; then
  326.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/main.c'\" unpacked with wrong size!
  327.   fi
  328.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmpnetstat/main.c'
  329. fi
  330. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmptrap.c' -a "${1}" != "-c" ; then 
  331.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmptrap.c'\"
  332. else
  333.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmptrap.c'\" \(6715 characters\)
  334.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmptrap.c' <<'END_OF_FILE'
  335. X/*
  336. X * snmptrap.c - send snmp traps to a network entity.
  337. X *
  338. X */
  339. X/***********************************************************
  340. X    Copyright 1989 by Carnegie Mellon University
  341. X
  342. X                      All Rights Reserved
  343. X
  344. XPermission to use, copy, modify, and distribute this software and its 
  345. Xdocumentation for any purpose and without fee is hereby granted, 
  346. Xprovided that the above copyright notice appear in all copies and that
  347. Xboth that copyright notice and this permission notice appear in 
  348. Xsupporting documentation, and that the name of CMU not be
  349. Xused in advertising or publicity pertaining to distribution of the
  350. Xsoftware without specific, written prior permission.  
  351. X
  352. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  353. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  354. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  355. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  356. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  357. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  358. XSOFTWARE.
  359. X******************************************************************/
  360. X#include <sys/types.h>
  361. X#include <netinet/in.h>
  362. X#include <netdb.h>
  363. X#include <stdio.h>
  364. X#include <sys/time.h>
  365. X#include <sys/socket.h>
  366. X#include <net/if.h>
  367. X#include <sys/ioctl.h>
  368. X#include <sys/file.h>
  369. X#include <nlist.h>
  370. X
  371. X#include "snmp.h"
  372. X#include "snmp_impl.h"
  373. X#include "asn1.h"
  374. X#include "snmp_api.h"
  375. X#include "snmp_client.h"
  376. X
  377. Xextern int  errno;
  378. Xint    snmp_dump_packet = 0;
  379. X
  380. X#define NUM_NETWORKS    16   /* max number of interfaces to check */
  381. X
  382. Xoid objid_enterprise[] = {1, 3, 6, 1, 4, 1, 3, 1, 1};
  383. Xoid objid_sysdescr[] = {1, 3, 6, 1, 2, 1, 1, 1, 0};
  384. X
  385. Xstruct nlist nl[] = {
  386. X    { "_boottime" },
  387. X    { "" }
  388. X};
  389. X
  390. X
  391. Xint snmp_input(){
  392. X}
  393. X
  394. X#ifndef IFF_LOOPBACK
  395. X#define IFF_LOOPBACK 0
  396. X#endif
  397. X#define LOOPBACK    0x7f000001
  398. Xu_long
  399. Xget_myaddr(){
  400. X    int sd;
  401. X    struct ifconf ifc;
  402. X    struct ifreq conf[NUM_NETWORKS], *ifrp, ifreq;
  403. X    struct sockaddr_in *in_addr;
  404. X    int count;
  405. X    int interfaces;        /* number of interfaces returned by ioctl */
  406. X
  407. X    if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  408. X    return 0;
  409. X    ifc.ifc_len = sizeof(conf);
  410. X    ifc.ifc_buf = (caddr_t)conf;
  411. X    if (ioctl(sd, SIOCGIFCONF, (char *)&ifc) < 0){
  412. X    close(sd);
  413. X    return 0;
  414. X    }
  415. X    ifrp = ifc.ifc_req;
  416. X    interfaces = ifc.ifc_len / sizeof(struct ifreq);
  417. X    for(count = 0; count < interfaces; count++, ifrp++){
  418. X    ifreq = *ifrp;
  419. X    if (ioctl(sd, SIOCGIFFLAGS, (char *)&ifreq) < 0)
  420. X        continue;
  421. X    in_addr = (struct sockaddr_in *)&ifrp->ifr_addr;
  422. X    if ((ifreq.ifr_flags & IFF_UP)
  423. X        && (ifreq.ifr_flags & IFF_RUNNING)
  424. X        && !(ifreq.ifr_flags & IFF_LOOPBACK)
  425. X        && in_addr->sin_addr.s_addr != LOOPBACK){
  426. X        close(sd);
  427. X        return in_addr->sin_addr.s_addr;
  428. X        }
  429. X    }
  430. X    close(sd);
  431. X    return 0;
  432. X}
  433. X
  434. X/*
  435. X * Returns uptime in centiseconds(!).
  436. X */
  437. Xlong uptime(){
  438. X    struct timeval boottime, now, diff;
  439. X    int kmem;
  440. X
  441. X    if ((kmem = open("/dev/kmem", 0)) < 0)
  442. X    return 0;
  443. X    nlist("/vmunix", nl);
  444. X    if (nl[0].n_type == 0){
  445. X    close(kmem);
  446. X    return 0;
  447. X    }
  448. X    
  449. X    lseek(kmem, (long)nl[0].n_value, L_SET);
  450. X    read(kmem, &boottime, sizeof(boottime));
  451. X    close(kmem);
  452. X
  453. X    gettimeofday(&now, 0);
  454. X    now.tv_sec--;
  455. X    now.tv_usec += 1000000L;
  456. X    diff.tv_sec = now.tv_sec - boottime.tv_sec;
  457. X    diff.tv_usec = now.tv_usec - boottime.tv_usec;
  458. X    if (diff.tv_usec > 1000000L){
  459. X    diff.tv_usec -= 1000000L;
  460. X    diff.tv_sec++;
  461. X    }
  462. X    return ((diff.tv_sec * 100) + (diff.tv_usec / 10000));
  463. X}
  464. X
  465. Xu_long parse_address(address)
  466. X    char *address;
  467. X{
  468. X    u_long addr;
  469. X    struct sockaddr_in saddr;
  470. X    struct hostent *hp;
  471. X
  472. X    if ((addr = inet_addr(address)) != -1)
  473. X    return addr;
  474. X    hp = gethostbyname(address);
  475. X    if (hp == NULL){
  476. X    fprintf(stderr, "unknown host: %s\n", address);
  477. X    return 0;
  478. X    } else {
  479. X    bcopy((char *)hp->h_addr, (char *)&saddr.sin_addr, hp->h_length);
  480. X    return saddr.sin_addr.s_addr;
  481. X    }
  482. X
  483. X}
  484. Xmain(argc, argv)
  485. X    int        argc;
  486. X    char    *argv[];
  487. X{
  488. X    struct snmp_session session, *ss;
  489. X    struct snmp_pdu *pdu;
  490. X    struct variable_list *vars;
  491. X    int    arg;
  492. X    char *gateway = NULL;
  493. X    char *community = NULL;
  494. X    char *trap = NULL, *specific = NULL, *description = NULL, *agent = NULL;
  495. X
  496. X
  497. X    /*
  498. X     * usage: snmptrap gateway-name community-name trap-type specific-type device-description [ -a agent-addr ]
  499. X     */
  500. X    for(arg = 1; arg < argc; arg++){
  501. X    if (argv[arg][0] == '-'){
  502. X        switch(argv[arg][1]){
  503. X        case 'a':
  504. X            agent = argv[++arg];
  505. X            break;
  506. X        case 'd':
  507. X            snmp_dump_packet++;
  508. X            break;
  509. X        default:
  510. X            printf("invalid option: -%c\n", argv[arg][1]);
  511. X            break;
  512. X        }
  513. X        continue;
  514. X    }
  515. X    if (gateway == NULL){
  516. X        gateway = argv[arg];
  517. X    } else if (community == NULL){
  518. X        community = argv[arg]; 
  519. X    } else if (trap == NULL){
  520. X        trap = argv[arg];
  521. X    } else if (specific == NULL){
  522. X        specific = argv[arg];
  523. X    } else {
  524. X        description = argv[arg];
  525. X    }
  526. X    }
  527. X
  528. X    if (!(gateway && community && trap && specific && description)){
  529. X    printf("usage: snmptrap host community trap-type specific-type device-description [ -a agent-addr ]\n");
  530. X    exit(1);
  531. X    }
  532. X
  533. X    bzero((char *)&session, sizeof(struct snmp_session));
  534. X    session.peername = gateway;
  535. X    session.community = (u_char *)community;
  536. X    session.community_len = strlen((char *)community);
  537. X    session.retries = SNMP_DEFAULT_RETRIES;
  538. X    session.timeout = SNMP_DEFAULT_TIMEOUT;
  539. X    session.authenticator = NULL;
  540. X    session.callback = snmp_input;
  541. X    session.callback_magic = NULL;
  542. X    session.remote_port = SNMP_TRAP_PORT;
  543. X    ss = snmp_open(&session);
  544. X    if (ss == NULL){
  545. X    printf("Couldn't open snmp\n");
  546. X    exit(-1);
  547. X    }
  548. X
  549. X    pdu = snmp_pdu_create(TRP_REQ_MSG);
  550. X    pdu->enterprise = (oid *)malloc(sizeof(objid_enterprise));
  551. X    bcopy((char *)objid_enterprise, (char *)pdu->enterprise, sizeof(objid_enterprise));
  552. X    pdu->enterprise_length = sizeof(objid_enterprise) / sizeof(oid);
  553. X    if (agent != NULL)
  554. X    pdu->agent_addr.sin_addr.s_addr = parse_address(agent);
  555. X    else
  556. X    pdu->agent_addr.sin_addr.s_addr = get_myaddr();
  557. X    pdu->trap_type = atoi(trap);
  558. X    pdu->specific_type = atoi(specific);
  559. X    pdu->time = uptime();
  560. X
  561. X    pdu->variables = vars = (struct variable_list *)malloc(sizeof(struct variable_list));
  562. X    vars->next_variable = NULL;
  563. X    vars->name = (oid *)malloc(sizeof(objid_sysdescr));
  564. X    bcopy((char *)objid_sysdescr, (char *)vars->name, sizeof(objid_sysdescr));
  565. X    vars->name_length = sizeof(objid_sysdescr) / sizeof(oid);
  566. X    vars->type = ASN_OCTET_STR;
  567. X    vars->val.string = (u_char *)malloc(strlen(description) + 1);
  568. X    strcpy((char *)vars->val.string, description);
  569. X    vars->val_len = strlen(description);
  570. X
  571. X    if (snmp_send(ss, pdu)== 0){
  572. X    printf("error\n");
  573. X    }
  574. X    snmp_close(ss);
  575. X}
  576. X
  577. END_OF_FILE
  578.   if test 6715 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmptrap.c'`; then
  579.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmptrap.c'\" unpacked with wrong size!
  580.   fi
  581.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmptrap.c'
  582. fi
  583. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmptrapd.c.cmu' -a "${1}" != "-c" ; then 
  584.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmptrapd.c.cmu'\"
  585. else
  586.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmptrapd.c.cmu'\" \(5919 characters\)
  587.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmptrapd.c.cmu' <<'END_OF_FILE'
  588. X/*
  589. X * snmptrapd.c - receive and log snmp traps
  590. X *
  591. X */
  592. X/***********************************************************
  593. X    Copyright 1989 by Carnegie Mellon University
  594. X
  595. X                      All Rights Reserved
  596. X
  597. XPermission to use, copy, modify, and distribute this software and its 
  598. Xdocumentation for any purpose and without fee is hereby granted, 
  599. Xprovided that the above copyright notice appear in all copies and that
  600. Xboth that copyright notice and this permission notice appear in 
  601. Xsupporting documentation, and that the name of CMU not be
  602. Xused in advertising or publicity pertaining to distribution of the
  603. Xsoftware without specific, written prior permission.  
  604. X
  605. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  606. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  607. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  608. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  609. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  610. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  611. XSOFTWARE.
  612. X******************************************************************/
  613. X#include <sys/types.h>
  614. X#include <netinet/in.h>
  615. X#include <stdio.h>
  616. X#include <sys/time.h>
  617. X#include <errno.h>
  618. X#include <syslog.h>
  619. X
  620. X#include "snmp.h"
  621. X#include "snmp_impl.h"
  622. X#include "asn1.h"
  623. X#include "snmp_api.h"
  624. X#include "snmp_client.h"
  625. X
  626. X#ifndef BSD4_3
  627. X
  628. Xtypedef long    fd_mask;
  629. X#define NFDBITS    (sizeof(fd_mask) * NBBY)    /* bits per mask */
  630. X
  631. X#define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  632. X#define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  633. X#define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  634. X#define FD_ZERO(p)    bzero((char *)(p), sizeof(*(p)))
  635. X#endif
  636. X
  637. Xextern int  errno;
  638. Xint    snmp_dump_packet = 0;
  639. Xint Print = 0;
  640. X
  641. Xchar *
  642. Xtrap_description(trap)
  643. X    int trap;
  644. X{
  645. X    switch(trap){
  646. X    case SNMP_TRAP_COLDSTART:
  647. X        return "Cold Start";
  648. X    case SNMP_TRAP_WARMSTART:
  649. X        return "Warm Start";
  650. X    case SNMP_TRAP_LINKDOWN:
  651. X        return "Link Down";
  652. X    case SNMP_TRAP_LINKUP:
  653. X        return "Link Up";
  654. X    case SNMP_TRAP_AUTHFAIL:
  655. X        return "Authentication Failure";
  656. X    case SNMP_TRAP_EGPNEIGHBORLOSS:
  657. X        return "EGP Neighbor Loss";
  658. X    case SNMP_TRAP_ENTERPRISESPECIFIC:
  659. X        return "Enterprise Specific";
  660. X    default:
  661. X        return "Unknown Type";
  662. X    }
  663. X}
  664. X
  665. Xchar *
  666. Xuptime_string(timeticks, buf)
  667. X    register u_long timeticks;
  668. X    char *buf;
  669. X{
  670. X    int    seconds, minutes, hours, days;
  671. X
  672. X    timeticks /= 100;
  673. X    days = timeticks / (60 * 60 * 24);
  674. X    timeticks %= (60 * 60 * 24);
  675. X
  676. X    hours = timeticks / (60 * 60);
  677. X    timeticks %= (60 * 60);
  678. X
  679. X    minutes = timeticks / 60;
  680. X    seconds = timeticks % 60;
  681. X
  682. X    if (days == 0){
  683. X    sprintf(buf, "%d:%02d:%02d", hours, minutes, seconds);
  684. X    } else if (days == 1) {
  685. X    sprintf(buf, "%d day, %d:%02d:%02d", days, hours, minutes, seconds);
  686. X    } else {
  687. X    sprintf(buf, "%d days, %d:%02d:%02d", days, hours, minutes, seconds);
  688. X    }
  689. X    return buf;
  690. X}
  691. X
  692. Xint snmp_input(op, session, reqid, pdu, magic)
  693. X    int op;
  694. X    struct snmp_session *session;
  695. X    int reqid;
  696. X    struct snmp_pdu *pdu;
  697. X    void *magic;
  698. X{
  699. X    struct variable_list *vars;
  700. X    char buf[64];
  701. X
  702. X    if (op == RECEIVED_MESSAGE && pdu->command == TRP_REQ_MSG){
  703. X    if (Print){
  704. X        printf("%s: %s Trap (%d) Uptime: %s\n", inet_ntoa(pdu->agent_addr.sin_addr),
  705. X        trap_description(pdu->trap_type), pdu->specific_type, uptime_string(pdu->time, buf));
  706. X        for(vars = pdu->variables; vars; vars = vars->next_variable)
  707. X        print_variable(vars->name, vars->name_length, vars);
  708. X    } else {
  709. X        syslog(LOG_WARNING, "%s: %s Trap (%d) Uptime: %s\n", inet_ntoa(pdu->agent_addr.sin_addr),
  710. X        trap_description(pdu->trap_type), pdu->specific_type, uptime_string(pdu->time, buf));
  711. X    }
  712. X    } else if (op == TIMED_OUT){
  713. X    printf("Timeout: This shouldn't happen!\n");
  714. X    }
  715. X}
  716. X
  717. X
  718. Xmain(argc, argv)
  719. X    int        argc;
  720. X    char    *argv[];
  721. X{
  722. X    struct snmp_session session, *ss;
  723. X    int    arg;
  724. X    int count, numfds, block;
  725. X    fd_set fdset;
  726. X    struct timeval timeout, *tvp;
  727. X
  728. X
  729. X    init_syslog();
  730. X    init_mib();
  731. X    /*
  732. X     * usage: snmptrapd [-p]
  733. X     */
  734. X    for(arg = 1; arg < argc; arg++){
  735. X    if (argv[arg][0] == '-'){
  736. X        switch(argv[arg][1]){
  737. X        case 'd':
  738. X            snmp_dump_packet++;
  739. X            break;
  740. X        case 'p':
  741. X            Print++;
  742. X            break;
  743. X        default:
  744. X            printf("invalid option: -%c\n", argv[arg][1]);
  745. X            printf("Usage: snmptrapd [-p ]\n");
  746. X            break;
  747. X        }
  748. X        continue;
  749. X    }
  750. X    }
  751. X
  752. X    bzero((char *)&session, sizeof(struct snmp_session));
  753. X    session.peername = NULL;
  754. X    session.community = NULL;
  755. X    session.community_len = 0;
  756. X    session.retries = SNMP_DEFAULT_RETRIES;
  757. X    session.timeout = SNMP_DEFAULT_TIMEOUT;
  758. X    session.authenticator = NULL;
  759. X    session.callback = snmp_input;
  760. X    session.callback_magic = NULL;
  761. X    session.local_port = SNMP_TRAP_PORT;
  762. X    ss = snmp_open(&session);
  763. X    if (ss == NULL){
  764. X    printf("Couldn't open snmp\n");
  765. X    exit(-1);
  766. X    }
  767. X
  768. X    while(1){
  769. X    numfds = 0;
  770. X    FD_ZERO(&fdset);
  771. X    block = 1;
  772. X    tvp = &timeout;
  773. X    timerclear(tvp);
  774. X    snmp_select_info(&numfds, &fdset, tvp, &block);
  775. X    if (block == 1)
  776. X        tvp = NULL;    /* block without timeout */
  777. X    count = select(numfds, &fdset, 0, 0, tvp);
  778. X    if (count > 0){
  779. X        snmp_read(&fdset);
  780. X    } else switch(count){
  781. X        case 0:
  782. X        snmp_timeout();
  783. X        break;
  784. X        case -1:
  785. X        if (errno == EINTR){
  786. X            continue;
  787. X        } else {
  788. X            perror("select");
  789. X        }
  790. X        return -1;
  791. X        default:
  792. X        printf("select returned %d\n", count);
  793. X        return -1;
  794. X    }
  795. X    }
  796. X}
  797. X
  798. Xinit_syslog(){
  799. X/*
  800. X * These definitions handle 4.2 systems without additional syslog facilities.
  801. X */
  802. X#ifndef LOG_CONS
  803. X#define LOG_CONS    0    /* Don't bother if not defined... */
  804. X#endif
  805. X#ifndef LOG_LOCAL0
  806. X#define LOG_LOCAL0    0
  807. X#endif
  808. X    /*
  809. X     * All messages will be logged to the local0 facility and will be sent to
  810. X     * the console if syslog doesn't work.
  811. X     */
  812. X    openlog("snmptrapd", LOG_CONS, LOG_LOCAL0);
  813. X    syslog(LOG_INFO, "Starting snmptrapd");
  814. X}
  815. END_OF_FILE
  816.   if test 5919 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmptrapd.c.cmu'`; then
  817.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmptrapd.c.cmu'\" unpacked with wrong size!
  818.   fi
  819.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmptrapd.c.cmu'
  820. fi
  821. if test -f 'nocol-3.0/src/cmu-snmp/apps/snmpwalk_asy.c' -a "${1}" != "-c" ; then 
  822.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/apps/snmpwalk_asy.c'\"
  823. else
  824.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/apps/snmpwalk_asy.c'\" \(6401 characters\)
  825.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/apps/snmpwalk_asy.c' <<'END_OF_FILE'
  826. X/*
  827. X * snmpwalk.c - send snmp GETNEXT requests to a network entity, walking a subtree.
  828. X * This uses the asynchronous interface directly.
  829. X *
  830. X */
  831. X/***********************************************************
  832. X    Copyright 1989 by Carnegie Mellon University
  833. X
  834. X                      All Rights Reserved
  835. X
  836. XPermission to use, copy, modify, and distribute this software and its 
  837. Xdocumentation for any purpose and without fee is hereby granted, 
  838. Xprovided that the above copyright notice appear in all copies and that
  839. Xboth that copyright notice and this permission notice appear in 
  840. Xsupporting documentation, and that the name of CMU not be
  841. Xused in advertising or publicity pertaining to distribution of the
  842. Xsoftware without specific, written prior permission.  
  843. X
  844. XCMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  845. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  846. XCMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  847. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  848. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  849. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  850. XSOFTWARE.
  851. X******************************************************************/
  852. X#include <sys/param.h>
  853. X#include <sys/types.h>
  854. X#include <sys/socket.h>
  855. X#include <netinet/in.h>
  856. X#include <arpa/inet.h>
  857. X#include <netdb.h>
  858. X#include <stdio.h>
  859. X#include <ctype.h>
  860. X#include <sys/time.h>
  861. X#include <errno.h>
  862. X
  863. X#include "snmp.h"
  864. X#include "snmp_impl.h"
  865. X#include "asn1.h"
  866. X#include "snmp_api.h"
  867. X#include "snmp_client.h"
  868. X
  869. X#ifndef BSD4_3
  870. X#define BSD4_2
  871. X#endif
  872. X
  873. X#ifndef BSD4_3
  874. X
  875. Xtypedef long    fd_mask;
  876. X#define NFDBITS    (sizeof(fd_mask) * NBBY)    /* bits per mask */
  877. X
  878. X#define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  879. X#define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  880. X#define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  881. X#define FD_ZERO(p)    bzero((char *)(p), sizeof(*(p)))
  882. X#endif
  883. X
  884. Xoid objid_mib[] = {1, 3, 6, 1, 2, 1};
  885. X
  886. Xextern int  errno;
  887. Xint    snmp_dump_packet = 0;
  888. Xstruct state {
  889. X    oid    name[MAX_NAME_LEN];
  890. X    int name_length;
  891. X    oid root[MAX_NAME_LEN];
  892. X    int    rootlen;
  893. X    int running;
  894. X    int waiting;
  895. X} state_info;
  896. X
  897. Xsnmp_input(op,  session, reqid, pdu, magic)
  898. X    int op;
  899. X    struct snmp_session *session;
  900. X    int reqid;
  901. X    struct snmp_pdu *pdu;
  902. X    void *magic;
  903. X{
  904. X    struct variable_list *vars;
  905. X    struct state *state = (struct state *)magic;
  906. X    int count;
  907. X
  908. X    state->waiting = 0;
  909. X    state->running = 0;
  910. X    if (op == RECEIVED_MESSAGE && pdu->command == GET_RSP_MSG){
  911. X    if (pdu->errstat == SNMP_ERR_NOERROR){
  912. X        for(vars = pdu->variables; vars; vars = vars->next_variable){
  913. X        if (vars->name_length < state->rootlen || bcmp(state->root, vars->name, state->rootlen * sizeof(oid)))
  914. X            continue;    /* not part of this subtree */
  915. X        print_variable(vars->name, vars->name_length, vars);
  916. X        bcopy((char *)vars->name, (char *)state->name, vars->name_length * sizeof(oid));
  917. X        state->name_length = vars->name_length;
  918. X        state->running = 1; /* restart so we can get next variable */
  919. X        }
  920. X    } else {
  921. X        if (pdu->errstat == SNMP_ERR_NOSUCHNAME){
  922. X        printf("End of MIB.\n");
  923. X        } else {
  924. X        printf("Error in packet.\nReason: %s\n", snmp_errstring(pdu->errstat));
  925. X        if (pdu->errstat == SNMP_ERR_NOSUCHNAME){
  926. X            printf("The request for this object identifier failed: ");
  927. X            for(count = 1, vars = pdu->variables; vars && count != pdu->errindex;
  928. X            vars = vars->next_variable, count++)
  929. X                ;
  930. X            if (vars)
  931. X            print_objid(vars->name, vars->name_length);
  932. X            printf("\n");
  933. X        }
  934. X        }
  935. X    }
  936. X    } else if (op == TIMED_OUT){
  937. X    /* We don't restart on timeout so main will exit */
  938. X    printf("Timed Out\n");
  939. X    }
  940. X    return 1;
  941. X}
  942. X
  943. Xmain(argc, argv)
  944. X    int        argc;
  945. X    char    *argv[];
  946. X{
  947. X    struct snmp_session    session, *ss;
  948. X    struct snmp_pdu *pdu;
  949. X    int    arg;
  950. X    char *gateway = NULL;
  951. X    char *community = NULL;
  952. X    int    count, numfds, gotroot = 0, block;
  953. X    fd_set fdset;
  954. X    struct timeval timeout, *tvp;
  955. X    struct state *state = &state_info;
  956. X
  957. X    init_mib();
  958. X    /*
  959. X     * usage: snmpwalk gateway-name community-name [object-id]
  960. X     */
  961. X    for(arg = 1; arg < argc; arg++){
  962. X    if (argv[arg][0] == '-'){
  963. X        switch(argv[arg][1]){
  964. X        case 'd':
  965. X            snmp_dump_packet++;
  966. X            break;
  967. X        default:
  968. X            printf("invalid option: -%c\n", argv[arg][1]);
  969. X            break;
  970. X        }
  971. X        continue;
  972. X    }
  973. X    if (gateway == NULL){
  974. X        gateway = argv[arg];
  975. X    } else if (community == NULL){
  976. X        community = argv[arg]; 
  977. X    } else {
  978. X        state->rootlen = MAX_NAME_LEN;
  979. X        if (read_objid(argv[arg], state->root, &state->rootlen)){
  980. X        gotroot = 1;
  981. X        } else {
  982. X        printf("Invalid object identifier: %s\n", argv[arg]);
  983. X        }
  984. X    }
  985. X    }
  986. X
  987. X    if (gotroot == 0){
  988. X    bcopy((char *)objid_mib, (char *)state->root, sizeof(objid_mib));
  989. X    state->rootlen = sizeof(objid_mib) / sizeof(oid);
  990. X    gotroot = 1;
  991. X    }
  992. X
  993. X    if (!(gateway && community && gotroot == 1)){
  994. X    printf("usage: snmpwalk gateway-name community-name object-identifier\n");
  995. X    exit(1);
  996. X    }
  997. X
  998. X    session.peername = gateway;
  999. X    session.community = (u_char *)community;
  1000. X    session.community_len = strlen((char *)community);
  1001. X    session.retries = SNMP_DEFAULT_RETRIES;
  1002. X    session.timeout = SNMP_DEFAULT_TIMEOUT;
  1003. X    session.authenticator = NULL;
  1004. X    session.callback = snmp_input;
  1005. X    session.callback_magic = (void *)state;
  1006. X    ss = snmp_open(&session);
  1007. X    if (ss == NULL){
  1008. X    printf("Couldn't open snmp\n");
  1009. X    exit(-1);
  1010. X    }
  1011. X
  1012. X    state->running = 1;
  1013. X    state->waiting = 0;
  1014. X    bcopy((char *)state->root, (char *)state->name, state->rootlen * sizeof(oid));
  1015. X    state->name_length = state->rootlen;
  1016. X
  1017. X    while(state->running){
  1018. X    if (!state->waiting){
  1019. X        pdu = snmp_pdu_create(GETNEXT_REQ_MSG);
  1020. X
  1021. X        snmp_add_null_var(pdu, state->name, state->name_length);
  1022. X
  1023. X        if (snmp_send(ss, pdu) == 0){
  1024. X        snmp_free_pdu(pdu);
  1025. X        state->running = 0;
  1026. X        }
  1027. X    }
  1028. X    state->waiting = 1;    
  1029. X
  1030. X    numfds = 0;
  1031. X    FD_ZERO(&fdset);
  1032. X    block = 1;
  1033. X    tvp = &timeout;
  1034. X    timerclear(tvp);
  1035. X    snmp_select_info(&numfds, &fdset, tvp, &block);
  1036. X    if (block == 1)
  1037. X        tvp = NULL;    /* block without timeout */
  1038. X    count = select(numfds, &fdset, 0, 0, tvp);
  1039. X    if (count > 0){
  1040. X        snmp_read(&fdset);
  1041. X    } else switch(count){
  1042. X        case 0:
  1043. X        snmp_timeout();
  1044. X        break;
  1045. X        case -1:
  1046. X        if (errno == EINTR){
  1047. X            continue;
  1048. X        } else {
  1049. X            perror("select");
  1050. X        }
  1051. X        default:
  1052. X        printf("select returned %d\n", count);
  1053. X    }
  1054. X    }
  1055. X}
  1056. X
  1057. END_OF_FILE
  1058.   if test 6401 -ne `wc -c <'nocol-3.0/src/cmu-snmp/apps/snmpwalk_asy.c'`; then
  1059.     echo shar: \"'nocol-3.0/src/cmu-snmp/apps/snmpwalk_asy.c'\" unpacked with wrong size!
  1060.   fi
  1061.   # end of 'nocol-3.0/src/cmu-snmp/apps/snmpwalk_asy.c'
  1062. fi
  1063. if test -f 'nocol-3.0/src/cmu-snmp/man/snmpnetstat.1' -a "${1}" != "-c" ; then 
  1064.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/man/snmpnetstat.1'\"
  1065. else
  1066.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/man/snmpnetstat.1'\" \(6613 characters\)
  1067.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/man/snmpnetstat.1' <<'END_OF_FILE'
  1068. X.\* /***********************************************************
  1069. X.\"     Copyright 1989 by Carnegie Mellon University
  1070. X.\" 
  1071. X.\"                       All Rights Reserved
  1072. X.\" 
  1073. X.\" Permission to use, copy, modify, and distribute this software and its 
  1074. X.\" documentation for any purpose and without fee is hereby granted, 
  1075. X.\" provided that the above copyright notice appear in all copies and that
  1076. X.\" both that copyright notice and this permission notice appear in 
  1077. X.\" supporting documentation, and that the name of CMU not be
  1078. X.\" used in advertising or publicity pertaining to distribution of the
  1079. X.\" software without specific, written prior permission.  
  1080. X.\" 
  1081. X.\" CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1082. X.\" ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  1083. X.\" CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  1084. X.\" ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1085. X.\" WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1086. X.\" ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1087. X.\" SOFTWARE.
  1088. X.\" ******************************************************************/
  1089. X.\" Copyright (c) 1983 The Regents of the University of California.
  1090. X.\" All rights reserved.
  1091. X.\"
  1092. X.\" Redistribution and use in source and binary forms are permitted
  1093. X.\" provided that the above copyright notice and this paragraph are
  1094. X.\" duplicated in all such forms and that any documentation,
  1095. X.\" advertising materials, and other materials related to such
  1096. X.\" distribution and use acknowledge that the software was developed
  1097. X.\" by the University of California, Berkeley.  The name of the
  1098. X.\" University may not be used to endorse or promote products derived
  1099. X.\" from this software without specific prior written permission.
  1100. X.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1101. X.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1102. X.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1103. X.\"
  1104. X.\"    @(#)netstat.1    6.8 (Berkeley) 9/20/88
  1105. X.\"
  1106. X.TH SNMPNETSTAT 1 "September 17, 1989"
  1107. X.UC 5
  1108. X.SH NAME
  1109. Xsnmpnetstat \- show network status using SNMP
  1110. X.SH SYNOPSIS
  1111. X.B snmpnetstat
  1112. X.I host community
  1113. X[ 
  1114. X.B \-an
  1115. X]
  1116. X.br
  1117. X.B snmpnetstat
  1118. X.I host community
  1119. X[ 
  1120. X.B \-inrs
  1121. X]
  1122. X.br
  1123. X.B snmpnetstat
  1124. X.I host community
  1125. X[ 
  1126. X.B \-n
  1127. X] [
  1128. X.B \-I
  1129. X.I interface
  1130. X]
  1131. X.I interval
  1132. X.br
  1133. X.B snmpnetstat
  1134. X.I host community
  1135. X[ 
  1136. X.B \-p
  1137. X.I protocol
  1138. X]
  1139. X.SH DESCRIPTION
  1140. XThe
  1141. X.I snmpnetstat 
  1142. Xcommand symbolically displays the values of various network-related
  1143. Xinformation retrieved from a remote system using the SNMP protocol.
  1144. XThere are a number of output formats,
  1145. Xdepending on the options for the information presented.
  1146. XThe first form of the command displays a list of active sockets.
  1147. XThe second form presents the values of other network-related
  1148. Xinformation according to the option selected.
  1149. XUsing the third form, with an 
  1150. X.I interval
  1151. Xspecified,
  1152. X.I snmpnetstat
  1153. Xwill continuously display the information regarding packet
  1154. Xtraffic on the configured network interfaces.
  1155. XThe fourth form displays statistics about the named protocol.
  1156. X.PP
  1157. XThe
  1158. X.I host
  1159. Xspecification may be either a host name or an internet address
  1160. Xspecified in "dot notation"
  1161. X.PP
  1162. XThe
  1163. X.I community
  1164. Xspecifies the community name for the transaction with the remote system.
  1165. X.PP
  1166. XThe options have the following meaning:
  1167. X.TP
  1168. X.B \-a
  1169. XWith the default display,
  1170. Xshow the state of all sockets; normally sockets used by
  1171. Xserver processes are not shown.
  1172. X.TP
  1173. X.B \-i
  1174. XShow the state of all of the interfaces.
  1175. X.TP
  1176. X.BI \-I " interface"
  1177. XShow information only about this interface;
  1178. Xused with an
  1179. X.I interval
  1180. Xas described below.
  1181. X.TP
  1182. X.B \-n
  1183. XShow network addresses as numbers (normally 
  1184. X.I snmpnetstat
  1185. Xinterprets addresses and attempts to display them
  1186. Xsymbolically).
  1187. XThis option may be used with any of the display formats.
  1188. X.TP
  1189. X.BI \-p " protocol"
  1190. XShow statistics about 
  1191. X.IR protocol ,
  1192. Xwhich is either a well-known name for a protocol or an alias for it.  Some
  1193. Xprotocol names and aliases are listed in the file 
  1194. X.IR /etc/protocols .
  1195. XA null response typically means that there are no interesting numbers to 
  1196. Xreport.
  1197. XThe program will complain if
  1198. X.I protocol
  1199. Xis unknown or if there is no statistics routine for it.
  1200. X.TP
  1201. X.B \-s
  1202. XShow per-protocol statistics.
  1203. X.TP
  1204. X.B \-r
  1205. XShow the routing tables.
  1206. XWhen
  1207. X.B \-s
  1208. Xis also present, show routing statistics instead.
  1209. X.PP
  1210. XThe default display, for active sockets, shows the local
  1211. Xand remote addresses, protocol,
  1212. Xand the internal state of the protocol.
  1213. XAddress formats are of the form ``host.port'' or ``network.port''
  1214. Xif a socket's address specifies a network but no specific host address.
  1215. XWhen known the host and network addresses are displayed symbolically
  1216. Xaccording to the data bases
  1217. X.I /etc/hosts
  1218. Xand
  1219. X.IR /etc/networks ,
  1220. Xrespectively.  If a symbolic name for an address is unknown, or if
  1221. Xthe 
  1222. X.B \-n
  1223. Xoption is specified, the address is printed numerically, according
  1224. Xto the address family.
  1225. XFor more information regarding 
  1226. Xthe Internet ``dot format,''
  1227. Xrefer to 
  1228. X.IR inet (3N).
  1229. XUnspecified,
  1230. Xor ``wildcard'', addresses and ports appear as ``*''.  
  1231. X.PP
  1232. XThe interface display provides a table of cumulative
  1233. Xstatistics regarding packets transferred, errors, and collisions.
  1234. XThe network addresses of the interface
  1235. Xand the maximum transmission unit (``mtu'') are also displayed.
  1236. X.PP
  1237. XThe routing table display indicates the available routes and
  1238. Xtheir status.  Each route consists of a destination host or network
  1239. Xand a gateway to use in forwarding packets.  The flags field shows
  1240. Xthe state of the route (``U'' if ``up''), whether the route
  1241. Xis to a gateway (``G''), whether the route was created dynamically
  1242. Xby a redirect (``D''), and whether the route has been modified
  1243. Xby a redirect (``M'').  Direct routes are created for each
  1244. Xinterface attached to the local host;
  1245. Xthe gateway field for such entries shows the address of the outgoing interface.
  1246. XThe interface entry indicates the network
  1247. Xinterface utilized for the route.
  1248. X.PP
  1249. XWhen 
  1250. X.I snmpnetstat
  1251. Xis invoked with an
  1252. X.I interval
  1253. Xargument, it displays a running count of statistics related to
  1254. Xnetwork interfaces.  This display consists of a
  1255. Xcolumn for the primary interface
  1256. Xand a column summarizing
  1257. Xinformation for all interfaces.
  1258. XThe primary interface may be replaced with another interface with the
  1259. X.I \-I
  1260. Xoption.
  1261. XThe first line of each screen of information contains a summary since the
  1262. Xsystem was last rebooted.  Subsequent lines of output show values
  1263. Xaccumulated over the preceding interval.
  1264. X.SH SEE ALSO
  1265. Xiostat(1),
  1266. Xvmstat(1),
  1267. Xhosts(5),
  1268. Xnetworks(5),
  1269. Xprotocols(5),
  1270. Xservices(5),
  1271. XRFC1067
  1272. X.SH BUGS
  1273. XThe notion of errors is ill-defined.
  1274. END_OF_FILE
  1275.   if test 6613 -ne `wc -c <'nocol-3.0/src/cmu-snmp/man/snmpnetstat.1'`; then
  1276.     echo shar: \"'nocol-3.0/src/cmu-snmp/man/snmpnetstat.1'\" unpacked with wrong size!
  1277.   fi
  1278.   # end of 'nocol-3.0/src/cmu-snmp/man/snmpnetstat.1'
  1279. fi
  1280. if test -f 'nocol-3.0/src/cmu-snmp/man/snmpwalk.1' -a "${1}" != "-c" ; then 
  1281.   echo shar: Will not clobber existing file \"'nocol-3.0/src/cmu-snmp/man/snmpwalk.1'\"
  1282. else
  1283.   echo shar: Extracting \"'nocol-3.0/src/cmu-snmp/man/snmpwalk.1'\" \(3034 characters\)
  1284.   sed "s/^X//" >'nocol-3.0/src/cmu-snmp/man/snmpwalk.1' <<'END_OF_FILE'
  1285. X.\* /***********************************************************
  1286. X.\"     Copyright 1988, 1989 by Carnegie Mellon University
  1287. X.\" 
  1288. X.\"                       All Rights Reserved
  1289. X.\" 
  1290. X.\" Permission to use, copy, modify, and distribute this software and its 
  1291. X.\" documentation for any purpose and without fee is hereby granted, 
  1292. X.\" provided that the above copyright notice appear in all copies and that
  1293. X.\" both that copyright notice and this permission notice appear in 
  1294. X.\" supporting documentation, and that the name of CMU not be
  1295. X.\" used in advertising or publicity pertaining to distribution of the
  1296. X.\" software without specific, written prior permission.  
  1297. X.\" 
  1298. X.\" CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1299. X.\" ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  1300. X.\" CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  1301. X.\" ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1302. X.\" WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1303. X.\" ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1304. X.\" SOFTWARE.
  1305. X.\" ******************************************************************/
  1306. X.TH SNMPWALK 1 "17 September 1989"
  1307. X.UC 4
  1308. X.SH NAME
  1309. Xsnmpwalk - communicates with a network entity using SNMP GET Next Requests.
  1310. X.SH SYNOPSIS
  1311. Xsnmpwalk host community [variable-name]
  1312. X.SH DESCRIPTION
  1313. XSnmpwalk is an SNMP application that uses GET NEXT Requests to query for a tree
  1314. Xof information about a network entity.
  1315. X.PP
  1316. XThe
  1317. X.I host
  1318. Xspecification may be either a host name or an internet address
  1319. Xspecified in "dot notation"
  1320. X.PP
  1321. XThe
  1322. X.I community
  1323. Xspecifies the community name for the transaction with the remote system.
  1324. X.PP
  1325. XA variable may also be given on the
  1326. Xcommand line.  This variable specifies which portion of the object identifier
  1327. Xspace will be searched using GET NEXT Requests.  All variables in the subtree
  1328. Xbelow the given variable are queried and their values presented to the user.
  1329. XEach variable name is given in the format specified in
  1330. X.IR variables (5).
  1331. X.PP
  1332. XIf the "variable-name" argument is not present, snmpwalk will search the whole Internet MIB.
  1333. X.PP
  1334. XFor example
  1335. X.PP
  1336. X.I snmpwalk netdev-kbox.cc.cmu.edu public system
  1337. X.PP
  1338. Xwill retrieve the variables sysDescr.0 and sysObjectID.0 and sysUpTime.0:
  1339. X.PP
  1340. X.I Name: system.sysDescr.0
  1341. X.br
  1342. X.I OCTET STRING- (ascii):    Kinetics FastPath2
  1343. X.PP
  1344. X.I Name: system.sysObjectID.0
  1345. X.br
  1346. X.I OBJECT IDENTIFIER:  .iso.org.dod.internet.private.enterprises.CMU.sysID.CMU-KIP
  1347. X.PP
  1348. X.I Name: system.sysUpTime.0
  1349. X.br
  1350. X.I Timeticks: (2291082) 6:21:50
  1351. X.PP
  1352. XIf the network entity has an error processing the request packet, an error
  1353. Xpacket will be returned and a message will be shown, helping to pinpoint why
  1354. Xthe request was malformed.
  1355. X.PP
  1356. XIf the tree search causes attempts to search beyond the end of the MIB, a message
  1357. Xwill be displayed:
  1358. X.PP
  1359. X.I End of MIB.
  1360. X.PP
  1361. XAdding a "-d" to the argument list will cause the application to dump input and output packets.
  1362. X.PP
  1363. X.SH "SEE ALSO"
  1364. Xvariables(5), RFC 1065, RFC 1066, RFC 1067
  1365. END_OF_FILE
  1366.   if test 3034 -ne `wc -c <'nocol-3.0/src/cmu-snmp/man/snmpwalk.1'`; then
  1367.     echo shar: \"'nocol-3.0/src/cmu-snmp/man/snmpwalk.1'\" unpacked with wrong size!
  1368.   fi
  1369.   # end of 'nocol-3.0/src/cmu-snmp/man/snmpwalk.1'
  1370. fi
  1371. if test -f 'nocol-3.0/src/doc/nocol.1' -a "${1}" != "-c" ; then 
  1372.   echo shar: Will not clobber existing file \"'nocol-3.0/src/doc/nocol.1'\"
  1373. else
  1374.   echo shar: Extracting \"'nocol-3.0/src/doc/nocol.1'\" \(6241 characters\)
  1375.   sed "s/^X//" >'nocol-3.0/src/doc/nocol.1' <<'END_OF_FILE'
  1376. X.\" $Header: /home/aggarwal/lsrc/nocol/src/doc/RCS/nocol.1,v 1.7 1993/10/28 16:38:03 aggarwal Exp $
  1377. X.\"
  1378. X.TH NOCOL 1 "October 1, 1993"
  1379. X.SH NAME
  1380. Xnocol \- NOCOL (
  1381. X.I Network Operation Center On-Line
  1382. X) display agent for the monitoring package. This program displays
  1383. Xevents being monitored by the various monitors.
  1384. X.SH USAGE
  1385. X.B nocol
  1386. X[
  1387. X.B \-e
  1388. X] [
  1389. X.B \-d
  1390. X] [
  1391. X.B \-l 
  1392. X.I level
  1393. X] [
  1394. X.I data-directory
  1395. X]
  1396. X.SH OPTIONS
  1397. X.TP
  1398. X.B \-e
  1399. XFor \fIextended\fR (132 column) display mode (resize your terminal to 132
  1400. Xcolumn mode)
  1401. X.TP
  1402. X.B \-d
  1403. XFor \fIdebug\fR mode - various debug messages are displayed in the message
  1404. Xwindow to help debug the program.
  1405. X.TP
  1406. X.B \-l
  1407. XThe display \fIlevel\fR which varies from:
  1408. X.DS
  1409. X.br
  1410. X    1    Critical events only
  1411. X.br
  1412. X    2    Errors and critical events
  1413. X.br
  1414. X    3    Warning, errors and critical events
  1415. X.br
  1416. X    4    Informational, warning, errors and critical events
  1417. X.DE
  1418. X.TP
  1419. X.I <data directory>
  1420. Xwhich is an alternate data directory name where NOCOL format data files are
  1421. Xlocated. If no directory name is specified, then the program parses all files
  1422. Xin a predefined
  1423. X.I data
  1424. Xdirectory.
  1425. X.SH DESCRIPTION
  1426. X.LP
  1427. X.B nocol
  1428. Xis the display agent for viewing the event data collected by various
  1429. Xmonitoring programs in the NOCOL format. It uses the 
  1430. X.I curses
  1431. Xscreen management system and thus supports a wide variety of terminal types.
  1432. X
  1433. XAll events in NOCOL are classified as
  1434. X.I CRITICAL, ERROR, WARNING
  1435. Xand
  1436. X.I INFO.
  1437. XDepending on the user selectable display 
  1438. X.IR level ,
  1439. Xall events more severe than the selected level are displayed.
  1440. XHence if the selected display level is '3 (=WARNING)',
  1441. Xthen all CRITICAL, ERROR and WARNING events are displayed on the terminal.
  1442. X
  1443. XThe screen automatically scrolls if there are more than a screenful of events
  1444. Xto be displayed. If a new site goes CRITICAL, the terminal starts beeping (if
  1445. Xthe terminal type supports it) and the site shows up in reverse video.
  1446. X
  1447. XA portion of the screen is used for displaying text messages (the 
  1448. X.I MESSAGES
  1449. Xwindow). All files in a specific 
  1450. X.I MSGS
  1451. Xdirectory are displayed line by line sequentially. This can give information
  1452. Xabout scheduled downtimes,  past logs, debug messages, etc.
  1453. X
  1454. XAdditional capabilities include freezing the screen so that the next
  1455. Xscreenful is displayed only when the user enters a key on the terminal,
  1456. Xfiltering out the sites to be displayed by putting a filter which tests
  1457. Xagainst the lines to be displayed, resizing window size, etc.
  1458. X
  1459. X.SH DISPLAY FIELDS
  1460. XThe various fields that are displayed in \fBnocol\fR are:
  1461. X.IP Site name
  1462. Xwhich is the name of the system that is being monitored.
  1463. X.IP Address
  1464. XThis is the network address (IP, OSI NSAP) or any other resource
  1465. Xfor the entity being monitored.
  1466. X.IP Date/Time
  1467. Xthe time stamp for the event. Note that some (most) monitors set this to the
  1468. Xtime when the site was \fIinitially\fR detected in the current state 
  1469. X.RI ( e.g.
  1470. Xwhen a site was first detected unreachable via
  1471. X.IR ping ).
  1472. X.IP Sender
  1473. Xis the name of the monitoring program
  1474. X.RI ( "pingmon, nsmon, tsmon, tpmon"
  1475. X) that recorded this event.
  1476. X.IP Variable
  1477. Xis the name of the variable that is being monitored. Further information
  1478. Xregarding the type of variable and its properties can be found in the
  1479. Xdescriptions of the respective 
  1480. X.IR Sender .
  1481. XTypical names are
  1482. X.I reachability, thruput, named-status.
  1483. X.IP Value
  1484. XIt is a long integer indicating the value of the variable being monitored.
  1485. X.IP Threshold
  1486. XThe threshold value due to which the event is in the present status.
  1487. X.IP Units
  1488. Xit is the units for the value being displayed.
  1489. X.IP Flags
  1490. XThis is an integer used internally by the various agents. Each bit signifies
  1491. Xone of the following flags for that particular site:
  1492. X.in +.5i
  1493. X.DS
  1494. X0x01    Site UP
  1495. X.br
  1496. X0x02    Site DOWN
  1497. X.br
  1498. X0x04    Status UNKNOWN
  1499. X.br
  1500. X0x08    Site in TEST mode
  1501. X.DE
  1502. X.in -.5i
  1503. X.IP Condition
  1504. Xis the last known condition of the variable and is listed as one of
  1505. X.I critical, error, warning 
  1506. Xor
  1507. X.I informational.
  1508. X
  1509. X.SH RUN TIME OPTIONS
  1510. X.LP
  1511. X.I nocol
  1512. Xallows certain options to be entered at the prompt while running the
  1513. Xprogram. A carriage return is not necessary after entering an option,
  1514. Xand the keystrokes are not echoed. Thus, to change the display level,
  1515. Xthe user simply presses a 
  1516. X.I 'l'
  1517. Xon the keyboard followed by a number representing the display level.
  1518. X
  1519. XThe following options can be entered at the prompt while running 
  1520. X.BR nocol \-
  1521. X.TP
  1522. X.B h
  1523. Xfor help
  1524. X.TP
  1525. X.B b
  1526. Xto turn the bell off once a critical event is acknowledged.
  1527. X.TP
  1528. X.B c
  1529. XCondense the number of lines in the 
  1530. X.I event
  1531. Xwindow, and correspondingly increase the size of the 
  1532. X.I messages
  1533. Xwindow.
  1534. X.TP
  1535. X.B d
  1536. Xfor toggling debug mode. Debug messages are displayed in the MESSAGES
  1537. Xsub-window of the nocol display.
  1538. X.TP
  1539. X.B e
  1540. Xfor toggling between extended (132 column) and short (80 column) display modes.
  1541. X.TP
  1542. X.B f
  1543. XFor toggling \fIfreezing\fR the screen. Once this option is set, the screen
  1544. Xwill not scroll until the user enters a key on the keyboard.
  1545. X.TP
  1546. X.B l
  1547. X.I <level>
  1548. Xfor selecting a display level. Here the 
  1549. X.I level
  1550. Xis any number between 1 and 4 (where 
  1551. X.RI 1= "Critical, "
  1552. X.RI 2= "Error, "
  1553. X.RI 3= "Warning, "
  1554. X.RI 4= "Info "
  1555. X). Alternatively, the characters
  1556. X.I C, E, W, I
  1557. Xcan also be used.
  1558. X.TP
  1559. X.B r
  1560. Xto redraw/refresh a messed up screen.
  1561. X.TP
  1562. X.B "s /"
  1563. Xto put a search filter on the lines being displayed. Only lines that match
  1564. Xthe filter specified will be displayed. The filter can have multiple words
  1565. Xseparated by
  1566. X.B '|'
  1567. Xor
  1568. X.B '&'
  1569. Xfor matching either or all of the words. The current mode (extended or not)
  1570. Xis taken into consideration when matching the pattern.
  1571. X.br
  1572. XThus, a filter such as:
  1573. X.in +.5i
  1574. X.DS
  1575. XAWORD | BWORD | CWORD & DWORD | EWORD
  1576. X.DE
  1577. X.in -.5i
  1578. Xwill search for lines that have \fIeither\fR
  1579. X.RS
  1580. X.IP -
  1581. XAWORD or
  1582. X.IP -
  1583. XBWORD or
  1584. X.IP -
  1585. XCWORD and DWORD (both)
  1586. X.IP -
  1587. XEWORD
  1588. X.RE
  1589. X.IP
  1590. Xin the display lines.
  1591. X.TP
  1592. X.B x
  1593. XTo \fIexpand\fR the number of lines in the \fIevent\fR window.
  1594. X.TP
  1595. X.B q
  1596. Xto quit from the program.
  1597. X.\" --------------------------------------------
  1598. X.SH ACCESS
  1599. X.LP
  1600. XThe JvNCnet version of this program can be seen by logging onto
  1601. X.B nocol.jvnc.net
  1602. Xas user
  1603. X.B nocol.
  1604. X.\" --------------------------------------------
  1605. X.SH AUTHOR
  1606. XVikas Aggarwal, vikas@jvnc.net.
  1607. X.SH SEE ALSO
  1608. Xnocol(1) nocol-prog(3) perlnocol(3)
  1609. Xeventselect(8) genmon(8) noclogd(8) nocol-overview(8)
  1610. Xnocol-utility(8) nsmon(8) pingmon(8) portmon(8) 
  1611. Xtpmon(8) trapmon(8)
  1612. X
  1613. END_OF_FILE
  1614.   if test 6241 -ne `wc -c <'nocol-3.0/src/doc/nocol.1'`; then
  1615.     echo shar: \"'nocol-3.0/src/doc/nocol.1'\" unpacked with wrong size!
  1616.   fi
  1617.   # end of 'nocol-3.0/src/doc/nocol.1'
  1618. fi
  1619. if test -f 'nocol-3.0/src/lib/eventlog.c' -a "${1}" != "-c" ; then 
  1620.   echo shar: Will not clobber existing file \"'nocol-3.0/src/lib/eventlog.c'\"
  1621. else
  1622.   echo shar: Extracting \"'nocol-3.0/src/lib/eventlog.c'\" \(6139 characters\)
  1623.   sed "s/^X//" >'nocol-3.0/src/lib/eventlog.c' <<'END_OF_FILE'
  1624. X/* $Header: /home/aggarwal/lsrc/nocol/src/lib/RCS/eventlog.c,v 3.4 1993/11/03 20:51:03 aggarwal Exp $ */
  1625. X
  1626. X/*
  1627. X * DESCRIPTION
  1628. X *    A small library of functions for use in connecting to the
  1629. X *    NOCOL event logging daemon  (noclogd).
  1630. X *
  1631. X * Caveats:
  1632. X *
  1633. X *    The server host is hardcoded  (NLOG_HOST)
  1634. X */
  1635. X
  1636. X/*
  1637. X * AUTHOR
  1638. X *    David Wagner, wagner@jvnc.net
  1639. X *
  1640. X *    Modified by:  vikas@jvnc.net
  1641. X */
  1642. X
  1643. X/*+
  1644. X * $Log: eventlog.c,v $
  1645. X * Revision 3.4  1993/11/03  20:51:03  aggarwal
  1646. X * Added ifdef for h_addr (defined in netdb.h) in case its defined.
  1647. X *
  1648. X * Revision 3.3  1993/11/02  21:20:15  aggarwal
  1649. X * Did not need the htons in front of the sp->s_port on line 134
  1650. X *
  1651. X * Revision 3.2  1993/10/30  03:23:17  aggarwal
  1652. X * Fixed the ntohs and htons mixup
  1653. X *
  1654. X * Revision 3.1  1993/10/11  20:49:19  aggarwal
  1655. X * Fixed bug in converting gethostname() output to inaddr.
  1656. X * Also reduced the delaycount to 50 instead of 100 and sleep(1).
  1657. X *
  1658. X * Revision 3.0  1993/09/21  20:20:08  aggarwal
  1659. X * Deleted the Unix socket feature entirely. Tested, and seems ready
  1660. X * to go.
  1661. X *
  1662. X * Revision 2.0  1993/09/18  21:52:18  aggarwal
  1663. X * This version 2.0 tries to use stream Unix sockets and dgram inet
  1664. X * sockets. This is not workable, see comments in noclogd.c for more
  1665. X * details.
  1666. X *
  1667. X * This file is checked in just to record the way something like this
  1668. X * 'could' be done.
  1669. X *
  1670. X * Revision 1.4  1993/09/14  21:45:59  aggarwal
  1671. X * Put detailed fail message between ifdef DEBUG since we normally
  1672. X * don't want to see this message.
  1673. X *
  1674. X * Revision 1.3  1993/09/14  15:34:45  aggarwal
  1675. X * Does a sizeof(v) instead of sizeof(EVENT)
  1676. X *
  1677. X * Revision 1.2  1993/09/14  12:59:36  aggarwal
  1678. X * Cleaned up and made more robust.
  1679. X *
  1680. X * Revision 1.1  1993/09/13  13:31:22  aggarwal
  1681. X * Initial revision
  1682. X *
  1683. X */
  1684. X
  1685. X#ifndef lint
  1686. X static char rcsid[] = "$Id: eventlog.c,v 3.4 1993/11/03 20:51:03 aggarwal Exp $" ;
  1687. X#endif
  1688. X
  1689. X#include "noclogd.h"
  1690. X#include <sys/time.h>
  1691. X
  1692. X/*
  1693. X * The logfile descriptor:   -2 if it hasn't been opened at all, and
  1694. X *     -1 if openeventlog()  failed.
  1695. X */
  1696. Xstatic int logfd= -2;        /* global in this module */
  1697. Xstatic int delaycount;        /* to prevent overrunning the dgram server */
  1698. Xstatic time_t    closetime;
  1699. X
  1700. X/*
  1701. X * Opens a socket to the nocol logging daemon.
  1702. X * Returns 0 on success, or prints an error message to stderr
  1703. X * and returns -1 on failure. ON failure, it MUST change logfd
  1704. X * to a value of -1.
  1705. X */
  1706. Xint openeventlog()
  1707. X{
  1708. X    struct sockaddr_in    sin;
  1709. X    struct servent    *sp;
  1710. X    char *s ;
  1711. X
  1712. X    /* Silently fail if there's already a connection open */
  1713. X    if (logfd >= 0)
  1714. X      return(-1);
  1715. X
  1716. X    /*
  1717. X     * Try to open a connection to the log address over the network.
  1718. X     */
  1719. X
  1720. X    logfd = socket(AF_INET, SOCK_DGRAM, 0);
  1721. X    if (logfd < 0) {
  1722. X    perror("openeventlog: AF_INET socket() failed");
  1723. X    logfd = -1 ;
  1724. X    return(-1);
  1725. X    }
  1726. X    
  1727. X    /* Got a socket, now assign family, server_addr, dest port */
  1728. X    bzero(&sin, sizeof(sin));
  1729. X
  1730. X    sin.sin_family = AF_INET;
  1731. X    s = NLOG_HOST ;
  1732. X    if (isdigit(*s))        /* given an address, not a name */
  1733. X      sin.sin_addr.s_addr = inet_addr(s);
  1734. X    else
  1735. X    {
  1736. X    struct hostent  *hp ;    /* gethostbyname returns in_addr structures */
  1737. X    if ((hp = gethostbyname(NLOG_HOST)) == NULL)
  1738. X    {
  1739. X        perror("openeventlog");
  1740. X        fprintf(stderr, "gethostbyname() failed for %s\n", NLOG_HOST);
  1741. X        logfd = -1 ;
  1742. X        return(-1);
  1743. X    }
  1744. X#ifdef h_addr        /* in netdb.h */
  1745. X    bcopy((char *)hp->h_addr, (char *)&sin.sin_addr,hp->h_length);
  1746. X#else
  1747. X    bcopy((char *)hp->h_addr_list[0], (char *)&sin.sin_addr,hp->h_length);
  1748. X#endif
  1749. X    }
  1750. X
  1751. X
  1752. X#ifdef DEBUG
  1753. X    fprintf(stderr, "openeventlog: logging to %s\n", inet_ntoa(sin.sin_addr)) ;
  1754. X#endif
  1755. X
  1756. X    if (sin.sin_addr.s_addr == -1)    /* error */
  1757. X    {
  1758. X    perror("openeventlog: inet_addr() failed");
  1759. X    logfd = -1 ;
  1760. X    return(-1);
  1761. X    }    
  1762. X
  1763. X    /* Figure out what port number to use */
  1764. X    if ((sp = getservbyname(NLOG_SERVICE, "udp")) == NULL)
  1765. X      sin.sin_port = htons(NLOG_PORT);
  1766. X    else
  1767. X      sin.sin_port = sp->s_port;
  1768. X    
  1769. X    if (connect(logfd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
  1770. X        perror("client: AF_INET connect() failed");
  1771. X    logfd = -1;
  1772. X    return(-1);
  1773. X    }
  1774. X
  1775. X#ifdef DEBUG
  1776. X    fprintf(stderr, "openeventlog: opened INET socket %d\n", logfd);
  1777. X#endif
  1778. X    
  1779. X    return(0);
  1780. X}
  1781. X
  1782. X/*
  1783. X * Writes an EVENT structure to the nocol logging daemon.
  1784. X * The connection must have been already created with openeventlog().
  1785. X * If logfd = -2, then assumes that the user erred and never called
  1786. X * openeventlog(), so it does it for him.
  1787. X * Returns 0 on success, or prints an error message to stderr
  1788. X * and returns -1  on failure.
  1789. X *
  1790. X * NOTE: since the socket is of the connectionless type, logfd might actually
  1791. X *    be okay, but the logging daemon might not be up. There is no
  1792. X *    way to tell since a connection is not established with the logging
  1793. X *    daemon.
  1794. X */
  1795. X#define RETRY_REOPEN    1*60    /* seconds before trying to reopen logfd */
  1796. X
  1797. Xint eventlog(v)
  1798. X     EVENT *v;
  1799. X{
  1800. X    int bytesleft, retval;
  1801. X
  1802. X    if (logfd == -2)    /* Never been tried, try to open if RETRY_REOPEN */
  1803. X    {
  1804. X    time_t curtime = time((time_t *) NULL);
  1805. X
  1806. X    if ((curtime - closetime) > RETRY_REOPEN)
  1807. X      openeventlog();
  1808. X    }
  1809. X
  1810. X    if (logfd < 0)        /* Silently fail if no connection could be opened */
  1811. X      return(-1);
  1812. X    
  1813. X    for (bytesleft=sizeof(*v); bytesleft > 0; bytesleft-=retval)
  1814. X      if ((retval=write(logfd, (char *)v, bytesleft)) < 0)
  1815. X      {
  1816. X#ifdef DEBUG
  1817. X      perror("eventlog: write() failed");
  1818. X#endif /* DEBUG */
  1819. X      closeeventlog();    /* no point keeping it open */
  1820. X      return(-1);
  1821. X      }
  1822. X
  1823. X    if ((++delaycount % 50) == 0)    /* small delay after X loggings */
  1824. X    {
  1825. X      delaycount = 0 ;
  1826. X      sleep(1);
  1827. X    }
  1828. X
  1829. X    return(0);
  1830. X}
  1831. X
  1832. X/*
  1833. X * Closes the current connection to the nocol logging daemon.
  1834. X */
  1835. Xint closeeventlog()
  1836. X{
  1837. X    /* Silently fail if no connection has been opened yet */
  1838. X    if (logfd < 0)
  1839. X      return(-1);
  1840. X    
  1841. X    if (close(logfd) < 0) {
  1842. X    perror("closeeventlog: close() failed");
  1843. X    return(-1);
  1844. X    }
  1845. X
  1846. X    /*
  1847. X     * Reset things cleanly so we can call openeventlog() later if we want.
  1848. X     * Store the time that we closed the file desc so that we don't try
  1849. X     * and reopen too many times in 'openeventlog'
  1850. X     */
  1851. X    closetime = time((time_t *) NULL);
  1852. X
  1853. X    logfd = -2;
  1854. X    return(0);
  1855. X}
  1856. END_OF_FILE
  1857.   if test 6139 -ne `wc -c <'nocol-3.0/src/lib/eventlog.c'`; then
  1858.     echo shar: \"'nocol-3.0/src/lib/eventlog.c'\" unpacked with wrong size!
  1859.   fi
  1860.   # end of 'nocol-3.0/src/lib/eventlog.c'
  1861. fi
  1862. if test -f 'nocol-3.0/src/netmon/event_dpy.c' -a "${1}" != "-c" ; then 
  1863.   echo shar: Will not clobber existing file \"'nocol-3.0/src/netmon/event_dpy.c'\"
  1864. else
  1865.   echo shar: Extracting \"'nocol-3.0/src/netmon/event_dpy.c'\" \(6423 characters\)
  1866.   sed "s/^X//" >'nocol-3.0/src/netmon/event_dpy.c' <<'END_OF_FILE'
  1867. X/*+ 
  1868. X** $Header: /home/aggarwal/lsrc/nocol/src/netmon/RCS/event_dpy.c,v 1.12 1993/10/30 03:51:04 aggarwal Exp $
  1869. X**/
  1870. X
  1871. X/* Copyright 1993 JvNCnet, Global Enterprise Services */
  1872. X
  1873. X/*+ 
  1874. X** Displays the network events in the event window. Calls upon the
  1875. X** function fill_window() to display *all* files in the datadir.
  1876. X**/
  1877. X
  1878. X/*
  1879. X *
  1880. X *    $Log: event_dpy.c,v $
  1881. X * Revision 1.12  1993/10/30  03:51:04  aggarwal
  1882. X * Changed filter() to nocolfilter() to avoid name conflicts.
  1883. X *
  1884. X * Revision 1.11  1993/10/02  05:29:46  aggarwal
  1885. X * Now puts out the string specified in the header file for consistency.
  1886. X *
  1887. X * Revision 1.10  1992/06/18  21:03:22  aggarwal
  1888. X * Cleaned up for releasing.
  1889. X *
  1890. X * Revision 1.9  1992/05/14  11:02:45  aggarwal
  1891. X * Changed display of address from 'inet_ntoa' to 'char' after change
  1892. X * of the event structure in nocol.h
  1893. X *
  1894. X * Revision 1.4  90/05/13  16:13:47  aggarwal
  1895. X * Added option in display_one_evnt() so that nothing is
  1896. X * displayed (event ignored) if the read struct event
  1897. X * is all zero. This is done to avoid the occurrence
  1898. X * of displaying zeroes if the datafile is open by netmon and is
  1899. X * overwritten by a smaller datafile.
  1900. X * 
  1901. X * Revision 1.1  90/03/09  13:05:33  aggarwal
  1902. X * Initial revision
  1903. X * 
  1904. X */
  1905. X
  1906. X#include    "netmon.h"
  1907. X
  1908. Xstatic int warnbeep ;                /* Set to beep once    */
  1909. Xstatic int startcycle ;                /* if reopening datadir    */
  1910. X
  1911. Xevent_dpy ()
  1912. X{
  1913. X    extern int page;                /* In netmon.h         */
  1914. X    extern struct allwins aw ;            /* In netmon.h        */
  1915. X    extern char *datadir ;            /* in netmon.h        */
  1916. X    static DIR *datadirp ;                 /* Ptr to data dir    */
  1917. X    static int datafd ;                /* Open file desc    */
  1918. X    int display_one_event() ;
  1919. X
  1920. X    if (datadirp == NULL)            /* Not opened yet    */
  1921. X    {
  1922. X    page = 1;                /* reset the value    */
  1923. X    startcycle = 0;
  1924. X    if ((datadirp = opendir(datadir)) == NULL)    /* Cannot open    */
  1925. X    {
  1926. X        wprintw (aw.wmsg, 
  1927. X             "\nevent_dpy (opendir) %s", sys_errlist[errno]) ;
  1928. X        wclrtoeol(aw.wmsg) ;
  1929. X        return(1) ;                /* minor error    */
  1930. X    }
  1931. X    }
  1932. X
  1933. X    if (fill_window(aw.wevent, datadirp, datadir, &datafd, display_one_event))
  1934. X    {
  1935. X    closedir(datadirp);            /* All files displayed    */
  1936. X    datadirp = NULL ;            /* reset to reopen dir    */
  1937. X    datafd = 0 ;
  1938. X    if (warnbeep)
  1939. X    {
  1940. X        Beep() ;                /* Beep once at end    */
  1941. X        warnbeep = 0 ;            /* reset the value    */
  1942. X    }
  1943. X
  1944. X    }
  1945. X    return(0);
  1946. X
  1947. X}                        /* end:  event_dpy    */
  1948. X
  1949. X/*+         display_one_event
  1950. X** FUNCTION:
  1951. X**     This function displays one line / event on the window passed
  1952. X** to it. This funtion is repeatedly called *BY* the fill_window()
  1953. X** function until the window is filled.
  1954. X**
  1955. X** Ignores and prints nothing if the read event struct is zero.
  1956. X** This was done to prevent the program from displaying zeroes if 
  1957. X** the current data file is over-written with new data while the 
  1958. X** file pointer is left after the end of the end of the file - the
  1959. X** program started displaying zeroes if this is not done.
  1960. X**
  1961. X** It first prints out the data as desired using EFMT & SFMT. The
  1962. X** last field (status) is printed out depending on the value of the
  1963. X** event.severity & event.nocop
  1964. X**
  1965. X** Can customize the status part to print whatever you want, but rather
  1966. X** not mess with the EFMT and SFMT parts.
  1967. X** Presently indicates a TEST site by adding "test" in the status.
  1968. X** If IGNORE flag is set, then does not display event at all.
  1969. X**
  1970. X** If the 'startcycle' value is zero, that implies that the data directory
  1971. X** has been reopened (a new cycle). Keep track of the previous critical
  1972. X** sites and the new critical sites. IF the number of critical sites
  1973. X** increases, then force the bell on.
  1974. X**
  1975. X** RETURN VALUES:
  1976. X**     0   if reached end of present file
  1977. X**     1   if not at end of data file.
  1978. X**/
  1979. X
  1980. Xdisplay_one_event(fd, wevent)
  1981. X     int fd ;                    /* opened file descr    */
  1982. X     WINDOW *wevent;                /* Output window    */
  1983. X{
  1984. X    extern int page ;
  1985. X    EVENT v;                    /* from nocol.h        */
  1986. X    static int prevcritical, curcritical ;    /* Number of critical    */
  1987. X
  1988. X    if (startcycle == 0)            /* new cycle        */
  1989. X    {
  1990. X    startcycle = 1 ;
  1991. X    prevcritical = curcritical ;        /* save previous value    */
  1992. X    curcritical = 0 ;
  1993. X    }
  1994. X
  1995. X
  1996. X    if (read (fd, (char *)&v, sizeof(v)) != sizeof(v))
  1997. X      return (0) ;                /* end of file ? */
  1998. X    else
  1999. X    {
  2000. X    static EVENT null_event ;        /* All fields are null    */
  2001. X
  2002. X    if (bcmp(&v, &null_event, sizeof(v)) != 0)    /* not null 'v'    */
  2003. X      if ((int)v.severity <= level && !(v.nocop & n_NODISPLAY))
  2004. X        if (nocolfilter(&v))
  2005. X        {                    /* if to be displayed    */
  2006. X        if (options & emode)                 /* long mode    */
  2007. X          wprintw ( wevent, EFMT, EFIELDS );
  2008. X        else                    /* Short mode    */
  2009. X          wprintw (wevent, SFMT, SFIELDS  );
  2010. X        
  2011. X        switch (v.severity)
  2012. X        {
  2013. X         case E_CRITICAL:
  2014. X            if (!(options & quiet))
  2015. X              warnbeep = 1 ;        /* Beep once in window    */
  2016. X            ++curcritical ;        /* Increase number    */
  2017. X            if (curcritical > prevcritical)
  2018. X              options = options & (~quiet);    /* Force bell on */
  2019. X            
  2020. X            wstandout (wevent);
  2021. X            if (v.nocop & n_TEST)
  2022. X              wprintw (wevent, "%-8.8s", "Test-Cri");
  2023. X            else
  2024. X              wprintw (wevent, "%-8.8s", severity_txt[v.severity]);
  2025. X            wstandend (wevent);
  2026. X            break;
  2027. X         case E_ERROR:
  2028. X            /* Displaying the bold strings is a real pain */
  2029. X/*            wprintw (wevent, "%s", bolds);    /* bold string */
  2030. X            if (v.nocop & n_TEST)
  2031. X              wprintw (wevent, "%-8.8s", "Test-Err");
  2032. X            else
  2033. X              wprintw (wevent, "%-8.8s", severity_txt[v.severity]);
  2034. X            if (bolde)
  2035. X              tputs(bolde, 1, outchar) ;
  2036. X/*            wprintw (wevent, "%s", bolde);    /* turn off bolding */
  2037. X            break;
  2038. X         case E_WARNING:
  2039. X            if (v.nocop & n_TEST)
  2040. X              wprintw (wevent, "%-8.8s", "Test-War");
  2041. X            else
  2042. X              wprintw (wevent, "%-8.8s", severity_txt[v.severity]);
  2043. X            break;
  2044. X         case E_INFO:
  2045. X            wprintw (wevent, "%-8.8s", severity_txt[v.severity]);
  2046. X            break;
  2047. X            
  2048. X        }                /* end of:   switch    */
  2049. X
  2050. X        /*
  2051. X         * This test is necessary since the bold strings were
  2052. X         * causing curses to think that the line had wrapped, and
  2053. X         * the '\n' would insert a blank line. This way, if the
  2054. X         * line wrapped, then the (internal) location of the cursor
  2055. X         * will be low (less than 10 or so).
  2056. X         */
  2057. X/*        if (wevent->_curx > 10)        /* else wrapped line */
  2058. X          wprintw(wevent, "\n") ;    /* insert a newline    */
  2059. X          
  2060. X        }                    /* end: if(severity..)    */
  2061. X    return(1) ;
  2062. X    }                        /* end:  if read()    */
  2063. X
  2064. X}        /* end:  event_dpy    */
  2065. X
  2066. X
  2067. X/*+ 
  2068. X ** FUNCTION:
  2069. X **     To 'beep' on the terminal.
  2070. X **/
  2071. X
  2072. XBeep()
  2073. X{
  2074. X    tputs( bellstr, /* 1 for no lines affected */ 1, 
  2075. X      /* routine to print char, cannot be a macro */ outchar) ;
  2076. X}
  2077. END_OF_FILE
  2078.   if test 6423 -ne `wc -c <'nocol-3.0/src/netmon/event_dpy.c'`; then
  2079.     echo shar: \"'nocol-3.0/src/netmon/event_dpy.c'\" unpacked with wrong size!
  2080.   fi
  2081.   # end of 'nocol-3.0/src/netmon/event_dpy.c'
  2082. fi
  2083. if test -f 'nocol-3.0/src/netmon/utils.c' -a "${1}" != "-c" ; then 
  2084.   echo shar: Will not clobber existing file \"'nocol-3.0/src/netmon/utils.c'\"
  2085. else
  2086.   echo shar: Extracting \"'nocol-3.0/src/netmon/utils.c'\" \(6742 characters\)
  2087.   sed "s/^X//" >'nocol-3.0/src/netmon/utils.c' <<'END_OF_FILE'
  2088. X/*
  2089. X * $Header: /home/aggarwal/lsrc/nocol/src/netmon/RCS/utils.c,v 1.4 1993/10/30 03:55:13 aggarwal Exp $
  2090. X */
  2091. X
  2092. X/* Copyright 1993 JvNCnet, Global Enterprise Services */
  2093. X
  2094. X/*+
  2095. X ** Utility functions:
  2096. X **
  2097. X **      get_reply: prompt and get user's response.
  2098. X **     setuserenviron: get terminal type and extract bold strings
  2099. X **     outchar:    function to print out char (uses macro putc)
  2100. X **
  2101. X **/
  2102. X
  2103. X#ifndef lint
  2104. X static char rcsid[] = "$RCSfile: utils.c,v $ $Revision: 1.4 $ $Date: 1993/10/30 03:55:13 $" ;
  2105. X#endif
  2106. X
  2107. X#include  "netmon.h"
  2108. X
  2109. X/*+         get_reply
  2110. X** FUNCTION:
  2111. X**     This function prompts a user and gets a response from him. The
  2112. X** 'prompt' & 'default' are supplied to the function - it returns a
  2113. X** pointer to a static character string which is the 'reply'.
  2114. X**/
  2115. X
  2116. X#ifndef C_ANY
  2117. X*
  2118. X * Define types of user responses for get_reply()
  2119. X */
  2120. X#define C_ANY        0x0    /* Any character (printable or non-) */
  2121. X#define C_ALPHA        0x1    /* A-z */
  2122. X#define C_DIGIT        0x2    /* 0-9 */
  2123. X#define C_SPACE        0x4    /* SPACE, TAB */
  2124. X#define C_PUNCT        0x8    /* All punctuation characters */
  2125. X
  2126. X#endif    /* C_ANY */
  2127. X
  2128. Xchar *get_reply (prompt, deflt, response_type)
  2129. X     char *prompt;
  2130. X     char *deflt ;
  2131. X     int  response_type ;        /* types defined above */
  2132. X{
  2133. X    static char reply[MAXLINE];
  2134. X    char *r ;                /* temp pointer */
  2135. X    int nodefault = 0, invalid = 0;
  2136. X
  2137. X    reply[sizeof(reply) - 1] = '\0' ;        /* terminate with a NULL */
  2138. X
  2139. X    if (deflt == NULL || *deflt == NULL)
  2140. X      nodefault = 1 ;                /* No default value    */
  2141. X
  2142. X    printf("%s ", prompt);
  2143. X    if (nodefault)
  2144. X      printf(": ");
  2145. X    else
  2146. X      printf("[%s]: ", deflt) ;
  2147. X    if (strlen(prompt) > 70)                /* long string    */
  2148. X      putchar('\n');
  2149. X
  2150. X again:
  2151. X    r = (char *)reply ;
  2152. X    gets(reply) ;
  2153. X    if ( *reply == NULL )
  2154. X    {
  2155. X    if ( nodefault )
  2156. X    {
  2157. X        printf("Invalid NULL response!! Enter again: ");
  2158. X        goto again;
  2159. X    }
  2160. X    else    /* default has been supplied */
  2161. X    {
  2162. X        strncpy(reply, deflt, sizeof(reply) - 1) ;
  2163. X        return (reply) ;
  2164. X    }
  2165. X    }
  2166. X    
  2167. X    /*
  2168. X     * Now check the user's response against the desired response_type
  2169. X     */
  2170. X
  2171. X    if (response_type == C_ANY)
  2172. X      return (reply);
  2173. X
  2174. X    invalid = 0;
  2175. X    while (!invalid && *r)
  2176. X    {
  2177. X    register int ch_type = classify (*r++) ;
  2178. X
  2179. X    if ( (response_type & ch_type) == 0)
  2180. X    {
  2181. X        fprintf (stderr, "Invalid reply. ");
  2182. X        if ( isprint(*(--r)) )
  2183. X        fprintf(stderr, "(character '%c' illegal)\n", *r);
  2184. X        fprintf(stderr, " Enter again: ");
  2185. X        invalid = 1 ;
  2186. X        break ;
  2187. X    }
  2188. X    }    /* end while */
  2189. X
  2190. X    if (invalid)
  2191. X      goto again;
  2192. X    else
  2193. X      return (reply);
  2194. X
  2195. X}    /* end get_reply    */
  2196. X
  2197. X/*
  2198. X * Return class of character 'c' - one of C_ALPHA, C_DIGIT, ... Used
  2199. X * by get_reply()
  2200. X */
  2201. Xclassify (c)
  2202. X  int c ;
  2203. X{
  2204. X
  2205. X    if (isalpha(c))
  2206. X      return (C_ALPHA) ;
  2207. X
  2208. X    else if (isdigit(c))
  2209. X      return (C_DIGIT) ;
  2210. X
  2211. X    else if (isspace(c))
  2212. X      return (C_SPACE) ;
  2213. X
  2214. X    else if (ispunct(c))
  2215. X      return (C_PUNCT);
  2216. X
  2217. X    else
  2218. X      return (C_ANY);
  2219. X
  2220. X}    /* end classify */
  2221. X      
  2222. X/*   */
  2223. X/*+        setuserenviron 
  2224. X** FUNCTION
  2225. X**
  2226. X**    This function attempts to set the environment variables
  2227. X** relevant to the program (like TERM). It modifies the structure
  2228. X** 'environ' which is a pointer to the strings containing the
  2229. X** variables. If an essential environment variable is not set, then
  2230. X** it sets the variable by prompting or by a default value.
  2231. X**
  2232. X** 'putenv' requires that the storage for the variable be static.
  2233. X**
  2234. X** Lastly gets the value of the termcap variable to enable 'bold'
  2235. X** on the terminals. 'md' = bold, 'mh' = half-intensity, 'me' = end all
  2236. X**
  2237. X**/
  2238. X
  2239. Xsetuserenviron ()
  2240. X{
  2241. X    char termtype[MAXLINE], bp[1024] ;             /* needed by tgetent    */
  2242. X    char *get_reply() ;
  2243. X    static char newvar[MAXLINE];        /* has to be static    */
  2244. X    
  2245. X    bzero(termtype, sizeof (termtype)) ;
  2246. X    strcpy (termtype, (char *)getenv("TERM"));    /* retrieve TERM type    */
  2247. X    
  2248. X    if (check_terminal(termtype) == -1)           /* Extract terminal type */
  2249. X      return(-1) ;
  2250. X    
  2251. X    sprintf (newvar, "TERM=%s\0",(char *)termtype);
  2252. X    if (putenv(newvar) != 0)            /* add the new string  */
  2253. X      return (-1) ;
  2254. X    
  2255. X    /*
  2256. X     * Extract the bold string from the '/etc/termcap' ("md")
  2257. X     */
  2258. X    if ( tgetent(bp, termtype) != 1 )        /* some error   */
  2259. X    {
  2260. X    bolds[0] = '\0' ; bolde[0] = '\0' ;    /* Null strings    */
  2261. X    clscr[0] = '\0' ; bellstr[0] = '\0' ;
  2262. X    }
  2263. X    else                    /* bp has valid data    */
  2264. X    {
  2265. X    char *s = (char *)bolds  ;
  2266. X    tgetstr("md", &s) ;            /* extract bold string    */
  2267. X    s = (char *)bolde ;
  2268. X    tgetstr("me", &s) ;            /* end all attr string    */
  2269. X    s = (char *)clscr ;
  2270. X    tgetstr("cl", &s);
  2271. X    s = (char *)bellstr ;
  2272. X    if (tgetstr("bl", &s) == NULL)
  2273. X      strcpy(bellstr, "\007") ;
  2274. X    }
  2275. X    
  2276. X}    /* end setuserenviron    */
  2277. X
  2278. X
  2279. X/*+         check_terminal
  2280. X** FUNCTION:
  2281. X**     Check the supplied terminal string against the arrays
  2282. X** 'good_term' and 'bad_terminals'. Sets the value of the terminal type.
  2283. X** Return 1 if ok, -1 if error.
  2284. X**/
  2285. Xcheck_terminal(ptermtype)
  2286. X     char *ptermtype ;
  2287. X{
  2288. X    register char **p ;
  2289. X    char bp[1024];        /* to extract 'tgetent' entry  */
  2290. X    int tries = 2 , badterm = 1 ;
  2291. X
  2292. X    /* Always prompt  so user can see the terminal type */
  2293. X    strcpy(ptermtype, get_reply("Terminal type", ptermtype,
  2294. X                C_ALPHA|C_DIGIT|C_PUNCT));
  2295. X    for ( p = good_terminals ; **p != NULL ; ++p )
  2296. X      if (strcmp (*p, ptermtype) == 0)
  2297. X    return(1) ;
  2298. X
  2299. X    while (tries--)
  2300. X    {                
  2301. X    fprintf (stderr, "Searching for terminal type '%s'...", ptermtype);
  2302. X
  2303. X    if ( tgetent(bp, ptermtype)  == 1 )
  2304. X    {
  2305. X        badterm = 0 ;            /* Okay terminal type */
  2306. X        fprintf(stderr, "\n") ;
  2307. X        /*
  2308. X         * Now check against unacceptable terminals
  2309. X         */
  2310. X        for ( p = bad_terminals ; **p != NULL ; ++p )
  2311. X          if (strcmp (*p, ptermtype) == 0)
  2312. X          {
  2313. X          badterm = 1 ;
  2314. X          break ;
  2315. X          }
  2316. X    }
  2317. X    else                /* Couldn't get term entry */
  2318. X    {
  2319. X        badterm = 1 ;
  2320. X        fprintf(stderr, "not found\n") ;
  2321. X    }
  2322. X
  2323. X    if (!badterm)
  2324. X      return (1) ;
  2325. X
  2326. X    if (tries)
  2327. X      strncpy(ptermtype, get_reply("Terminal type", "vt100",
  2328. X                      C_ALPHA|C_DIGIT|C_PUNCT), MAXLINE -1);
  2329. X    else
  2330. X      break ;
  2331. X
  2332. X    }        /* end while() */
  2333. X
  2334. X    strcpy(ptermtype, "dumb") ;        /* set terminal type to dumb    */
  2335. X    fprintf(stderr, "Setting terminal type to '%s'\n", ptermtype) ;
  2336. X    sleep (2) ;
  2337. X    if ( tgetent(bp, ptermtype) <= 0 )        /* can't even find dumb */
  2338. X    {
  2339. X    fprintf(stderr, "(%s) ERROR: tgetent cannot find entry for '%s'\n",
  2340. X        prognm, ptermtype);
  2341. X    return (-1) ;                /* error */
  2342. X    }
  2343. X    else
  2344. X      return(1);
  2345. X}
  2346. X     
  2347. X/*+ 
  2348. X** FUNCTION:
  2349. X**     Just wakeup from the ALARM signal. Do nothing.
  2350. X**/
  2351. Xvoid wakeup()
  2352. X{
  2353. X    signal(SIGALRM, SIG_DFL);        /* restore default action */
  2354. X    if (options & debug)
  2355. X      fprintf(stderr, "(debug) wakeup: reset SIGALRM to SIG_DFL") ;
  2356. X}
  2357. X
  2358. X
  2359. X/*+ 
  2360. X ** FUNCTION:
  2361. X **     Prints out character to the terminal. Used by tputs, and hence
  2362. X ** cannot be a macro
  2363. X **/
  2364. Xoutchar(c)
  2365. X     char c ;
  2366. X{
  2367. X    putc (c, stdout) ;
  2368. X}
  2369. X
  2370. END_OF_FILE
  2371.   if test 6742 -ne `wc -c <'nocol-3.0/src/netmon/utils.c'`; then
  2372.     echo shar: \"'nocol-3.0/src/netmon/utils.c'\" unpacked with wrong size!
  2373.   fi
  2374.   # end of 'nocol-3.0/src/netmon/utils.c'
  2375. fi
  2376. if test -f 'nocol-3.0/src/perlnocol/bpmon' -a "${1}" != "-c" ; then 
  2377.   echo shar: Will not clobber existing file \"'nocol-3.0/src/perlnocol/bpmon'\"
  2378. else
  2379.   echo shar: Extracting \"'nocol-3.0/src/perlnocol/bpmon'\" \(6484 characters\)
  2380.   sed "s/^X//" >'nocol-3.0/src/perlnocol/bpmon' <<'END_OF_FILE'
  2381. X#!/usr/local/bin/perl
  2382. X#
  2383. X# $Header: /home/aggarwal/lsrc/nocol/src/perlnocol/RCS/bpmon,v 1.3 1993/11/01 23:44:40 aggarwal Exp $
  2384. X#
  2385. X#     bpmon - perl bootp service monitor
  2386. X#
  2387. X# Date: September 21, 1993
  2388. X# Programmer: John Wobus, jmwobus@mailbox.syr.edu
  2389. X#  Modifications:  vikas@jvnc.net
  2390. X#
  2391. X#    (c) Syracuse University Computing & Network Services 1993
  2392. X#
  2393. X# No warranty is expressed or implied.  Permission to copy and use is
  2394. X# extended to all.  Permission to redistribute is granted under the
  2395. X# following conditions: it is not sold for profit; this copyright
  2396. X# notice remains intact; the same permissions extend to the recipient;
  2397. X# and if any changes are made, a notice is added so stating.
  2398. X#
  2399. X# Command Format:
  2400. X#
  2401. X#  bpmon
  2402. X#
  2403. X#    Automatically kills old process and forks a new one, reading
  2404. X#    the configuration file in the process.
  2405. X#
  2406. X# What it does:
  2407. X#
  2408. X#    This program is used to monitor a bootp daemon. It uses the
  2409. X#    'bootpquery' program to send out a bootp query to the server, 
  2410. X#    and reports whether it received an answer (in NOCOL format).
  2411. X#     Example report of problem:
  2412. X#
  2413. X#    Site      Address      Time   +-Variable-+ +-Value-+  Condition
  2414. X#   butler  144.1.8.2       13:38  bootp status        1    Critical
  2415. X#
  2416. X#    This reports that a bootp server called "butler" with IP number
  2417. X#    144.1.8.2 went down at 13:38.
  2418. X#
  2419. X##### Output of 'bootpquery'
  2420. X#    sentinel.syr.edu# bootpquery -h
  2421. X#    Usage: bootpquery haddr [htype] [-i ipaddr] [-s server]
  2422. X#                        [-b bootfile] [-v vendor]
  2423. X#    sentinel.syr.edu# bootpquery 0800200846b7 -s 128.230.12.5 
  2424. X#    Received BOOTREPLY from lurch.cns.syr.EDU (128.230.12.5)
  2425. X#
  2426. X#    Hardware Address:       08:00:20:08:46:b7
  2427. X#    Hardware Type:          ethernet
  2428. X#    IP Address:             128.230.4.7
  2429. X#    Boot file:              /tftpboot/mx1500.sys
  2430. X#
  2431. X#    RFC 1048 Vendor Information:
  2432. X#         Time Offset:          18000 seconds
  2433. X#         Subnet Mask:          255.255.255.0
  2434. X#         Gateway:              128.230.4.1
  2435. X#         Domain Name Servers:  128.230.1.49, 128.230.12.5
  2436. X#         Log Server            128.230.12.5
  2437. X#         LPR Server:           128.230.12.5
  2438. X#    sentinel.syr.edu#
  2439. X######
  2440. X# Files used:
  2441. X#
  2442. X#   bootpquery            a Unix command that queries a bootp
  2443. X#                server. Probably can be replaced with
  2444. X#                               'bootptest' with some tweaking.
  2445. X#   nocol/data/bpmon-output     path to which to write nocol events.
  2446. X#   bpmon-confg                 configuration file.
  2447. X#   bpmon.pid                   file holding bpmon's current process id.
  2448. X#
  2449. X# Nocol event elements used:
  2450. X#   sender                     "bpmon"
  2451. X#   mon, day, hour, min        time at which entity went up or down
  2452. X#   severity                   up: 4; down: 3,2,1; test & down: 2;
  2453. X#   nocop                      up, down, unknown
  2454. X#   site
  2455. X#    name                      the server name
  2456. X#    addr                      the server's IP number
  2457. X#   var                       
  2458. X#    name                      "bootp status"
  2459. X#    value                     1=up, 0=down
  2460. X#    threshold                 always 2
  2461. X#    units                     always "entry"
  2462. X#
  2463. X# To install this:
  2464. X#   (1) Choose where to put this file and the above 4 files and
  2465. X#       assign the perl variables below appropriately.
  2466. X#   (2) Create your bpmon-confg file in its chosen place.
  2467. X#   (3) Install bootpquery in your chosen location.
  2468. X#   (4) Put this file in its chosen place.
  2469. X#   (5) Add appropriate code to rc.local to start this monitor.
  2470. X#
  2471. X# Configuration file format:
  2472. X#    #<text>                                   Comment line.
  2473. X#    haddr=<enet addr>                         Ethernet address of host
  2474. X#                                               that is running bpmon.
  2475. X#    broadcast                                 Check queries that are
  2476. X#                                               broadcast.
  2477. X#    <name> <ip number>                        Name and number of bootp
  2478. X#                                               server.
  2479. X#
  2480. X# Sample configuration file:
  2481. X#    # bpmon configuration
  2482. X#    haddr=080020011234
  2483. X#    butler 144.1.8.2
  2484. X#
  2485. X## 
  2486. X##
  2487. X#
  2488. X#
  2489. X############################
  2490. X## Variables customization #  overrides values in the nocollib.pl library
  2491. X############################
  2492. X$rprog="./bootpquery";        # Path for bootpquery program
  2493. X$rpasswd="";            # if NULL, uses the default in rcisco
  2494. X$rcommand="show apple route";
  2495. X$varname="Bootp_Server";
  2496. X$varunits="Status";
  2497. X$sleepint=60*5;               # Seconds to sleep between tries.
  2498. X############################
  2499. X$debug = 0;            # set to 1 for debugging output
  2500. X$libdebug = 0;            # set to 1 for nocollib.pl debugging
  2501. X
  2502. Xrequire  "nocollib.pl" ;
  2503. X
  2504. X-x $rprog || die("Could not find executable $rprog, exiting");
  2505. X
  2506. X@me=split(/\//,$0); $me=pop(@me);
  2507. X#$piddir=join("/",@me); if ($piddir eq "") {$piddir=$etcdir;}
  2508. X$piddir=$etcdir;
  2509. X$cfile="$etcdir/$me-confg";
  2510. X$datafile="$datadir/$me-output";
  2511. X
  2512. X$sender= $me ;                # filled in the EVENT sender
  2513. X$maxseverity = $E_ERROR ;        # max severity of events
  2514. X
  2515. X##
  2516. X# Read the config file. Use '\t' as a separator
  2517. Xsub readconf {
  2518. X    open(CONFIG,"<$cfile")||die("Couldn't find $cfile, exiting");
  2519. X    while(<CONFIG>) {
  2520. X    chop;
  2521. X    if(/^\s*#/) {next;}    # skip comments
  2522. X    if(/^\s*$/) {next;}   # skip blank lines
  2523. X
  2524. X    if (/^\s*haddr=(\S+)(\s.*)?$/) {$haddr=$1;}
  2525. X    elsif (/^\s*broadcast(\s.*)?$/) {push(@items,"255.255.255.255\tbroadcast");}
  2526. X    elsif (/^\s*(\S+)\s+(\S+)(\s.*)?$/) {push(@items,"$2\t$1");}
  2527. X    }
  2528. X    close(CONFIG);
  2529. X    
  2530. X    if(0>$#items){die("Nothing to monitor in $cfile, exiting")};
  2531. X}
  2532. X
  2533. X## This sends a bootpquery to the server. Note handling of broadcast query.
  2534. X#  Returns 0 if server works, 1 if it doesn't. 
  2535. Xsub dotest {
  2536. X    local($server)=@_;
  2537. X    local($command,$works);
  2538. X
  2539. X    if ($server eq "255.255.255.255") {$command = "$rprog $haddr";}
  2540. X    else {$command="$rprog $haddr -s $server"; }
  2541. X    $works=0;
  2542. X    foreach(`$command 2>/dev/null`) {
  2543. X    if(/Received\s+BOOTREPLY/){$works=1;}
  2544. X    }
  2545. X    return($works);
  2546. X}
  2547. X
  2548. X
  2549. X###
  2550. X### Main program:
  2551. X###
  2552. X
  2553. X#Fork and get rid of old process.
  2554. Xif($p=fork){print "$p\n";exit;}
  2555. X&standalone($me,$piddir);
  2556. X
  2557. X&readconf;
  2558. X
  2559. X# $item is an index into the arrays
  2560. Xforeach $item (@items) {
  2561. X    local($number,$name)=split(/\t/,$item);
  2562. X    &init_event("$name", "$number", $item);
  2563. X}
  2564. X
  2565. Xwhile (1) {
  2566. X    foreach $item (@items)
  2567. X    {
  2568. X    local ($status) = &dotest($siteaddr{$item}) ;
  2569. X    
  2570. X    &update_event($item, $status, $status, $maxseverity);
  2571. X    }
  2572. X    
  2573. X    ## Note: we want to write the file quickly.
  2574. X    open(OEVENTS,">$datafile");
  2575. X    foreach $item (@items)  { &writeevent($item) } ;
  2576. X    close(OEVENTS);
  2577. X    sleep($sleepint);
  2578. X    
  2579. X} # end while(forever)
  2580. X
  2581. END_OF_FILE
  2582.   if test 6484 -ne `wc -c <'nocol-3.0/src/perlnocol/bpmon'`; then
  2583.     echo shar: \"'nocol-3.0/src/perlnocol/bpmon'\" unpacked with wrong size!
  2584.   fi
  2585.   chmod +x 'nocol-3.0/src/perlnocol/bpmon'
  2586.   # end of 'nocol-3.0/src/perlnocol/bpmon'
  2587. fi
  2588. echo shar: End of archive 21 \(of 26\).
  2589. cp /dev/null ark21isdone
  2590. MISSING=""
  2591. 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
  2592.     if test ! -f ark${I}isdone ; then
  2593.     MISSING="${MISSING} ${I}"
  2594.     fi
  2595. done
  2596. if test "${MISSING}" = "" ; then
  2597.     echo You have unpacked all 26 archives.
  2598.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2599. else
  2600.     echo You still must unpack the following archives:
  2601.     echo "        " ${MISSING}
  2602. fi
  2603. exit 0
  2604. exit 0 # Just in case...
  2605.