Plan 9 from Bell Labs’s /usr/web/sources/contrib/rsc/snmp/snmpwalk.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <ip.h>
#include "a1.h"

int chatty;

void
usage(void)
{
	fprint(2, "usage: snmpwalk host 1.3.6.1.2\n");
	exits("usage");
}

void
main(int argc, char **argv)
{
	int fd;
	Snmp s, r;

	fmtinstall('I', eipfmt);
	ARGBEGIN {
	case 'D':
		chatty++;
		break;
	default:
		usage();
	} ARGEND;

	if(argc < 2)
		usage();

	if((fd = dial(netmkaddr(argv[0], "udp", "snmp"), 0, 0, 0)) < 0)
		sysfatal("dial: %s: %r", argv[0]);

	memset(&s, 0, sizeof s);
	memset(&r, 0, sizeof r);
	s.vers = 0;
	s.private = 0;
	s.type = Pgetn;
	strcpy(s.pdu[0].objid, argv[1]);
	s.pdu[0].type = Anull;
	s.npdu = 1;

	r.eindex = 0;
	while(r.eindex == 0) {
		if(dosnmp(fd, &s, &r) < 0)
			sysfatal("snmp failed: %r");
		if(strncmp(argv[1], r.pdu[0].objid, strlen(argv[1])) != 0)
			break;
		Sprint(&r);
		strcpy(s.pdu[0].objid, r.pdu[0].objid);
	}
	close(fd);

	exits(0);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].