How to set request-specific data to SNMP agent using net-snmp? -


i want snmp agent response differently depending on source requester, cannot find way magic convey data make distinguishable snmp agent.

what have tried setting netsnmp_session structure , netsnmp_pdu structure. because they're 2 parameters of snmp_send. data field tried facilitate myvoid , callback_magic.

but unfortunately on snmp agent, data received 0, not have set on snmp client.

sorry answer myselv's question.

finally found following trick circumvent issue: insert known snmp object(such ifnumber) after target snmp object identify specific snmp query.

the handler function in agent should check variable next current variable see whether it's known snmp object ifnumber. if yes query comes you, using net-snmp api form variable list of query.

client code:

    oid dest_oid[ max_oid_len ] = {0};     size_t dest_oid_len = count_of(dest_oid);     get_node(g_snmp_name_ifnumber, dest_oid, &dest_oid_len );     snmp_add_null_var(pdu, dest_oid, dest_oid_len); 

on agent side:

 int get_status(netsnmp_mib_handler *handler,             netsnmp_handler_registration *reginfo,             netsnmp_agent_request_info *reqinfo,             netsnmp_request_info *requests)  {     switch (reqinfo->mode) {          case mode_get:             {                      bool is_sent_by_manager = false;                     if( requests->requestvb->next_variable )                     {                         struct variable_list * v = requests->requestvb->next_variable;                          oid dest_oid[ max_oid_len ] = {0};                         size_t dest_oid_len = count_of(dest_oid);                         get_node(g_snmp_name_ifnumber, dest_oid, &dest_oid_len );                          const int nbytes = v->name_length * sizeof(v->name[0]);                         if( dest_oid_len >= v->name_length                             && memcmp(dest_oid, v->name, nbytes) == 0 ) {                             is_sent_by_manager = true;                         }                     }                      if( is_sent_by_manager ) {                        ...                     }                     else {                        ...                     } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -