All pastes #590067 Raw Edit

SNMPv2c request fails

public c v1 · immutable
#590067 ·published 2007-06-26 09:56 UTC
rendered paste body
#include <net-snmp/net-snmp-config.h>#include <net-snmp/net-snmp-includes.h>intmain (void){	struct snmp_session  session, *ss;	struct snmp_pdu     *pdu, *response;	oid    oids[MAX_OID_LEN][2];	size_t len = MAX_OID_LEN;	struct variable_list *vars;	int                   status;	init_snmp ("example");	snmp_sess_init (&session);	session.peername      = "127.0.0.1";	session.version       = SNMP_VERSION_2c;	session.community     = "public";	session.community_len = strlen (session.community);	if ((ss = snmp_open (&session)) == NULL)	{		snmp_perror ("snmp_open");		exit (1);	}	pdu = snmp_pdu_create (SNMP_MSG_GET);	read_objid ("DISMAN-EVENT-MIB::sysUpTimeInstance", oids[0], &len);	// Timeticks	snmp_add_null_var (pdu, oids[0], len);	read_objid ("HOST-RESOURCES-MIB::hrSystemProcesses.0", oids[1], &len);	// Gauge32	snmp_add_null_var (pdu, oids[1], len);	status = snmp_synch_response (ss, pdu, &response);	if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR)	{		for (vars = response->variables; vars; vars = vars->next_variable)			switch (vars->type)			{			case ASN_TIMETICKS:				printf ("Timeticks: %li\n", *(vars->val.integer));				break;			case ASN_GAUGE:				if (vars->val.counter64->high > vars->val.counter64->low)					printf ("Gauge32: %lu\n", vars->val.counter64->high);				else					printf ("Gauge32: %lu\n", vars->val.counter64->low);				break;			default:				printf ("Invalid type %i\n", vars->type);			}	}	else if (status == STAT_SUCCESS)		fprintf (stderr, "Error in packet: %s\n", snmp_errstring (response->errstat));	else		snmp_sess_perror ("snmp_synch_response", ss);	if (response)		snmp_free_pdu (response);	snmp_close (ss);	return 0;}