All pastes #587239 Raw Edit

example snmp app

public c v1 · immutable
#587239 ·published 2007-06-24 11:46 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    anOID[MAX_OID_LEN];	size_t anOID_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_1;	session.community     = "public";	session.community_len = strlen (session.community);	if ((ss = snmp_open (&session)) == NULL)	{		snmp_perror ("ack");		exit (1);	}	pdu = snmp_pdu_create (SNMP_MSG_GET);	read_objid (".1.3.6.1.4.1.2021.8.1.101.1", anOID, &anOID_len);	snmp_add_null_var (pdu, anOID, anOID_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)			if (vars->type == ASN_INTEGER)				printf ("int: %i\n", *(vars->val.integer));			else if (vars->type == ASN_OCTET_STR)				printf ("str: %s\n", vars->val.string);	}	else if (status == STAT_SUCCESS)		fprintf (stderr, "Error in packet\nReason: %s\n", snmp_errstring (response->errstat));	else		snmp_sess_perror ("snmpget", ss);	if (response)		snmp_free_pdu (response);	snmp_close (ss);	return 0;}