Hi,

Thanks for your hint.
With snmp_synch_response it works properly.

Best regards, 
Andrei Yahorau



From:   "Craig Small" <csm...@dropbear.xyz>
To:     ayaho...@ibagroup.eu
Cc:     "net-snmp coders" <net-snmp-coders@lists.sourceforge.net>
Date:   28.01.2021 04:20
Subject:        Re: A simple C program which sends v2c informs do not make 
retries in case of unavailable destination



Hi,
  Maybe have a look at the source to snmptrap to see how its done there?

snmp_send seems to be a fire and forget.  

You probably want snmp_synch_response or to look how it does the select, 
read and timeout functions and copy that.

 - Craig


On Thu, 28 Jan 2021 at 01:35, <ayaho...@ibagroup.eu> wrote:
Hello!

Did anyone face the same behaviour? 
Why the retries are not accepted?

What is necessary to do in order to resolve this situation? 

Best regards, 
Andrei Yahorau 



From:        Andrei Yahorau/IBA 
To:        net-snmp-coders@lists.sourceforge.net 
Date:        08.05.2020 10:37 
Subject:        A simple C program which sends v2c informs do not make 
retries in case of unavailable destination 


Hello Everyone! 

I have a question. I want to send SNMP v2c informs using C and net-snmp 
module in linux SLES 12.
To do this I created the following simple program where everything comes 
to send_trap_to_sess() function :

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
oid             objid_sysuptime[] = { 1, 3, 6, 1, 2, 1, 1, 3, 0 };
oid             objid_id[] = { 1,3,6,1,4,1,78945,1,1,2,4,0};
oid             objid_name[] = { 1,3,6,1,4,1,78945,1,1,2,1,0};
oid              trap_oid[] = {1,3,6,1,4,1,78945,1,1,1,1,1};
int main()
{
   netsnmp_session session, *ss;
   netsnmp_pdu    *pdu, *response;
   char *trap = NULL;

   char comm[] = "public";
   snmp_sess_init( &session );
   session.version = SNMP_VERSION_2c;
   session.community = comm;
   session.community_len = strlen(session.community);
   session.peername = "192.168.4.10:1234"; 
    session.retries = 3; 
    session.timeout = 1000;
   ss = snmp_open(&session);
   if (!ss) {
     snmp_sess_perror("ack", &session);
     exit(1);
   }
   pdu = snmp_pdu_create(SNMP_MSG_INFORM);
   pdu->community = comm;
   pdu->community_len = strlen(comm);
   pdu->trap_type = SNMP_TRAP_ENTERPRISESPECIFIC;
   long sysuptime;
   char csysuptime [20];
   sysuptime = get_uptime ();
   sprintf (csysuptime, "%ld", sysuptime);
   trap = csysuptime;
   snmp_add_var (pdu, objid_sysuptime, sizeof (objid_sysuptime)/sizeof
(oid),'t', trap);
   snmp_add_var(pdu, trap_oid, OID_LENGTH(trap_oid), 'o', 
"1.3.6.1.4.1.78945.1.1.1.1.1");
   snmp_add_var(pdu, objid_name, OID_LENGTH(objid_name), 's', "Test Name"
);
   snmp_add_var(pdu, objid_id, OID_LENGTH(objid_id) , 'i', "5468");
   send_trap_to_sess (ss, pdu);
   snmp_close(ss);
   return (0);
}


Frankly speaking this is modified part of code taken from 
https://stackoverflow.com/questions/30050542/how-to-send-v2-traps-in-net-snmp-using-c
 
 where a user asked how to send snmp v2c trap using C. 
Here I modified creation of pdu:
pdu = snmp_pdu_create(SNMP_MSG_INFORM);
and added assignments of retries and timeout values for informs
session.retries = 3; 
session.timeout = 1000; 

This example works quite well. I see that it sends inform request in 
wireshark output. But there is one problem: If the destination is not 
available it will not do any retries despite that this is an inform.

Could you please give me a suggestion what I do wrong here? 
Thank you in advance.

Best regards, 
Andrei Yahorau 
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to