#!/bin/sh # This is `snmp2.09' (part 9 of snmp2). # Do not concatenate these parts, unpack them in order with `/bin/sh'. # File `snmp2/apps/snmpwalk.c' is being continued... # touch -am 1231235999 $$.touch >/dev/null 2>&1 if test ! -f 1231235999 && test -f $$.touch; then shar_touch=touch else shar_touch=: echo echo 'WARNING: not restoring timestamps. Consider getting and' echo "installing GNU \`touch', distributed in GNU File Utilities..." echo fi rm -f 1231235999 $$.touch # if test ! -r _sharseq.tmp; then echo 'Please unpack part 1 first!' exit 1 fi shar_sequence=`cat _sharseq.tmp` if test "$shar_sequence" != 9; then echo "Please unpack part $shar_sequence next!" exit 1 fi if test ! -f _sharnew.tmp; then echo 'x - still skipping snmp2/apps/snmpwalk.c' else echo 'x - continuing file snmp2/apps/snmpwalk.c' sed 's/^X//' << 'SHAR_EOF' >> 'snmp2/apps/snmpwalk.c' && X session.peername = hostname; X if (port_flag) X session.remote_port = dest_port; X if (version == 1){ X session.version = SNMP_VERSION_1; X session.community = (u_char *)community; X session.community_len = strlen((char *)community); X } else if (version == 2){ X session.version = SNMP_VERSION_2; X session.srcParty = src; X session.srcPartyLen = srclen; X session.dstParty = dst; X session.dstPartyLen = dstlen; X session.context = context; X session.contextLen = contextlen; X } X session.retries = SNMP_DEFAULT_RETRIES; X session.timeout = 2000000L; X session.authenticator = NULL; X snmp_synch_setup(&session); X ss = snmp_open(&session); X if (ss == NULL){ X printf("Couldn't open snmp\n"); X exit(-1); X } X X X bcopy((char *)root, (char *)name, rootlen * sizeof(oid)); X name_length = rootlen; X X running = 1; X while(running){ X running = 0; X pdu = snmp_pdu_create(GETNEXT_REQ_MSG); X X snmp_add_null_var(pdu, name, name_length); X X status = snmp_synch_response(ss, pdu, &response); X if (status == STAT_SUCCESS){ X if (response->errstat == SNMP_ERR_NOERROR){ X for(vars = response->variables; vars; X vars = vars->next_variable){ X if (vars->name_length < rootlen X || bcmp(root, vars->name, rootlen * sizeof(oid))) X continue; /* not part of this subtree */ X print_variable(vars->name, vars->name_length, vars); X if (vars->type != SNMP_ENDOFMIBVIEW X && vars->type != SNMP_NOSUCHOBJECT /* for robustness */ X && vars->type != SNMP_NOSUCHINSTANCE){ X bcopy((char *)vars->name, (char *)name, X vars->name_length * sizeof(oid)); X name_length = vars->name_length; X running = 1; /* restart so we can get next variable */ X } X } X } else { X if (response->errstat == SNMP_ERR_NOSUCHNAME){ X printf("End of MIB.\n"); X } else { X printf("Error in packet.\nReason: %s\n", X snmp_errstring(response->errstat)); X if (response->errstat == SNMP_ERR_NOSUCHNAME){ X printf("The request for this object identifier failed: "); X for(count = 1, vars = response->variables; vars X && count != response->errindex; X vars = vars->next_variable, count++) X /*EMPTY*/; X if (vars) X print_objid(vars->name, vars->name_length); X printf("\n"); X } X } X } X X } else if (status == STAT_TIMEOUT){ X printf("No Response from %s\n", hostname); X } else { /* status == STAT_ERROR */ X printf("An error occurred, Quitting\n"); X } X X if (response) X snmp_free_pdu(response); X } X snmp_close(ss); } X X #if 0 /* X * to be part of security client library. X */ find_params(srcParty, dstParty, context, ipaddress, entity, time, security) X struct partyEntry *srcParty, *dstParty; X struct contextEntry *context; X u_long ipaddress; X char *entity; X char *time; X char *security; { X struct partyEntry *pp, *goodParties[32]; X struct contextEntry *cxp, *goodContexts[32]; X struct aclEntry *ap; X int numParties = 0, numContexts = 0; X X party_scanInit(); X for(pp = party_scanNext(); pp; pp = party_scanNext()){ X if (pp->partyTDomain == 1 && !bcmp(pp->partyTAddress, &ipaddress, 4)){ X if (security == 0 || *security == '\0' || !strcmp(security, "*")){ X goodParties[numParties++] = pp; X } else if (!strcmp(security, "auth") X && (pp->partyAuthProtocol == 6)){ X goodParties[numParties++] = pp; X } else if (!strcmp(security, "priv") X && (pp->partyPrivProtocol == 4)){ X goodParties[numParties++] = pp; X } X } X } X /* X * Unfinished ... X */ } X #endif SHAR_EOF echo 'File snmp2/apps/snmpwalk.c is complete' && $shar_touch -am 1015123593 'snmp2/apps/snmpwalk.c' && chmod 0644 'snmp2/apps/snmpwalk.c' || echo 'restore of snmp2/apps/snmpwalk.c failed' shar_count="`wc -c < 'snmp2/apps/snmpwalk.c'`" test 10968 -eq "$shar_count" || echo "snmp2/apps/snmpwalk.c: original size 10968, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/apps/snmptranslate.c ============== if test -f 'snmp2/apps/snmptranslate.c' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/apps/snmptranslate.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/apps/snmptranslate.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/apps/snmptranslate.c' && /* X * X */ /************************************************************************ X Copyright 1988, 1989, 1991, 1992 by Carnegie Mellon University X X All Rights Reserved X Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of CMU not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. X CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ #include #include #include #include X #include "snmp.h" #include "asn1.h" #include "snmp_impl.h" #include "snmp_api.h" #include "snmp_client.h" X extern int errno; int snmp_dump_packet = 0; X #ifdef VXWORKS snmptranslate #else /* VXWORKS */ main #endif X (argc, argv) int argc; char *argv []; { X int arg, count; X char *current_name = NULL; X char *cp, buf[256]; X oid name[MAX_NAME_LEN]; X int name_length; X int tosymbolic = 0; X int description = 0; X int random_access = 0; X X init_mib(); X /* X * usage: snmptranslate name X */ X for(arg = 1; arg < argc; arg++){ X if (argv[arg][0] == '-'){ X switch(argv[arg][1]){ X case 'n': X tosymbolic = 1; X break; X case 'd': X description = 1; X break; X case 'r': X random_access = 1; X break; X default: X printf("invalid option: -%c\n", argv[arg][1]); X break; X } X continue; X } X current_name = argv[arg]; X } X X if (current_name == NULL){ X printf("usage: snmptranslate [-n] [-d] [-r] object-identifier\n"); X return(1); X } X name_length = MAX_NAME_LEN; X if (random_access){ X if (!get_node(current_name, name, &name_length)){ X printf("Unknown object descriptor %s\n", current_name); X return(2); X } X } else { X if (!read_objid(current_name, name, &name_length)){ X printf("Invalid object identifier: %s\n", current_name); X } X } X if (tosymbolic){ X print_objid(name, name_length); X } else { X for(count = 0; count < name_length; count++) X printf(".%d", name[count]); X printf("\n"); X } X if (description){ X printf("\n"); X print_description(name, name_length); X } } X SHAR_EOF $shar_touch -am 1015123593 'snmp2/apps/snmptranslate.c' && chmod 0644 'snmp2/apps/snmptranslate.c' || echo 'restore of snmp2/apps/snmptranslate.c failed' shar_count="`wc -c < 'snmp2/apps/snmptranslate.c'`" test 2816 -eq "$shar_count" || echo "snmp2/apps/snmptranslate.c: original size 2816, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/apps/snmpnetstat/Makefile ============== if test ! -d 'snmp2/apps/snmpnetstat'; then echo 'x - creating directory snmp2/apps/snmpnetstat' mkdir 'snmp2/apps/snmpnetstat' fi if test -f 'snmp2/apps/snmpnetstat/Makefile' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/apps/snmpnetstat/Makefile (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/apps/snmpnetstat/Makefile (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/apps/snmpnetstat/Makefile' && # # Copyright (c) 1987 Regents of the University of California. # All rights reserved. # # Redistribution and use in source and binary forms are permitted # provided that the above copyright notice and this paragraph are # duplicated in all such forms and that any documentation, # advertising materials, and other materials related to such # distribution and use acknowledge that the software was developed # by the University of California, Berkeley. The name of the # University may not be used to endorse or promote products derived # from this software without specific prior written permission. # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. # # @(#)Makefile 5.10 (Berkeley) 9/20/88 # CFLAGS= -g -I../../snmplib LIBS= ../../lib/libsnmp.a SRCS= inet.c if.c main.c route.c OBJS= inet.o if.o main.o route.o X all: snmpnetstat X snmpnetstat: ${OBJS} ${LIBS} X ${CC} -o $@ ${CFLAGS} ${OBJS} ${LIBS} X clean: X rm -f ${OBJS} core snmpnetstat X cleandir: clean X rm -f ${MAN} tags .depend X depend: ${SRCS} X mkdep ${CFLAGS} ${SRCS} X lint: ${SRCS} X lint ${CFLAGS} ${SRCS} X tags: ${SRCS} X ctags ${SRCS} X install: X cp snmpnetstat ../../bin SHAR_EOF $shar_touch -am 1015123593 'snmp2/apps/snmpnetstat/Makefile' && chmod 0644 'snmp2/apps/snmpnetstat/Makefile' || echo 'restore of snmp2/apps/snmpnetstat/Makefile failed' shar_count="`wc -c < 'snmp2/apps/snmpnetstat/Makefile'`" test 1283 -eq "$shar_count" || echo "snmp2/apps/snmpnetstat/Makefile: original size 1283, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/apps/snmpnetstat/if.c ============== if test -f 'snmp2/apps/snmpnetstat/if.c' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/apps/snmpnetstat/if.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/apps/snmpnetstat/if.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/apps/snmpnetstat/if.c' && /***************************************************************** X Copyright 1989, 1991, 1992 by Carnegie Mellon University X X All Rights Reserved X Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of CMU not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. X CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ /* X * Copyright (c) 1983,1988 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that this notice is preserved and that due credit is given X * to the University of California at Berkeley. The name of the University X * may not be used to endorse or promote products derived from this X * software without specific prior written permission. This software X * is provided ``as is'' without express or implied warranty. X */ X #include #include X #include X #include #include X #include "main.h" #include "asn1.h" #include "snmp.h" #include "snmp_impl.h" #include "snmp_api.h" #include "snmp_client.h" #include "mib.h" X #define YES 1 #define NO 0 X extern int nflag; extern char *interface; extern char *routename(), *netname(); extern struct snmp_session *Session; extern struct variable_list *getvarbyname(); X oid oid_ifname[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 1}; static oid oid_ifinucastpkts[] = {1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 1}; static oid oid_cfg_nnets[] = {1, 3, 6, 1, 2, 1, 2, 1, 0}; X #define IFNAME 2 #define IFMTU 4 #define IFOPERSTATUS 8 #define INUCASTPKTS 11 #define INNUCASTPKTS 12 #define INERRORS 14 #define OUTUCASTPKTS 17 #define OUTNUCASTPKTS 18 #define OUTERRORS 20 X /* X * Print a description of the network interfaces. X */ intpr(interval) X int interval; { X oid varname[MAX_NAME_LEN], *instance, *ifentry; X int varname_len; X int ifnum, cfg_nnets; X struct variable_list *var; X char name[128]; X int mtu; X int ipkts, ierrs, opkts, oerrs, operstatus, collisions; X X if (interval) { X sidewaysintpr((unsigned)interval); X return; X } X printf("%-11.11s %-5.5s %-11.11s %-15.15s %8.8s %5.5s %8.8s %5.5s", X "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs", X "Opkts", "Oerrs"); X putchar('\n'); X var = getvarbyname(Session, oid_cfg_nnets, sizeof(oid_cfg_nnets) / sizeof(oid)); X if (var) X cfg_nnets = *var->val.integer; X else X return; X bcopy((char *)oid_ifname, (char *)varname, sizeof(oid_ifname)); X varname_len = sizeof(oid_ifname) / sizeof(oid); X ifentry = varname + 9; X instance = varname + 10; X for (ifnum = 1; ifnum <= cfg_nnets; ifnum++) { X register char *cp; X char *index(); X X *name = mtu = 0; X ipkts = ierrs = opkts = oerrs = operstatus = collisions = 0; X *instance = ifnum; X *ifentry = IFNAME; X var = getvarbyname(Session, varname, varname_len); X if (var){ X bcopy((char *)var->val.string, name, var->val_len); X name[var->val_len] = 0; X } X *ifentry = IFMTU; X var = getvarbyname(Session, varname, varname_len); X if (var) X mtu = *var->val.integer; X *ifentry = IFOPERSTATUS; X var = getvarbyname(Session, varname, varname_len); X if (var) X operstatus = *var->val.integer; X *ifentry = INUCASTPKTS; X var = getvarbyname(Session, varname, varname_len); X if (var) X ipkts = *var->val.integer; X *ifentry = INNUCASTPKTS; X var = getvarbyname(Session, varname, varname_len); X if (var) X ipkts += *var->val.integer; X *ifentry = INERRORS; X var = getvarbyname(Session, varname, varname_len); X if (var) X ierrs = *var->val.integer; X *ifentry = OUTUCASTPKTS; X var = getvarbyname(Session, varname, varname_len); X if (var) X opkts = *var->val.integer; X *ifentry = OUTNUCASTPKTS; X var = getvarbyname(Session, varname, varname_len); X if (var) X opkts += *var->val.integer; X *ifentry = OUTERRORS; X var = getvarbyname(Session, varname, varname_len); X if (var) X oerrs = *var->val.integer; X X name[15] = '\0'; X if (interface != 0 && X strcmp(name, interface) != 0) X continue; X cp = index(name, '\0'); X if (operstatus != MIB_IFSTATUS_UP) X *cp++ = '*'; X *cp = '\0'; X printf("%-11.11s %-5d ", name, mtu); X printf("%-11.11s ", "none"); X printf("%-15.15s ", "none"); X printf("%8d %5d %8d %5d %5d", X ipkts, ierrs, X opkts, oerrs, collisions); X putchar('\n'); X } } X #define MAXIF 128 struct iftot { X char ift_name[128]; /* interface name */ X int ift_ip; /* input packets */ X int ift_ie; /* input errors */ X int ift_op; /* output packets */ X int ift_oe; /* output errors */ X int ift_co; /* collisions */ } iftot[MAXIF]; X u_char signalled; /* set if alarm goes off "early" */ X /* X * Print a running summary of interface statistics. X * Repeat display every interval seconds, showing statistics X * collected over that interval. Assumes that interval is non-zero. X * First line printed at top of screen is always cumulative. X */ sidewaysintpr(interval) X unsigned interval; { X register struct iftot *ip, *total; X register int line; X struct iftot *lastif, *sum, *interesting, ifnow, *now = &ifnow; X int oldmask; X int catchalarm(); X struct variable_list *var; X oid varname[MAX_NAME_LEN], *instance, *ifentry; X int varname_len; X int ifnum, cfg_nnets; X char *index(); X X lastif = iftot; X sum = iftot + MAXIF - 1; X total = sum - 1; X interesting = iftot; X var = getvarbyname(Session, oid_cfg_nnets, sizeof(oid_cfg_nnets) / sizeof(oid)); X if (var) X cfg_nnets = *var->val.integer; X else X return; X bcopy((char *)oid_ifname, (char *)varname, sizeof(oid_ifname)); X varname_len = sizeof(oid_ifname) / sizeof(oid); X for (ifnum = 1, ip = iftot; ifnum <= cfg_nnets; ifnum++) { X char *cp; X X ip->ift_name[0] = '('; X varname[10] = ifnum; X var = getvarbyname(Session, varname, varname_len); X if (var){ X bcopy((char *)var->val.string, ip->ift_name + 1, var->val_len); X } X if (interface && strcmp(ip->ift_name + 1, interface) == 0) X interesting = ip; X ip->ift_name[15] = '\0'; X cp = index(ip->ift_name, '\0'); X sprintf(cp, ")"); X ip++; X if (ip >= iftot + MAXIF - 2) X break; X } X lastif = ip; X X (void)signal(SIGALRM, catchalarm); X signalled = NO; X (void)alarm(interval); banner: X printf(" input %-6.6s output ", interesting->ift_name); X if (lastif - iftot > 0) X printf(" input (Total) output"); X for (ip = iftot; ip < iftot + MAXIF; ip++) { X ip->ift_ip = 0; X ip->ift_ie = 0; X ip->ift_op = 0; X ip->ift_oe = 0; X ip->ift_co = 0; X } X putchar('\n'); X printf("%8.8s %5.5s %8.8s %5.5s %5.5s ", X "packets", "errs", "packets", "errs", "colls"); X if (lastif - iftot > 0) X printf("%8.8s %5.5s %8.8s %5.5s %5.5s ", X "packets", "errs", "packets", "errs", "colls"); X putchar('\n'); X fflush(stdout); X line = 0; loop: X sum->ift_ip = 0; X sum->ift_ie = 0; X sum->ift_op = 0; X sum->ift_oe = 0; X sum->ift_co = 0; X bcopy((char *)oid_ifinucastpkts, (char *)varname, sizeof(oid_ifinucastpkts)); X varname_len = sizeof(oid_ifinucastpkts) / sizeof(oid); X ifentry = varname + 9; X instance = varname + 10; X for (ifnum = 1, ip = iftot; ifnum <= cfg_nnets && ip < lastif; ip++, ifnum++) { X bzero((char *)now, sizeof(*now)); X *instance = ifnum; X *ifentry = INUCASTPKTS; X var = getvarbyname(Session, varname, varname_len); X if (var) X now->ift_ip = *var->val.integer; X *ifentry = INNUCASTPKTS; X var = getvarbyname(Session, varname, varname_len); X if (var) X now->ift_ip += *var->val.integer; X *ifentry = INERRORS; X var = getvarbyname(Session, varname, varname_len); X if (var) X now->ift_ie = *var->val.integer; X *ifentry = OUTUCASTPKTS; X var = getvarbyname(Session, varname, varname_len); X if (var) X now->ift_op = *var->val.integer; X *ifentry = OUTNUCASTPKTS; X var = getvarbyname(Session, varname, varname_len); X if (var) X now->ift_op += *var->val.integer; X *ifentry = OUTERRORS; X var = getvarbyname(Session, varname, varname_len); X if (var) X now->ift_oe = *var->val.integer; X X if (ip == interesting) X printf("%8d %5d %8d %5d %5d ", X now->ift_ip - ip->ift_ip, X now->ift_ie - ip->ift_ie, X now->ift_op - ip->ift_op, X now->ift_oe - ip->ift_oe, X now->ift_co - ip->ift_co); X ip->ift_ip = now->ift_ip; X ip->ift_ie = now->ift_ie; X ip->ift_op = now->ift_op; X ip->ift_oe = now->ift_oe; X ip->ift_co = now->ift_co; X sum->ift_ip += ip->ift_ip; X sum->ift_ie += ip->ift_ie; X sum->ift_op += ip->ift_op; X sum->ift_oe += ip->ift_oe; X sum->ift_co += ip->ift_co; X } X if (lastif - iftot > 0) X printf("%8d %5d %8d %5d %5d ", X sum->ift_ip - total->ift_ip, X sum->ift_ie - total->ift_ie, X sum->ift_op - total->ift_op, X sum->ift_oe - total->ift_oe, X sum->ift_co - total->ift_co); X *total = *sum; X putchar('\n'); X fflush(stdout); X line++; X oldmask = sigblock(sigmask(SIGALRM)); X if (! signalled) { X sigpause(0); X } X sigsetmask(oldmask); X signalled = NO; X (void)alarm(interval); X if (line == 21) X goto banner; X goto loop; X /*NOTREACHED*/ } X /* X * Called if an interval expires before sidewaysintpr has completed a loop. X * Sets a flag to not wait for the alarm. X */ catchalarm() { X signalled = YES; } SHAR_EOF $shar_touch -am 1015123593 'snmp2/apps/snmpnetstat/if.c' && chmod 0644 'snmp2/apps/snmpnetstat/if.c' || echo 'restore of snmp2/apps/snmpnetstat/if.c failed' shar_count="`wc -c < 'snmp2/apps/snmpnetstat/if.c'`" test 9745 -eq "$shar_count" || echo "snmp2/apps/snmpnetstat/if.c: original size 9745, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/apps/snmpnetstat/inet.c ============== if test -f 'snmp2/apps/snmpnetstat/inet.c' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/apps/snmpnetstat/inet.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/apps/snmpnetstat/inet.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/apps/snmpnetstat/inet.c' && /**************************************************************** X Copyright 1989, 1991, 1992 by Carnegie Mellon University X X All Rights Reserved X Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of CMU not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. X CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ /* X * Copyright (c) 1983,1988 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that this notice is preserved and that due credit is given X * to the University of California at Berkeley. The name of the University X * may not be used to endorse or promote products derived from this X * software without specific prior written permission. This software X * is provided ``as is'' without express or implied warranty. X */ X #ifndef VXWORKS #include #endif /* VXWORKS */ X #include X #ifndef VXWORKS #include #endif /* VXWORKS */ X #include X #include X #ifdef VXWORKS #include #else /* VXWORKS */ #include #endif /* VXWORKS */ X #include "main.h" #include "asn1.h" #include "snmp.h" #include "snmp_impl.h" #include "snmp_api.h" #include "snmp_client.h" #include "mib.h" X extern int aflag; extern int nflag; extern char *plural(); extern char *malloc(); extern struct snmp_session *Session; extern struct variable_list *getvarbyname(); X X char *inetname(); X struct stat_table { X int entry; /* entry number in table */ X /* format string to printf(description, value, plural(value)); */ X /* warning: the %d must be before the %s */ X char description[80]; }; X static oid oid_ipstats[] = {1, 3, 6, 1, 2, 1, 4, 0, 0}; struct stat_table ip_stattab[] = { X {3, "%d total datagram%s received"}, X {4, "%d datagram%s with header errors"}, X {5, "%d datagram%s with an invalid destination address"}, X {6, "%d datagram%s forwarded"}, X {7, "%d datagram%s with unknown protocol"}, X {8, "%d datagram%s discarded"}, X {9, "%d datagram%s delivered"}, X {10, "%d output datagram request%s"}, X {11, "%d output datagram%s discarded"}, X {12, "%d datagram%s with no route"}, X {14, "%d fragment%s received"}, X {15, "%d datagram%s reassembled"}, X {16, "%d reassembly failure%s"}, X {17, "%d datagram%s fragmented"}, X {18, "%d fragmentation failure%s"}, X {19, "%d fragment%s created"} }; X static oid oid_udpstats[] = {1, 3, 6, 1, 2, 1, 7, 0, 0}; struct stat_table udp_stattab[] = { X {1, "%d total datagram%s received"}, X {2, "%d datagram%s to invalid port"}, X {3, "%d datagram%s dropped due to errors"}, X {4, "%d output datagram request%s"} }; X static oid oid_tcpstats[] = {1, 3, 6, 1, 2, 1, 6, 0, 0}; struct stat_table tcp_stattab[] = { X {5, "%d active open%s"}, X {6, "%d passive open%s"}, X {7, "%d failed attempt%s"}, X {8, "%d reset%s of established connections"}, X {9, "%d current established connection%s"}, X {10, "%d segment%s received"}, X {11, "%d segment%s sent"}, X {12, "%d segment%s retransmitted"} }; X static oid oid_icmpstats[] = {1, 3, 6, 1, 2, 1, 5, 0, 0}; struct stat_table icmp_stattab[] = { X {1, "%d total message%s received"}, X {2, "%d message%s dropped due to errors"}, X {14, "%d ouput message request%s"}, X {15, "%d output message%s discarded"} }; X struct stat_table icmp_inhistogram[] = { X {3, "Destination unreachable: %d"}, X {4, "Time Exceeded: %d"}, X {5, "Parameter Problem: %d"}, X {6, "Source Quench: %d"}, X {7, "Redirect: %d"}, X {8, "Echo Request: %d"}, X {9, "Echo Reply: %d"}, X {10, "Timestamp Request: %d"}, X {11, "Timestamp Reply: %d"}, X {12, "Address Mask Request: %d"}, X {13, "Addrss Mask Reply:%d"}, }; X struct stat_table icmp_outhistogram[] = { X {16, "Destination unreachable: %d"}, X {17, "Time Exceeded: %d"}, X {18, "Parameter Problem: %d"}, X {19, "Source Quench: %d"}, X {20, "Redirect: %d"}, X {21, "Echo Request: %d"}, X {22, "Echo Reply: %d"}, X {23, "Timestamp Request: %d"}, X {24, "Timestamp Reply: %d"}, X {25, "Address Mask Request: %d"}, X {26, "Addrss Mask Reply:%d"}, }; X struct tcpconn_entry { X oid instance[10]; X struct in_addr localAddress; X int locAddrSet; X u_short localPort; X int locPortSet; X struct in_addr remoteAddress; X int remAddrSet; X u_short remotePort; X int remPortSet; X int state; X int stateSet; X struct tcpconn_entry *next; }; X #define TCPCONN_STATE 1 #define TCPCONN_LOCADDR 2 #define TCPCONN_LOCPORT 3 #define TCPCONN_REMADDR 4 #define TCPCONN_REMPORT 5 X X X static oid oid_tcpconntable[] = {1, 3, 6, 1, 2, 1, 6, 13, 1}; #define ENTRY 9 X char *tcpstates[] = { X "", "CLOSED", "LISTEN", "SYNSENT", X "SYNRECEIVED", "ESTABLISHED", "FINWAIT1", "FINWAIT2", X "CLOSEWAIT", "LASTACK", "CLOSING", "TIMEWAIT" }; #define TCP_NSTATES 11 X /* X * Print a summary of connections related to an Internet X * protocol (currently only TCP). For TCP, also give state of connection. X */ protopr(){ X struct tcpconn_entry *tcpconn = NULL, *tp, *newp; X struct snmp_pdu *request, *response; X struct variable_list *vp; X oid *instance; X int first, status; X X request = snmp_pdu_create(GETNEXT_REQ_MSG); X X snmp_add_null_var(request, oid_tcpconntable, sizeof(oid_tcpconntable)/sizeof(oid)); X X while(1){ X status = snmp_synch_response(Session, request, &response); X if (status != STAT_SUCCESS || response->errstat != SNMP_ERR_NOERROR){ X fprintf(stderr, "SNMP request failed\n"); X break; X } X vp = response->variables; X if (vp->name_length != 20 || X bcmp((char *)vp->name, (char *)oid_tcpconntable, sizeof(oid_tcpconntable))){ X break; X } X X request = snmp_pdu_create(GETNEXT_REQ_MSG); X snmp_add_null_var(request, vp->name, vp->name_length); X X instance = vp->name + 10; X for(tp = tcpconn; tp != NULL; tp = tp->next){ X if (!bcmp((char *)instance, (char *)tp->instance, X sizeof(tp->instance))) X break; X } X if (tp == NULL){ X newp = (struct tcpconn_entry *)malloc(sizeof(struct tcpconn_entry)); X if (tcpconn == NULL){ X tcpconn = newp; X } else { X for(tp = tcpconn; tp->next != NULL; tp = tp->next) X ; X tp->next = newp; X } X tp = newp; X bzero((char *)tp, sizeof(*tp)); X tp->next = NULL; X bcopy((char *)instance, (char *)tp->instance, sizeof(tp->instance)); X } X X if (vp->name[ENTRY] == TCPCONN_STATE){ X tp->state = *vp->val.integer; X tp->stateSet = 1; X X } X X if (vp->name[ENTRY] == TCPCONN_LOCADDR){ X bcopy((char *)vp->val.string, (char *)&tp->localAddress, sizeof(u_long)); X tp->locAddrSet = 1; X X } X X if (vp->name[ENTRY] == TCPCONN_LOCPORT){ X tp->localPort = *vp->val.integer; X tp->locPortSet = 1; X X } X X if (vp->name[ENTRY] == TCPCONN_REMADDR){ X bcopy((char *)vp->val.string, (char *)&tp->remoteAddress, sizeof(u_long)); X tp->remAddrSet = 1; X X } X X if (vp->name[ENTRY] == TCPCONN_REMPORT){ X tp->remotePort = *vp->val.integer; X tp->remPortSet = 1; X X } X X } X X for(first = 1, tp = tcpconn; tp != NULL; tp = tp->next){ X if (!(tp->stateSet && tp->locAddrSet X && tp->locPortSet && tp->remAddrSet && tp->remPortSet)){ X printf("incomplete entry\n"); X continue; X } X if (!aflag && tp->state == MIB_TCPCONNSTATE_LISTEN) X continue; X if (first){ X printf("Active Internet Connections"); X if (aflag) X printf(" (including servers)"); X putchar('\n'); X printf("%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n", X "Proto", "Recv-Q", "Send-Q", X "Local Address", "Foreign Address", "(state)"); X first = 0; X } X printf("%-5.5s %6d %6d ", "tcp", 0, 0); X inetprint(&tp->localAddress, tp->localPort, "tcp"); X inetprint(&tp->remoteAddress, tp->remotePort, "tcp"); X if (tp->state < 1 || tp->state > TCP_NSTATES) X printf(" %d", tp->state); X else X printf(" %s", tcpstates[tp->state]); X putchar('\n'); X } X } X X /* X * Dump UDP statistics structure. X */ udp_stats() { X oid varname[MAX_NAME_LEN], *udpentry; X int varname_len; X struct variable_list *var; X int count; X struct stat_table *sp = udp_stattab; X X bcopy((char *)oid_udpstats, (char *)varname, sizeof(oid_udpstats)); X varname_len = sizeof(oid_udpstats) / sizeof(oid); X udpentry = varname + 7; X printf("udp:\n"); X count = sizeof(udp_stattab) / sizeof (struct stat_table); X while (count--){ X *udpentry = sp->entry; X var = getvarbyname(Session, varname, varname_len); X if (var){ X putchar('\t'); X printf(sp->description, *var->val.integer, plural((int)*var->val.integer)); X putchar('\n'); X } X sp++; X } X } X /* X * Dump TCP statistics structure. X */ tcp_stats() { X oid varname[MAX_NAME_LEN], *tcpentry; X int varname_len; X struct variable_list *var; X int count; X struct stat_table *sp = tcp_stattab; X X bcopy((char *)oid_tcpstats, (char *)varname, sizeof(oid_tcpstats)); X varname_len = sizeof(oid_tcpstats) / sizeof(oid); X tcpentry = varname + 7; X printf("tcp:\n"); X count = sizeof(tcp_stattab) / sizeof (struct stat_table); X while (count--){ X *tcpentry = sp->entry; X var = getvarbyname(Session, varname, varname_len); X if (var){ X putchar('\t'); X printf(sp->description, *var->val.integer, plural((int)*var->val.integer)); X putchar('\n'); X } X sp++; X } X } X /* X * Dump IP statistics structure. X */ ip_stats() { X oid varname[MAX_NAME_LEN], *ipentry; X int varname_len; X struct variable_list *var; X int count; X struct stat_table *sp = ip_stattab; X X bcopy((char *)oid_ipstats, (char *)varname, sizeof(oid_ipstats)); X varname_len = sizeof(oid_ipstats) / sizeof(oid); X ipentry = varname + 7; X printf("ip:\n"); X count = sizeof(ip_stattab) / sizeof (struct stat_table); X while (count--){ X *ipentry = sp->entry; X var = getvarbyname(Session, varname, varname_len); X if (var){ X putchar('\t'); X printf(sp->description, *var->val.integer, plural((int)*var->val.integer)); X putchar('\n'); X } X sp++; X } X } X /* X * Dump ICMP statistics. X */ icmp_stats() { X oid varname[MAX_NAME_LEN], *icmpentry; X int varname_len; X struct variable_list *var; X int count, first; X struct stat_table *sp; X X bcopy((char *)oid_icmpstats, (char *)varname, sizeof(oid_icmpstats)); X varname_len = sizeof(oid_icmpstats) / sizeof(oid); X icmpentry = varname + 7; X printf("icmp:\n"); X sp = icmp_stattab; X count = sizeof(icmp_stattab) / sizeof (struct stat_table); X while (count--){ X *icmpentry = sp->entry; X var = getvarbyname(Session, varname, varname_len); X if (var){ X putchar('\t'); X printf(sp->description, *var->val.integer, plural((int)*var->val.integer)); X putchar('\n'); X } X sp++; X } X X sp = icmp_outhistogram; X first = 1; X count = sizeof(icmp_outhistogram) / sizeof (struct stat_table); X while (count--){ X *icmpentry = sp->entry; X var = getvarbyname(Session, varname, varname_len); X if (var && *var->val.integer != 0){ X if (first){ X printf("\tOutput Histogram:\n"); X first = 0; X } X printf("\t\t"); X printf(sp->description, *var->val.integer, plural((int)*var->val.integer)); X putchar('\n'); X } X sp++; X } X X sp = icmp_inhistogram; X first = 1; X count = sizeof(icmp_inhistogram) / sizeof (struct stat_table); X while (count--){ X *icmpentry = sp->entry; X var = getvarbyname(Session, varname, varname_len); X if (var && *var->val.integer != 0){ X if (first){ X printf("\tInput Histogram:\n"); X first = 0; X } X printf("\t\t"); X printf(sp->description, *var->val.integer, plural((int)*var->val.integer)); X putchar('\n'); X } X sp++; X } } X /* X * Pretty print an Internet address (net address + port). X * If the nflag was specified, use numbers instead of names. X */ inetprint(in, port, proto) X register struct in_addr *in; X u_short port; X char *proto; { X struct servent *sp = 0; X char line[80], *cp, *index(); X int width; X X sprintf(line, "%.*s.", 16, inetname(*in)); X cp = index(line, '\0'); X if (!nflag && port) X sp = getservbyport((int)port, proto); X if (sp || port == 0) X sprintf(cp, "%.8s", sp ? sp->s_name : "*"); X else X sprintf(cp, "%d", ntohs((u_short)port)); X width = 22; X printf(" %-*.*s", width, width, line); } X /* X * Construct an Internet address representation. X * If the nflag has been supplied, give X * numeric value, otherwise try for symbolic name. X */ char * inetname(in) X struct in_addr in; { X register char *cp; X static char line[50]; X struct hostent *hp; X struct netent *np; X static char domain[MAXHOSTNAMELEN + 1]; X static int first = 1; X X if (first && !nflag) { X first = 0; X if (gethostname(domain, MAXHOSTNAMELEN) == 0 && X (cp = index(domain, '.'))) X (void) strcpy(domain, cp + 1); X else X domain[0] = 0; X } X cp = 0; X if (!nflag && in.s_addr != INADDR_ANY) { X u_long net = inet_netof(in); X u_long lna = inet_lnaof(in); X X if (lna == INADDR_ANY) { X np = getnetbyaddr(net, AF_INET); X if (np) X cp = np->n_name; X } X if (cp == 0) { X hp = gethostbyaddr((char *)&in, sizeof (in), AF_INET); X if (hp) { X if ((cp = index(hp->h_name, '.')) && X !strcmp(cp + 1, domain)) X *cp = 0; X cp = hp->h_name; X } X } X } X if (in.s_addr == INADDR_ANY) X strcpy(line, "*"); X else if (cp) X strcpy(line, cp); X else { X in.s_addr = ntohl(in.s_addr); #define C(x) ((x) & 0xff) X sprintf(line, "%u.%u.%u.%u", C(in.s_addr >> 24), X C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr)); X } X return (line); } SHAR_EOF $shar_touch -am 1015123593 'snmp2/apps/snmpnetstat/inet.c' && chmod 0644 'snmp2/apps/snmpnetstat/inet.c' || echo 'restore of snmp2/apps/snmpnetstat/inet.c failed' shar_count="`wc -c < 'snmp2/apps/snmpnetstat/inet.c'`" test 14211 -eq "$shar_count" || echo "snmp2/apps/snmpnetstat/inet.c: original size 14211, current size $shar_count" rm -f _sharnew.tmp fi # ============= snmp2/apps/snmpnetstat/main.c ============== if test -f 'snmp2/apps/snmpnetstat/main.c' && test X"$1" != X"-c"; then echo 'x - skipping snmp2/apps/snmpnetstat/main.c (file already exists)' rm -f _sharnew.tmp else > _sharnew.tmp echo 'x - extracting snmp2/apps/snmpnetstat/main.c (text)' sed 's/^X//' << 'SHAR_EOF' > 'snmp2/apps/snmpnetstat/main.c' && /****************************************************************** X Copyright 1989, 1991, 1992 by Carnegie Mellon University X X All Rights Reserved X Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of CMU not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. X CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ /* X * Copyright (c) 1983,1988 Regents of the University of California. X * All rights reserved. X * X * Redistribution and use in source and binary forms are permitted X * provided that this notice is preserved and that due credit is given X * to the University of California at Berkeley. The name of the University X * may not be used to endorse or promote products derived from this X * software without specific prior written permission. This software X * is provided ``as is'' without express or implied warranty. X */ X #ifndef lint char copyright[] = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ X All rights reserved.\n"; #endif not lint X #ifndef VXWORKS #include #endif /* VXWORKS */ X #ifndef VXWORKS #include #endif /* VXWORKS */ X #include X #ifdef VXWORKS #include #else /* VXWORKS */ #include #endif /* VXWORKS */ X #ifdef VXWORKS #include #else /* VXWORKS */ #include #endif /* VXWORKS */ X #include #include #include #include #include "asn1.h" #include "snmp.h" #include "snmp_api.h" #include "snmp_impl.h" #include "party.h" #include "context.h" #include "view.h" #include "acl.h" X /* internet protocols */ extern int protopr(); extern int tcp_stats(), udp_stats(), ip_stats(), icmp_stats(); X #define NULLPROTOX ((struct protox *) 0) struct protox { X u_char pr_wanted; /* 1 if wanted, 0 otherwise */ X int (*pr_cblocks)(); /* control blocks printing routine */ X int (*pr_stats)(); /* statistics printing routine */ X char *pr_name; /* well-known name */ } protox[] = { X { 1, protopr, tcp_stats, "tcp" }, X { 1, 0, udp_stats, "udp" }, X { 1, 0, ip_stats, "ip" }, X { 1, 0, icmp_stats, "icmp" }, X { 0, 0, 0, 0 } }; X int aflag; int iflag; int nflag; int pflag; int rflag; int sflag; int interval; char *interface; X int debug = 0; X X extern char *malloc(); X struct snmp_session *Session; int snmp_dump_packet = 0; int print_errors = 0; usage(){ X fprintf(stderr, "Usage: snmpnetstat -v 1 hostname community [ -ainrs ] [-p proto] [-I interface] [ interval ] or:\n"); X fprintf(stderr, "Usage: snmpnetstat [-v 2 ] hostname noAuth [ -ainrs ] [-p proto] [-I interface] [ interval ] or:\n"); X fprintf(stderr, "Usage: snmpnetstat [-v 2 ] hostname srcParty dstParty context [ -ainrs ] [-p proto] [-I interface] [ interval ]\n"); } X #ifdef VXWORKS snmpnetstat #else /* VXWORKS */ main #endif /* VXWORKS */ X (argc, argv) int argc; char *argv []; { X char *cp, *name; X char *hostname = NULL; X register struct protoent *p; X register struct protox *tp; /* for printing cblocks & stats */ X struct protox *name2protox(); /* for -p */ X char *community = NULL; X struct snmp_session session; X X int port_flag = 0; X int dest_port = 0; X int clock_flag = 0; X u_long srcclock, dstclock; X int version = 2; X struct partyEntry *pp; X struct contextEntry *cxp; X oid src[MAX_NAME_LEN], dst[MAX_NAME_LEN], context[MAX_NAME_LEN]; X int srclen = 0, dstlen = 0, contextlen = 0; X int trivialSNMPv2 = FALSE; X struct hostent *hp; X u_long destAddr; X int arg; X X init_mib(); X /* X * Usage: snmpnetstatwalk -v 1 hostname community ... or: X * Usage: snmpnetstat [-v 2 ] hostname noAuth ... or: X * Usage: snmpnetstat [-v 2 ] hostname srcParty dstParty context ... X */ X for(arg = 1; arg < argc; arg++){ X if (argv[arg][0] == '-'){ X switch(argv[arg][1]){ X case 'd': X snmp_dump_packet++; X break; X case 'p': X port_flag++; X dest_port = atoi(argv[++arg]); X break; X case 'c': X clock_flag++; X srcclock = atoi(argv[++arg]); X dstclock = atoi(argv[++arg]); X break; X case 'v': X version = atoi(argv[++arg]); X if (version < 1 || version > 2){ X fprintf(stderr, "Invalid version: %d\n", version); X usage(); X return(1); X } X break; X case 'a': X aflag++; X break; X X case 'i': X iflag++; X break; X X case 'n': X nflag++; X break; X X case 'r': X rflag++; X break; X X case 's': X sflag++; X break; X X case 'P': X argv++; X argc--; X if (argc == 0){ X usage(); X return(1); X } X if ((tp = name2protox(*argv)) == NULLPROTOX) { X fprintf(stderr, "%s: unknown or uninstrumented protocol\n", X *argv); X return(10); X } X pflag++; X break; X X case 'I': X iflag++; X if (*(interface = cp + 1) == 0) { X if ((interface = argv[1]) == 0) X break; X argv++; X argc--; X } X for (cp = interface; *cp; cp++) X ; X cp--; X break; X X default: X printf("invalid option: -%c\n", argv[arg][1]); X break; X } X continue; X } X if (hostname == NULL){ X hostname = argv[arg]; X } else if (version == 1 && community == NULL){ X community = argv[arg]; X } else if (version == 2 && srclen == 0 && !trivialSNMPv2){ X if (read_party_database("/etc/party.conf") > 0){ X fprintf(stderr, X "Couldn't read party database from /etc/party.conf\n"); X return(0); X } X if (read_context_database("/etc/context.conf") > 0){ X fprintf(stderr, X "Couldn't read context database from /etc/context.conf\n"); X return(0); X } X if (read_acl_database("/etc/acl.conf") > 0){ X fprintf(stderr, X "Couldn't read access control database from /etc/acl.conf\n"); X return(0); X } X X if (!strcasecmp(argv[arg], "noauth")){ X trivialSNMPv2 = TRUE; X } else { X party_scanInit(); X for(pp = party_scanNext(); pp; pp = party_scanNext()){ X if (!strcasecmp(pp->partyName, argv[arg])){ X srclen = pp->partyIdentityLen; X bcopy(pp->partyIdentity, src, srclen * sizeof(oid)); X break; X } X } X if (!pp){ X srclen = MAX_NAME_LEN; X if (!read_objid(argv[arg], src, &srclen)){ X printf("Invalid source party: %s\n", argv[arg]); X srclen = 0; X usage(); X return(1); X } X } X } X } else if (version == 2 && dstlen == 0 && !trivialSNMPv2){ X dstlen = MAX_NAME_LEN; X party_scanInit(); X for(pp = party_scanNext(); pp; pp = party_scanNext()){ X if (!strcasecmp(pp->partyName, argv[arg])){ X dstlen = pp->partyIdentityLen; X bcopy(pp->partyIdentity, dst, dstlen * sizeof(oid)); X break; X } X } X if (!pp){ X if (!read_objid(argv[arg], dst, &dstlen)){ X printf("Invalid destination party: %s\n", argv[arg]); X dstlen = 0; X usage(); X return(1); X } X } X } else if (version == 2 && contextlen == 0 && !trivialSNMPv2){ X contextlen = MAX_NAME_LEN; X context_scanInit(); X for(cxp = context_scanNext(); cxp; cxp = context_scanNext()){ X if (!strcasecmp(cxp->contextName, argv[arg])){ X contextlen = cxp->contextIdentityLen; X bcopy(cxp->contextIdentity, context, X contextlen * sizeof(oid)); X break; X } X } X if (!cxp){ X if (!read_objid(argv[arg], context, &contextlen)){ X printf("Invalid context: %s\n", argv[arg]); X contextlen = 0; X usage(); X return(1); X } X } X } else if (isdigit(argv[0][0])) { X interval = atoi(argv[0]); X if (interval <= 0){ X usage(); X return(1); X } X iflag++; X } else { X usage(); X return(1); X } X } X X if (!hostname || (version < 1) || (version > 2) X || (version == 1 && !community) X || (version == 2 && (!srclen || !dstlen || !contextlen) X && !trivialSNMPv2)){ X usage(); X return(1); X } X X if (trivialSNMPv2){ X if ((destAddr = inet_addr(hostname)) == -1){ X hp = gethostbyname(hostname); X if (hp == NULL){ X fprintf(stderr, "unknown host: %s\n", hostname); X return(1); X } else { X bcopy((char *)hp->h_addr, (char *)&destAddr, X hp->h_length); X } X } X srclen = dstlen = contextlen = MAX_NAME_LEN; X ms_party_init(destAddr, src, &srclen, dst, &dstlen, X context, &contextlen); X } X X if (clock_flag){ X pp = party_getEntry(src, srclen); X if (pp){ X pp->partyAuthClock = srcclock; X gettimeofday(&pp->tv, (struct timezone *)0); X pp->tv.tv_sec -= pp->partyAuthClock; X } X pp = party_getEntry(dst, dstlen); X if (pp){ X pp->partyAuthClock = dstclock; X gettimeofday(&pp->tv, (struct timezone *)0); X pp->tv.tv_sec -= pp->partyAuthClock; X } X } X X X bzero((char *)&session, sizeof(struct snmp_session)); X session.peername = hostname; X if (port_flag) X session.remote_port = dest_port; X if (version == 1){ X session.version = SNMP_VERSION_1; X session.community = (u_char *)community; X session.community_len = strlen((char *)community); X } else if (version == 2){ X session.version = SNMP_VERSION_2; X session.srcParty = src; X session.srcPartyLen = srclen; X session.dstParty = dst; X session.dstPartyLen = dstlen; X session.context = context; X session.contextLen = contextlen; X } X X session.retries = SNMP_DEFAULT_RETRIES; X session.timeout = SNMP_DEFAULT_TIMEOUT; X session.authenticator = NULL; X snmp_synch_setup(&session); SHAR_EOF : || echo 'restore of snmp2/apps/snmpnetstat/main.c failed' fi echo 'End of snmp2 part 9' echo 'File snmp2/apps/snmpnetstat/main.c is continued in part 10' echo 10 > _sharseq.tmp exit 0