Hello Friends.

Please, help me out.

I try to connect to snmp agent, but unsuccessfully. My code

	struct snmp_session sss;
	struct snmp_session* sss1;
	struct snmp_pdu * pdu = NULL;
	oid src_par[] = {1,3,6,1,2,1,1};
	oid dst_par[] = {1,3,6,1,2,1,1,9};
	oid cont[] = {1,3,6,1,2,1,1,1};
	sss.community = (u_char*)"public";
	sss.community_len = strlen("public");
	sss.retries = 2;
	sss.timeout = 500000;
	sss.peername = "192.168.123.187";
	sss.remote_port = 161;
	sss.local_port = 0;
	sss.authenticator = NULL;
	sss.callback = snmp_callback;
	sss.version = SNMP_VERSION_2;
	sss.srcParty = src_par;
	sss.srcPartyLen = 7;
	sss.dstParty = dst_par;
	sss.dstPartyLen = 8;
	sss.context = cont;
	sss.contextLen = 8;
	
			
	
	
	sss1 = snmp_open(&sss);
	
	pdu = snmp_pdu_create(GET_REQ_MSG);
	snmp_send( sss1, pdu );
	
	
	return EXIT_SUCCESS;

After snmp_send call I get error “Error building packet”.

You don’t seem to be setting up a variable to retrieve in the pdu, eg.

oid oid[MAX_OID_LEN];
size_t oid_len;

pdu = snmp_pdu_create(GET_REQ_MSG);

read_objid(OID_NAME, oid, &oid_len);
snmp_add_null_var(pdu, oid, oid_len);

snmp_send(…)

Hello Maschoen. Thanks for your help. I try to use your suggestion, but unsuccessfully. This is code.

struct snmp_session sss;
struct snmp_session* sss1;
struct snmp_pdu * pdu = NULL;

oid oid_sys[MAX_OID_LEN];
int oid_len;


oid src_par[] = {1,3,6,1,2,1,1};
oid dst_par[] = {1,3,6,1,2,1,1,9};
oid cont[] = {1,3,6,1,2,1,1,1};
sss.community = (u_char*)"public";
sss.community_len = strlen("public");
sss.retries = 2;
sss.timeout = 500000;
sss.peername = "192.168.123.187";
sss.remote_port = 161;
sss.local_port = 0;
sss.authenticator = NULL;
sss.callback = snmp_callback;
sss.version = SNMP_VERSION_2;
sss.srcParty = src_par;
sss.srcPartyLen = 7;
sss.dstParty = dst_par;
sss.dstPartyLen = 8;
sss.context = cont;
sss.contextLen = 8;

init_mib();I add this lines

sss1 = snmp_open(&sss);

pdu = snmp_pdu_create(GET_REQ_MSG);

read_objid(".1.3.6.1.2.1.1.1.0", oid_sys, &oid_len);
snmp_add_null_var(pdu, oid_sys, oid_len); I add this lines

snmp_send( sss1, pdu );

But error still remain - “Error building packet”

And what is the purpose of the srcParty,dstParty, context vars and what is difference between this vars???

Machoen , where are you???

I don’t have anything to add. I don’t know why your code isn’t working.

Maybe, someone have working snmp source code or part of the code , where PDU being initialized???