Plan 9 from Bell Labs’s /usr/web/sources/contrib/rsc/snmp/snmpget.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 = 0;

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

char*
ct(ulong t)
{
	char *p;

	p = ctime(t);
	if(p[strlen(p)-1] == '\n')
		p[strlen(p)-1] = '\0';
	return p;
}

void
main(int argc, char **argv)
{
	int fd, i;
	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 = Pget;
	for(i=0; i<argc-1 && i<Mpdu; i++){
		strcpy(s.pdu[i].objid, argv[i+1]);
		s.pdu[i].type = Anull;
	}
	s.npdu = i;

	if(dosnmp(fd, &s, &r) < 0)
		sysfatal("snmp failed: %r");

	Sprint(&r);
	exits(nil);
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.