Re: A simple C program which sends v2c informs do not make retries in case of unavailable destination

Craig Small <[email protected]>
Newsgroups gmane.network.net-snmp.devel
Message-ID <CALy8Cw4Bmypf-V=xZjcenMKWsQYw=ko8fYEzWfFPKqxRAn-kvA@mail.gmail.com>
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, <[email protected]> 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:        [email protected]
> 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*
> <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
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
>

_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.