Hello,
I am using netsnmp 5.4 , i have written a code that will send trap
to main agent i.e. snmpd, for this i have return a module that have
following function i.e.
1 ) initialize()
     doing snmp initialization in this function i.e
     if (netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_ROLE, 1) != 0)
                   return ERROR;
      //
      // for this i also modified snmpd.conf so that main agent
      // listen on correct port
     if (netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
           NETSNMP_DS_AGENT_X_SOCKET, "tcp:localhost:705") !=0 )
               return ERR_NETSNMP;
       while(i< 4) {
              ret_val = init_agent("subagent");
              if(ret_val == 0)
                      break;
              sleep(2);
              i++;
      }
      if(ret_val != 0)
              return ERR_NETSNMP;
      init_snmp("subagent");

2) trap_send
   send trap to main  agent i.e. snmpd
    using following api
    snmp_varlist_add_variable
    sendv2_trap
    snmp_free_varbind

3) destroy
   snmp_shutdown("sub-agent");
   shutdown_agent();


     when my program starts it call initialize then for sending trap it
call
     trap_send function. when main program dont want to send trap
     it call destroy & stop main agent & problem occurs when main program
want to send
     trap again then it again start Main agent then call initialization
function & when it call
     initialization then after that trap send by program not received by
main agent
     ie flow is like this
                          (start snmpd)
                           initialize
                                |
                          trap_send
                                |
                           destroy
                          ( stop snmpd)
                                |
                           (start snmpd)
                           initialize
                                |
                          trap_send (then trap send here not received by
Main agent
                                           because I think no
initialization done in init_snmp thats why)

     I seen  some code of  netsnmp  in init_snmp function if we are calling
first time
     then it will do further processing & if we are calling for second time
then it will just
     return by not doing anything, this is code of init_snmp
     void init_snmp(const char *type)
     {
              static int      done_init = 0;      /* To prevent double
init's. */
              if (done_init) {
                         return;
              }
              done_init = 1;


        /*
        * make the type available everywhere else
        */
       if (type && !netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
                                         NETSNMP_DS_LIB_APPTYPE)) {
          netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
                                NETSNMP_DS_LIB_APPTYPE, type);
       }
           .
           .
           .
           .
  }

  and as far as i know in init_snmp function subagent will send some packet
to
  main agent, & because of this that packet won't send by subagent, so trap
not received by main agent
  One more question i want ask
  I want prepare application which will at start main agent then call
initialize then trap_send,
 & when i don't want to send trap it will call destroy & then stop main
agent i.e snmpd
 & then afterward when I want to send trap then my application will again
start Main agent i.e snmpd
 call initialize then trap_send accordingly, thats why i want to call
init_snmp
 again, but it will return by not doing anything so what should i do ?.
 Thanks in Advance
 Regards
 bhushan. E . Sonawane
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to