/* snmpi.c - really minimal SNMP initiator */
static char *rcsid
= "$Header: /f/osi/snmp/RCS/snmpi.c,v 7.28 91/03/09 11:57:50 mrose Exp $";
* $Header: /f/osi/snmp/RCS/snmpi.c,v 7.28 91/03/09 11:57:50 mrose Exp $
* Contributed by NYSERNet Inc. This work was partially supported by the
* U.S. Defense Advanced Research Projects Agency and the Rome Air Development
* Center of the U.S. Air Force Systems Command under contract number
* Revision 7.28 91/03/09 11:57:50 mrose
* Revision 7.27 91/02/22 09:44:34 mrose
* Revision 7.26 91/01/11 15:35:28 mrose
* Revision 7.25 91/01/07 12:41:08 mrose
* Revision 7.24 90/10/23 20:37:09 mrose
* Revision 7.23 90/09/26 19:23:02 mrose
* Revision 7.22 90/09/26 18:47:18 mrose
* Revision 7.21 90/09/26 14:57:48 mrose
* Revision 7.20 90/09/07 11:11:39 mrose
* Revision 7.19 90/09/03 12:58:04 mrose
* Revision 7.18 90/08/30 15:11:11 mrose
* Revision 7.17 90/08/30 01:32:05 mrose
* Revision 7.16 90/08/20 21:25:52 mrose
* Revision 7.15 90/08/16 17:01:13 mrose
* Revision 7.14 90/08/08 14:01:31 mrose
* Revision 7.13 90/07/09 14:49:34 mrose
* Revision 7.12 90/06/23 18:25:14 mrose
* Revision 7.11 90/06/23 17:01:55 mrose
* Revision 7.10 90/05/12 17:02:09 mrose
* Revision 7.9 90/02/23 17:47:59 mrose
* Revision 7.8 90/02/19 19:17:05 mrose
* Revision 7.7 90/01/27 08:22:04 mrose
* Revision 7.6 90/01/11 18:34:43 mrose
* Revision 7.5 89/12/19 17:57:56 mrose
* Revision 7.4 89/12/19 16:18:26 mrose
* Revision 7.3 89/12/12 16:13:47 mrose
* Revision 7.2 89/12/11 16:22:33 mrose
* Revision 7.1 89/12/01 10:42:18 mrose
* Revision 7.0 89/11/23 22:23:30 mrose
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
#if !defined(CLTS) && !defined(COTS)
static char *myname
= "snmp";
static char **op
= NULLVP
;
static char *defs
= NULLCP
;
static char *community
= "public";
static struct TSAPaddr snmp_ta
;
struct type_SNMP_Message
*new_message ();
void adios (), advise ();
char *ds_name
; /* command name */
IFP ds_fnx
; /* dispatch */
char *ds_help
; /* help string */
struct dispatch
*getds ();
int f_compile (), f_dump ();
int f_get (), f_get_next (), f_set ();
int f_help (), f_quit (), f_status ();
static struct dispatch dispatches
[] = {
"audit", f_audit
, "audit traps",
"bulk", f_bulk
, "bulk retrieve colums from a table",
"compile", f_compile
, "write compiled objects file",
"dump", f_dump
, "dump a portion of the MIB",
"get", f_get
, "perform get operation",
"help", f_help
, "print help information",
"next", f_get_next
, "perform powerful get-next operation",
"quit", f_quit
, "terminate program",
"set", f_set
, "perform set operation",
"status", f_status
, "report status",
if (snmploop (vec
, NOTOK
) == NOTOK
)
istat
= signal (SIGINT
, intrser
);
for (interrupted
= 0;; interrupted
= 0) {
if (getline ("%s> ", buffer
) == NOTOK
) {
bzero ((char *) vec
, sizeof vec
);
if ((vecp
= str2vec (buffer
, vec
)) < 1)
switch (snmploop (vec
, OK
)) {
(void) signal (SIGINT
, istat
);
if (snmp_ta
.ta_addrs
-> na_stack
!= NA_TCP
) {
struct TSAPdisconnect tds
;
if (snmp_ta
.ta_addrs
-> na_stack
!= NA_NSAP
)
(void) TDiscRequest (sd
, NULLCP
, 0, &tds
);
exit (status
); /* NOTREACHED */
static int snmploop (vec
, error
)
register struct dispatch
*ds
;
if ((ds
= getds (strcmp (*vec
, "?") ? *vec
: "help")) == NULL
)
switch ((*ds
-> ds_fnx
) (vec
)) {
static struct dispatch
*getds (name
)
register struct dispatch
*ds
,
for (ds
= dispatches
; p
= ds
-> ds_name
; ds
++) {
for (q
= name
; *q
== *p
++; q
++)
if (q
- name
> longest
) {
advise (NULLCP
, "unknown operation \"%s\"", name
);
for (ds
= dispatches
, p
= buffer
; q
= ds
-> ds_name
; ds
++)
if (strncmp (q
, name
, longest
) == 0) {
(void) sprintf (p
, "%s \"%s\"", p
!= buffer
? "," : "", q
);
advise (NULLCP
, "ambiguous operation, it could be one of:%s",
struct type_SNMP_Audit
*au
;
if (*++vec
!= NULL
&& strcmp (*vec
, "-help") == 0) {
printf ("audit [-f | -N | +N] [file]\n");
printf (" audit trap sink\n");
printf (" -f: endless loop\n");
printf (" -N: last N traps\n");
printf (" +N: first N traps\n");
printf (" file: trap file (default %s)\n", file
);
if (strcmp (cp
, "-f") == 0)
follow
= -atoi (++cp
), forever
= 0;
follow
= atoi (++cp
), forever
= 0;
file
= _isodefile (isodelogpath
, file
);
if ((fp
= fopen (file
, "r")) == NULL
) {
advise (file
, "unable to read");
pe
= p
= NULLPE
, au
= NULL
;
if ((ps2
= ps_alloc (std_open
)) == NULLPS
) {
advise (NULLCP
, "ps_alloc(std_open): you lose");
if (std_setup (ps2
, fp
) == NOTOK
) {
advise (NULLCP
, "std_setup: %s", ps_error (ps2
-> ps_errno
));
longtimeago
= now
- 6L * 30L * 24L * 60L * 60L;
if ((opp
= (long *) calloc ((unsigned) follow
, sizeof *opp
)) == NULL
)
adios (NULLCP
, "out of memory");
for (ep
= (lp
= opp
) + follow
; lp
< ep
; lp
++)
if ((pe
= ps2pe (ps2
)) == NULLPE
)
if (decode_SNMP_Audit (pe
, 1, NULLIP
, NULLVP
, &au
) == NOTOK
)
fseek (fp
, (long) au
-> sizeOfEncodingWhichFollows
, 1);
if (follow
> 0 && i
> follow
)
if ((pe
= ps2pe (ps2
)) == NULLPE
) {
advise (NULLCP
, "ps2pe: %s", ps_error (ps2
-> ps_errno
));
ps2
-> ps_errno
= PS_ERR_NONE
;
if (decode_SNMP_Audit (pe
, 1, NULLIP
, NULLVP
, &au
) == NOTOK
) {
advise (NULLCP
, "decode_SNMP_Audit: %s", PY_pepy
);
if ((cp
= qb2str (au
-> dateAndTime
)) == NULL
) {
advise (NULLCP
, "qb2str: out of memory");
ut
= str2gent (cp
, strlen (cp
));
advise (NULLCP
, "str2gent: you lose");
mtime
= gtime (ut2tm (ut
));
if (mtime
< longtimeago
|| mtime
> now
)
printf ("%-7.7s %-4.4s ", cp
+ 4, cp
+ 20);
printf ("%-12.12s ", cp
+ 4);
if ((cp
= qb2str (au
-> source
)) == NULL
)
if ((p
= ps2pe (ps2
)) == NULLPE
) {
advise (NULLCP
, "ps2pe: %s", ps_error (ps2
-> ps_errno
));
if (print_SNMP_Message (p
, 1, NULLIP
, NULLVP
, NULLCP
) == NOTOK
)
free_SNMP_Audit (au
), au
= NULL
;
register struct type_SNMP_VarBindList
**vp
;
struct type_SNMP_VarBindList
*vb
;
if (*++vec
!= NULL
&& strcmp (*vec
, "-help") == 0) {
printf ("bulk [-alg1 | -alg2] columns...\n");
printf (" with arguments, bulk retrieves columns from a table\n");
if (strcmp (*vec
, "-alg1") == 0) {
if (strcmp (*vec
, "-alg2") == 0) {
if (snmp_ta
.ta_addrs
-> na_stack
!= NA_TCP
) {
if (snmp_ta
.ta_addrs
-> na_stack
!= NA_NSAP
) {
advise (NULLCP
, "bulk requires CL-mode transport!");
for (result
= NOTOK
; *vec
; vec
++) {
register struct type_SNMP_VarBindList
*bind
;
register struct type_SNMP_VarBind
*v
;
if ((ot
= text2obj (*vec
)) == NULL
) {
advise (NULLCP
, "unknown object \"%s\"", *vec
);
register OID eid
= et
-> ot_name
,
if (eid
-> oid_nelem
!= oid
-> oid_nelem
- 1
|| bcmp ((char *) eid
-> oid_elements
,
(char *) oid
-> oid_elements
,
* sizeof (eid
-> oid_elements
[0])) != 0) {
advise (NULLCP
, "%s not in same table as previous arguments",
ot
-> ot_name
-> oid_nelem
--;
et
= name2obj (ot
-> ot_name
);
ot
-> ot_name
-> oid_nelem
++;
advise (NULLCP
, "unable to find row object for %s",
/* || (i = strlen (et -> ot_text)) <= 5
|| strcmp (et -> ot_text + i - 5, "Entry")*/) {
advise (NULLCP
, "%s is not a column object", ot
-> ot_text
);
if ((bind
= (struct type_SNMP_VarBindList
*) calloc (1, sizeof *bind
))
adios (NULLCP
, "out of memory");
*vp
= bind
, vp
= &bind
-> next
;
if ((v
= (struct type_SNMP_VarBind
*) calloc (1, sizeof *v
)) == NULL
)
adios (NULLCP
, "out of memory");
if ((v
-> name
= oid_cpy (ot
-> ot_name
)) == NULLOID
|| (v
-> value
= pe_alloc (PE_CLASS_UNIV
, PE_FORM_PRIM
,
PE_PRIM_NULL
)) == NULLPE
)
adios (NULLCP
, "out of memory");
(*fnx
) (ps
, sd
, vb
, community
);
free_SNMP_VarBindList (vb
);
static char *access_t
[] = { "not-accessible",
static char *status_t
[] = { "obsolete",
static int f_compile (vec
)
file
= defs
? defs
: "./objects.defs";
if (*++vec
!= NULL
&& strcmp (*vec
, "-help") == 0) {
printf ("compile [-f] [file]\n");
printf (" -f: brief output (default to stdout)\n");
printf (" file: output file (default %s)\n", file
);
if (strcmp (cp
, "-f") == 0) {
if ((fp
= fopen (file
, "w")) == NULL
) {
advise (file
, "unable to write");
for (ot
= text2obj ("ccitt"); ot
; ot
= ot
-> ot_next
) {
j
+= strlen (ot
-> ot_text
)
+ strlen (sprintoid (ot
-> ot_name
));
k
+= ot
-> ot_name
-> oid_nelem
;
fprintf (fp
, "--* compiled %d %d %d\n", i
, j
, k
);
for (ot
= text2obj ("ccitt"); ot
; ot
= ot
-> ot_next
) {
fprintf (fp
, "%s=%s\n", ot
-> ot_text
, sprintoid (ot
-> ot_name
));
fprintf (fp
, "%-20s %-20s", ot
-> ot_text
, sprintoid (ot
-> ot_name
));
if ((os
= ot
-> ot_syntax
) || ot
-> ot_status
)
fprintf (fp
, " %-15s %-15s %s",
os
? os
-> os_name
: "Aggregate",
access_t
[ot
-> ot_access
& OT_RDWRITE
],
status_t
[ot
-> ot_status
& OT_DEPRECATED
]);
advise (NULLCP
, "%d objects written to %s", i
, file
);
struct type_SNMP_Message
*msg
;
register struct type_SNMP_PDU
*parm
;
register struct type_SNMP_VarBindList
*vp
;
if (*++vec
!= NULL
&& strcmp (*vec
, "-help") == 0) {
printf ("dump [object]\n");
printf (" with no arguments, dump entire MIB\n");
printf (" with an argument, dump a portion of the MIB\n");
if (*vec
&& strcmp (*vec
, "-time") == 0) {
(void) gettimeofday (&tvs
, (struct timezone
*) 0);
nvec
[1] = *vec
? *vec
: "0.0";
if ((msg
= new_message (type_SNMP_PDUs_get__next__request
, nvec
)) == NULL
)
request_id
= msg
-> data
-> un
.get__response
-> request__id
= 0;
if ((oid
= oid_cpy (msg
-> data
-> un
.get__next__request
->
variable__bindings
-> VarBind
-> name
)) == NULLOID
)
adios (NULLCP
, "out of memory");
if (encode_SNMP_Message (&pe
, 1, 0, NULLCP
, msg
) != NOTOK
) {
(void) print_SNMP_Message (pe
, 1, NULLIP
, NULLVP
, NULLCP
);
if (pe2ps (ps
, pe
) == NOTOK
) {
advise (NULLCP
, "pe2ps: %s", ps_error (ps
-> ps_errno
));
advise (NULLCP
, "encode_SNMP_Message: %s", PY_pepy
);
if ((pe
= ps2pe (ps
)) == NULLPE
) {
advise (NULLCP
, "ps2pe: %s", ps_error (ps
-> ps_errno
));
if (decode_SNMP_Message (pe
, 1, NULLIP
, NULLVP
, &msg
) == NOTOK
) {
advise (NULLCP
, "decode_SNMP_Message: %s", PY_pepy
);
(void) print_SNMP_Message (pe
, 1, NULLIP
, NULLVP
, NULLCP
);
if (msg
-> data
-> offset
!= type_SNMP_PDUs_get__response
) {
advise (NULLCP
, "unexpected message type %d",
if ((parm
= msg
-> data
-> un
.get__response
) -> request__id
fprintf (stderr
, "request-id mismatch (got %d, wanted %d)\n",
parm
-> request__id
, request_id
);
if (parm
-> error__status
!= int_SNMP_error__status_noError
) {
if (parm
-> error__status
!= int_SNMP_error__status_noSuchName
)
fprintf (stderr
, "%s at position %d\n",
snmp_error (parm
-> error__status
), parm
-> error__index
);
for (vp
= parm
-> variable__bindings
; vp
; vp
= vp
-> next
) {
register struct type_SNMP_VarBind
*v
= vp
-> VarBind
;
&& (oid
-> oid_nelem
> v
-> name
-> oid_nelem
|| bcmp ((char *) oid
-> oid_elements
,
(char *) v
-> name
-> oid_elements
,
* sizeof oid
-> oid_elements
[0])))
printf ("%s=", oid2ode (vp
-> VarBind
-> name
));
if ((oi
= name2inst (v
-> name
)) == NULL
|| (os
= oi
-> oi_type
-> ot_syntax
) == NULL
|| (*os
-> os_decode
) (&value
, v
-> value
) == NOTOK
)
(*os
-> os_print
) (value
, os
);
(*os
-> os_free
) (value
);
msg
-> data
-> offset
= type_SNMP_PDUs_get__next__request
;
request_id
= ++parm
-> request__id
;
(void) gettimeofday (&now
, (struct timezone
*) 0);
now
.tv_sec
-= tvs
.tv_sec
;
if ((now
.tv_usec
-= tvs
.tv_usec
) < 0)
now
.tv_sec
--, now
.tv_usec
+= 1000000;
"%d entr%s retrieved in %d.%06d seconds",
rows
, rows
!= 1 ? "ies" : "y", now
.tv_sec
, now
.tv_usec
);
(void) process (new_message (type_SNMP_PDUs_get__request
, vec
));
static int f_get_next (vec
)
(void) process (new_message (type_SNMP_PDUs_get__next__request
, vec
));
(void) process (new_message (type_SNMP_PDUs_set__request
, vec
));
static char *errors
[] = {
"noError", "tooBig", "noSuchName", "badValue", "readOnly", "genErr"
static char buffer
[BUFSIZ
];
if (0 < i
&& i
< sizeof errors
/ sizeof errors
[0])
(void) sprintf (buffer
, "error %d", i
);
static struct type_SNMP_Message
*new_message (offset
, vec
)
register struct type_SNMP_Message
*msg
;
register struct type_SNMP_PDUs
*pdu
;
register struct type_SNMP_PDU
*parm
;
register struct type_SNMP_VarBindList
**vp
;
if ((msg
= (struct type_SNMP_Message
*) calloc (1, sizeof *msg
)) == NULL
)
adios (NULLCP
, "out of memory");
msg
-> version
= int_SNMP_version_version__1
;
if ((msg
-> community
= str2qb (community
, strlen (community
), 1)) == NULL
)
adios (NULLCP
, "out of memory");
if ((pdu
= (struct type_SNMP_PDUs
*) calloc (1, sizeof *pdu
)) == NULL
)
adios (NULLCP
, "out of memory");
/* for now, always a PDU... */
if ((parm
= (struct type_SNMP_PDU
*) calloc (1, sizeof *parm
)) == NULL
)
adios (NULLCP
, "out of memory");
pdu
-> un
.get__request
= parm
;
parm
-> request__id
= ((int) random ()) & 0x7fffffff;
parm
-> request__id
= ((int) rand ()) & 0x7fffffff;
vp
= &parm
-> variable__bindings
;
for (vec
++; *vec
; vec
++) {
register struct type_SNMP_VarBindList
*bind
;
register struct type_SNMP_VarBind
*v
;
if ((bind
= (struct type_SNMP_VarBindList
*) calloc (1, sizeof *bind
))
adios (NULLCP
, "out of memory");
*vp
= bind
, vp
= &bind
-> next
;
if ((v
= (struct type_SNMP_VarBind
*) calloc (1, sizeof *v
)) == NULL
)
adios (NULLCP
, "out of memory");
if (get_ava (v
, *vec
, offset
) == NOTOK
) {
static int get_ava (v
, ava
, offset
)
register struct type_SNMP_VarBind
*v
;
if (cp
= index (ava
, '=')) {
if (offset
!= type_SNMP_PDUs_set__request
)
advise (NULLCP
, "value unnecessary for get operation");
if (offset
== type_SNMP_PDUs_set__request
) {
advise (NULLCP
, "need variable=value for set operation");
if ((oi
= text2inst (ava
)) == NULL
) {
if (cp
|| (oid
= text2oid (ava
)) == NULL
) {
advise (NULLCP
, "unknown variable \"%s\"", ava
);
if ((v
-> name
= oid_cpy (oi
? oi
-> oi_name
: oid
)) == NULLOID
)
adios (NULLCP
, "out of memory");
if ((v
-> value
= pe_alloc (PE_CLASS_UNIV
, PE_FORM_PRIM
, PE_PRIM_NULL
))
adios (NULLCP
, "out of memory");
if ((os
= ot
-> ot_syntax
) == NULL
) {
advise (NULLCP
, "no syntax defined for object \"%s\"", ava
);
if ((*os
-> os_parse
) (&value
, cp
) == NOTOK
) {
advise (NULLCP
, "invalid value for variable \"%s\": \"%s\"",
result
= (*os
-> os_encode
) (value
, &v
-> value
);
(*os
-> os_free
) (value
);
advise (NULLCP
, "encoding error for variable \"%s\"", ava
);
struct type_SNMP_Message
*msg
;
register struct type_SNMP_PDU
*parm
;
register struct type_SNMP_VarBindList
*vp
;
request_id
= msg
-> data
-> un
.get__request
-> request__id
;
if (encode_SNMP_Message (&pe
, 1, 0, NULLCP
, msg
) != NOTOK
) {
(void) print_SNMP_Message (pe
, 1, NULLIP
, NULLVP
, NULLCP
);
if (pe2ps (ps
, pe
) == NOTOK
) {
advise (NULLCP
, "pe2ps: %s", ps_error (ps
-> ps_errno
));
advise (NULLCP
, "encode_SNMP_Message: %s", PY_pepy
);
if ((pe
= ps2pe (ps
)) == NULLPE
) {
advise (NULLCP
, "ps2pe: %s", ps_error (ps
-> ps_errno
));
if (decode_SNMP_Message (pe
, 1, NULLIP
, NULLVP
, &msg
) == NOTOK
) {
advise (NULLCP
, "decode_SNMP_Message: %s", PY_pepy
);
(void) print_SNMP_Message (pe
, 1, NULLIP
, NULLVP
, NULLCP
);
if (msg
-> data
-> offset
!= type_SNMP_PDUs_get__response
) {
advise (NULLCP
, "unexpected message type %d",
if ((parm
= msg
-> data
-> un
.get__response
) -> request__id
fprintf (stderr
, "request-id mismatch (got %d, wanted %d)\n",
parm
-> request__id
, request_id
);
if (parm
-> error__status
!= int_SNMP_error__status_noError
) {
fprintf (stderr
, "%s at position %d\n",
snmp_error (parm
-> error__status
), parm
-> error__index
);
for (vp
= parm
-> variable__bindings
; vp
; vp
= vp
-> next
) {
register struct type_SNMP_VarBind
*v
= vp
-> VarBind
;
if ((oi
= name2inst (v
-> name
)) == NULL
) {
advise (NULLCP
, "unknown variable \"%s\"", oid2ode (v
-> name
));
printf ("%s=", oid2ode (v
-> name
));
if ((os
= oi
-> oi_type
-> ot_syntax
) == NULL
) {
advise (NULLCP
, "unknown syntax for object \"%s\"",
oi
-> oi_type
-> ot_text
);
if ((*os
-> os_decode
) (&value
, v
-> value
) == NOTOK
) {
advise (NULLCP
, "decode error for variable \"%s\"",
printf ("%s=", oid2ode (v
-> name
));
(*os
-> os_print
) (value
, os
);
(*os
-> os_free
) (value
);
register struct dispatch
*ds
,
for (es
= dispatches
; es
-> ds_name
; es
++)
if ((columns
= ncols (stdout
) / (width
= (width
+ 8) & ~7)) == 0)
lines
= ((es
- dispatches
) + columns
- 1) / columns
;
printf ("Operations:\n");
for (i
= 0; i
< lines
; i
++)
for (j
= 0; j
< columns
; j
++) {
ds
= dispatches
+ j
* lines
+ i
;
printf ("%s", ds
-> ds_name
);
for (w
= strlen (ds
-> ds_name
); w
< width
; w
= (w
+ 8) & ~7)
if (strcmp (*vec
, "-help") == 0) {
printf ("help [commands ...]\n");
printf (" with no arguments, lists operations which may be invoked\n");
printf (" otherwise prints help for each operation given\n");
if (strcmp (*vec
, "?") == 0) {
for (ds
= dispatches
; ds
-> ds_name
; ds
++)
printf ("%-*s\t- %s\n", width
, ds
-> ds_name
, ds
-> ds_help
);
printf ("%-*s\t- %s\n", width
, ds
-> ds_name
, ds
-> ds_help
);
if (vec
&& *++vec
!= NULL
&& strcmp (*vec
, "-help") == 0) {
printf (" terminate fred\n");
static int f_status (vec
)
if (*++vec
!= NULL
&& strcmp (*vec
, "-help") == 0) {
printf (" report status\n");
printf ("Connected to %s using community \"%s\"\n",
taddr2str (&snmp_ta
), community
);
static char *ifType
[] = {
"other", "regular1822", "hdh1822", "ddn-x25", "rfc877-x25",
"ethernet-csmacd", "iso88023-csmacd", "iso88024-tokenBus",
"iso88025-tokenRing", "iso88026-man", "starLan", "proteon-10Mbit",
"proteon-80Mbit", "hyperchannel", "fddi", "lapb", "sdlc", "t1-carrier",
"cept", "basicISDN", "primaryISDN", "propPointToPointSerial",
"ppp", "softwareLoopback", "eon", "ethernet-3Mbit",
static char *ifStatus
[] = {
static char *ipForwarding
[] = {
static char *routeType
[] = {
"other", "invalid", "direct", "remote"
static char *ipRouteProto
[] = {
"other", "local", "netmgmt", "icmp", "egp", "ggp", "hello", "rip", "is-is",
"es-is", "ciscoIgrp", "bbnSpfIgp", "ospf", "bgp"
static char *netToMediaType
[] = {
"other", "invalid", "dynamic", "static"
static char *tcpRtoAlgorithm
[] = {
"other", "constant", "rsre", "vanj"
static char *tcpConnState
[] = {
"closed", "listen", "synSent", "synReceived", "established", "finWait1",
"finWait2", "closeWait", "lastAck", "closing", "timewait"
static char *egpNeighState
[] = {
"idle", "acquisition", "down", "up", "cease"
static char *egpNeighMode
[] = {
static char *egpNeighEventTrigger
[] = {
static char *enabled
[] = {
static char *status
[] = {
static char *smuxPstatus
[] = {
"valid", "invalid", "connecting"
sizeof ifType
/ sizeof ifType
[0],
"ifAdminStatus", ifStatus
,
sizeof ifStatus
/ sizeof ifStatus
[0],
"ifOperStatus", ifStatus
,
sizeof ifStatus
/ sizeof ifStatus
[0],
"ipForwarding", ipForwarding
,
sizeof ipForwarding
/ sizeof ipForwarding
[0],
"ipRouteType", routeType
,
sizeof routeType
/ sizeof routeType
[0],
"ipRouteProto", ipRouteProto
,
sizeof ipRouteProto
/ sizeof ipRouteProto
[0],
"ipNetToMediaType", netToMediaType
,
sizeof netToMediaType
/ sizeof netToMediaType
[0],
"tcpRtoAlgorithm", tcpRtoAlgorithm
,
sizeof tcpRtoAlgorithm
/ sizeof tcpRtoAlgorithm
[0],
"tcpConnState", tcpConnState
,
sizeof tcpConnState
/ sizeof tcpConnState
[0],
"egpNeighState", egpNeighState
,
sizeof egpNeighState
/ sizeof egpNeighState
[0],
"egpNeighMode", egpNeighMode
,
sizeof egpNeighMode
/ sizeof egpNeighMode
[0],
"egpNeighEventTrigger", egpNeighEventTrigger
,
sizeof egpNeighEventTrigger
/ sizeof egpNeighEventTrigger
[0],
"snmpEnableAuthenTraps", enabled
,
sizeof enabled
/ sizeof enabled
[0],
"smuxPstatus", smuxPstatus
,
sizeof smuxPstatus
/ sizeof smuxPstatus
[0],
sizeof status
/ sizeof status
[0],
sizeof enabled
/ sizeof enabled
[0],
static int enum_print (x
, os
)
if (i
<= 0 || i
> os
-> os_data2
)
printf ("unknown(%d)", i
);
printf ("%s(%d)", os
-> os_data1
[i
- 1], i
);
register struct ivar
*iv
;
for (iv
= ivars
; iv
-> iv_object
; iv
++)
if (ot
= text2obj (iv
-> iv_object
)) {
if ((os
= ot
-> ot_syntax
) == NULL
) {
advise (NULLCP
, "no syntax defined for object \"%s\"",
(void) add_syntax (iv
-> iv_object
, os
-> os_encode
,
os
-> os_decode
, os
-> os_free
, os
-> os_parse
,
if ((os
= text2syn (iv
-> iv_object
)) == NULL
)
adios (NULLCP
, "lost syntax for object \"%s\"",
os
-> os_data1
= iv
-> iv_values
;
os
-> os_data2
= iv
-> iv_nvalue
;
advise (NULLCP
, "no \"%s\" object", iv
-> iv_object
);
register struct dispatch
*ds
;
struct sockaddr_in in_socket
;
register struct sockaddr_in
*isock
= &in_socket
;
register struct hostent
*hp
;
register struct servent
*sp
;
register struct TSAPaddr
*ta
= &snmp_ta
,
register struct NSAPaddr
*na
= ta
-> ta_addrs
;
if (myname
= rindex (*vec
, '/'))
if (myname
== NULL
|| *myname
== NULL
)
if (ontty
= isatty (fileno (stdin
)))
if ((sp
= getservbyname ("snmp", "udp")) == NULL
)
advise (NULLCP
, "udp/snmp: unknown service");
bzero ((char *) ta
, sizeof *ta
);
na
-> na_community
= ts_comm_tcp_default
;
(void) strncpy (na
-> na_domain
, getlocalhost (),
sizeof na
-> na_domain
- 1);
na
-> na_port
= sp
? sp
-> s_port
: htons ((u_short
) 161);
na
-> na_tset
= NA_TSET_UDP
;
for (vec
++; ap
= *vec
; vec
++) {
case 'a': /* e.g., NS+0504030201 */
if ((pp
= *++vec
) == NULL
|| *pp
== '-')
adios (NULLCP
, "usage: %s -a agent", myname
);
if (hp
= gethostbystring (pp
)) {
if (na
-> na_stack
!= NA_TCP
)
adios (NULLCP
, "use -a at most once...");
(void) strncpy (na
-> na_domain
,
inet_ntoa (isock
-> sin_addr
),
sizeof na
-> na_domain
- 1);
if ((tz
= str2taddr (pp
)) && tz
-> ta_naddr
> 0) {
*ta
= *tz
; /* struct copy */
if (na
-> na_stack
== NA_TCP
) {
na
-> na_port
= sp
? sp
-> s_port
na
-> na_tset
= NA_TSET_UDP
;
adios (NULLCP
, "%s: unknown host", pp
);
if ((pp
= *++vec
) == NULL
|| (port
= atoi (pp
)) <= 0)
adios (NULLCP
, "usage: %s -p portno", myname
);
if (na
-> na_stack
!= NA_TCP
)
adios (NULLCP
, "-p not allowed with %s",
na
-> na_port
= htons ((u_short
) port
);
if ((pp
= *++vec
) == NULL
|| *pp
== '-')
adios (NULLCP
, "usage: %s -c community", myname
);
if ((pp
= *++vec
) == NULL
|| *pp
== '-')
adios (NULLCP
, "usage: %s -f file", myname
);
adios (NULLCP
, "unknown switch -%c", *ap
);
for (ds
= dispatches
; ds
-> ds_name
; ds
++)
if ((w
= strlen (ds
-> ds_name
)) > helpwidth
)
adios (NULLCP
, "usage: %s -a string", myname
);
switch (na
-> na_stack
) {
struct sockaddr_in lo_socket
;
register struct sockaddr_in
*lsock
= &lo_socket
;
bzero ((char *) lsock
, sizeof *lsock
);
if ((hp
= gethostbystring (pp
= getlocalhost ())) == NULL
)
adios (NULLCP
, "%s: unknown host", pp
);
lsock
-> sin_family
= hp
-> h_addrtype
;
/* If the request is being sent out on the loopback interface,
make sure it appears to have originated from the loopback
interface, rather than the interface used as the default
hostname. If the interface used as the default hostname
is a serial link, responses to requests with this origin
may be undeliverable. (EJP) */
#define LOOPBACK ((127 << 24) + 1)
if (isock
-> sin_addr
.s_addr
== LOOPBACK
)
lsock
-> sin_addr
.s_addr
= LOOPBACK
;
if ((sd
= start_udp_client (lsock
, 0, 0, 0)) == NOTOK
)
adios ("failed", "start_udp_client");
bzero ((char *) isock
, sizeof *isock
);
if ((hp
= gethostbystring (na
-> na_domain
)) == NULL
)
adios (NULLCP
, "%s: unknown host", na
-> na_domain
);
isock
-> sin_family
= hp
-> h_addrtype
;
isock
-> sin_port
= na
-> na_port
;
if (join_udp_server (sd
, isock
) == NOTOK
)
adios ("failed", "join_udp_server");
if ((ps
= ps_alloc (dg_open
)) == NULLPS
|| dg_setup (ps
, sd
, MAXDGRAM
, read_udp_socket
,
write_udp_socket
, check_udp_socket
)
adios (NULLCP
, "ps_alloc: out of memory");
adios (NULLCP
, "dg_setup: %s",
ps_error (ps
-> ps_errno
));
adios (NULLCP
, "UDP support not configured");
adios (NULLCP
, "X.25 support not configured");
union sockaddr_osi lo_socket
;
register union sockaddr_osi
*lsock
= &lo_socket
;
bzero ((char *) lsock
, sizeof *lsock
);
if ((sd
= start_clts_client (lsock
, 0, 0, 0)) == NOTOK
)
adios ("failed", "start_clts_client");
(void) gen2tp4 (ta
, lsock
);
if (join_clts_server (sd
, lsock
) == NOTOK
)
adios ("failed", "join_udp_server");
if ((ps
= ps_alloc (dg_open
)) == NULLPS
|| dg_setup (ps
, sd
, MAXDGRAM
, read_clts_socket
,
write_clts_socket
, check_clts_socket
)
adios (NULLCP
, "ps_alloc: out of memory");
adios (NULLCP
, "dg_setup: %s",
ps_error (ps
-> ps_errno
));
adios (NULLCP
, "TP4 support not configured");
adios (NULLCP
, "unknown network type 0x%x", na
-> na_stack
);
register struct TSAPconnect
*tc
= &tcs
;
struct TSAPdisconnect tds
;
register struct TSAPdisconnect
*td
= &tds
;
fprintf (stderr
, "%s... ", taddr2str (ta
));
if (TConnRequest (NULLTA
, ta
, 0, NULLCP
, 0, NULLQOS
, tc
, td
)
fprintf (stderr
," failed\n");
adios (NULLCP
, td
-> td_cc
> 0
? "T-CONNECT.REQUEST: [%s] %*.*s"
: "T-CONNECT.REQUEST: [%s]",
TErrString (td
-> td_reason
),
td
-> td_cc
, td
-> td_cc
, td
-> td_data
);
fprintf (stderr
, "connected\n");
if ((ps
= ps_alloc (dg_open
)) == NULLPS
|| dg_setup (ps
, sd
= tc
-> tc_sd
, MAXDGRAM
, ts_read
,
ts_write
, NULLIFP
) == NOTOK
) {
adios (NULLCP
, "ps_alloc: out of memory");
adios (NULLCP
, "dg_setup: %s",
ps_error (ps
-> ps_errno
));
(void) srand ((unsigned int) time ((long *) 0));
(void) srandom ((int) time ((long *) 0));
ps_len_strategy
= PS_LEN_LONG
;
if (readobjects (defs
) == NOTOK
)
adios (NULLCP
, "readobjects: %s", PY_pepy
);
static int getline (prompt
, buffer
)
switch (setjmp (intrenv
)) {
printf ("\n"); /* and fall */
for (ep
= (cp
= buffer
) + BUFSIZ
- 1; (i
= getchar ()) != '\n';) {
(void) signal (SIGINT
, intrser
);
longjmp (intrenv
, NOTOK
);
if (ioctl (fileno (fp
), TIOCGWINSZ
, (char *) &ws
) != NOTOK
fprintf (stderr
, "%s: ", myname
);
(void) fputs (buffer
, stderr
);
(void) fputc ('\n', stderr
);