--===============0803639681==
Content-Type: multipart/alternative;
boundary="----=_Part_3919_1696858.1165320057643"

------=_Part_3919_1696858.1165320057643
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello Friends
In Investigation of problem I put log messages i.e. printf in
agent_trap.c (in agent directory) in function netsnmp_send_traps
because send_v2trap/ send_easy_trap calls this function
in turn. updated function look as follows (in this i putted some printfs)

int
netsnmp_send_traps(int trap, int specific,
oid * enterprise, int enterprise_length,
netsnmp_variable_list * vars,
char * context, int flags)
{
netsnmp_pdu *template_v1pdu;
netsnmp_pdu *template_v2pdu;
netsnmp_variable_list *vblist = NULL;
netsnmp_variable_list *trap_vb;
netsnmp_variable_list *var;
in_addr_t *pdu_in_addr_t;
u_long uptime;
struct trap_sink *sink;

DEBUGMSGTL(( "trap", "send_trap %d %d ", trap, specific));
DEBUGMSGOID(("trap", enterprise, enterprise_length));
DEBUGMSG(( "trap", "\n"));
printf("\nAt Intial stage 1\n");
if (vars) {
vblist = snmp_clone_varbind( vars );
if (!vblist) {
snmp_log(LOG_WARNING,
"send_trap: failed to clone varbind list\n");
printf("\n\ Faile 1 \n");
return -1;
}
}
printf("\nAt stage 2\n");

if ( trap == -1 ) {
printf("\nAt stage 2.1\n");
/*
* Construct the SNMPv2-style notification PDU
*/
if (!vblist) {
snmp_log(LOG_WARNING,
"send_trap: called with NULL v2 information\n");
printf("\n\ Faile 2 \n");
return -1;
}
template_v2pdu = snmp_pdu_create(SNMP_MSG_TRAP2);
if (!template_v2pdu) {
snmp_log(LOG_WARNING,
"send_trap: failed to construct v2 template PDU\n");
snmp_free_varbind(vblist);
printf("\n\ Faile 3 \n");
return -1;
}
printf("\nAt stage 2.2\n");

/*
* Check the varbind list we've been given.
* If it starts with a 'sysUptime.0' varbind, then use that.
* Otherwise, prepend a suitable 'sysUptime.0' varbind.
*/
if (!snmp_oid_compare( vblist->name, vblist->name_length,
sysuptime_oid, sysuptime_oid_len )) {
template_v2pdu->variables = vblist;
trap_vb = vblist->next_variable;
} else {
uptime = netsnmp_get_agent_uptime();
var = NULL;
snmp_varlist_add_variable( &var,
sysuptime_oid, sysuptime_oid_len,
ASN_TIMETICKS, (u_char*)&uptime, sizeof(uptime));
if (!var) {
snmp_log(LOG_WARNING,
"send_trap: failed to insert sysUptime varbind\n");
snmp_free_pdu(template_v2pdu);
snmp_free_varbind(vblist);
printf("\n\ Faile 4 \n");
return -1;
}
printf("\nAt stage 2.3\n");
template_v2pdu->variables = var;
var->next_variable = vblist;
trap_vb = vblist;

}
printf("\nAt stage 2.4\n");

/*
* 'trap_vb' should point to the snmpTrapOID.0 varbind,
* identifying the requested trap. If not then bomb out.
* If it's a 'standard' trap, then we need to append an
* snmpEnterprise varbind (if there isn't already one).
*/

if (!trap_vb ||
snmp_oid_compare(trap_vb->name, trap_vb->name_length,
snmptrap_oid, snmptrap_oid_len)) {
snmp_log(LOG_WARNING,
"send_trap: no v2 trapOID varbind provided\n");
snmp_free_pdu(template_v2pdu);
printf("\n\ Faile 5 \n");
return -1;
}
printf("\nAt stage 2.5\n");
printf("\nAt stage 4\n");
if (!snmp_oid_compare(vblist->val.objid, OID_LENGTH(trap_prefix),
trap_prefix, OID_LENGTH(trap_prefix))) {
var = find_varbind_in_list( template_v2pdu->variables,
snmptrapenterprise_oid,
snmptrapenterprise_oid_len);
if (!var &&
!snmp_varlist_add_variable( &(template_v2pdu->variables),
snmptrapenterprise_oid, snmptrapenterprise_oid_len,
ASN_OBJECT_ID,
(char*)enterprise, enterprise_length*sizeof(oid))) {
snmp_log(LOG_WARNING,
"send_trap: failed to add snmpEnterprise to v2
trap\n");
snmp_free_pdu(template_v2pdu);
printf("\n\ Faile 6 \n");
return -1;
}
}
printf("\nAt stage 2.6\n");

/*
* If everything's OK, convert the v2 template into an SNMPv1 trap
PDU.
*/
template_v1pdu = convert_v2pdu_to_v1( template_v2pdu );
if (!template_v1pdu) {
snmp_log(LOG_WARNING,
"send_trap: failed to convert v2->v1 template PDU\n");
snmp_free_pdu(template_v2pdu);
printf("\n\ Faile 7 \n");
return -1;
}
printf("\nStage 2 end\n");

} else {
printf("\nAt stage 3\n");
/*
* Construct the SNMPv1 trap PDU....
*/
template_v1pdu = snmp_pdu_create(SNMP_MSG_TRAP);
if (!template_v1pdu) {
snmp_log(LOG_WARNING,
"send_trap: failed to construct v1 template PDU\n");
snmp_free_varbind(vblist);
printf("\n\ Faile 8 \n");
return -1;
}
template_v1pdu->trap_type = trap;
template_v1pdu->specific_type = specific;
template_v1pdu->time = netsnmp_get_agent_uptime();
printf("\nAt stage 3.1\n");
if (snmp_clone_mem((void **) &template_v1pdu->enterprise,
enterprise, enterprise_length * sizeof(oid))) {
snmp_log(LOG_WARNING,
"send_trap: failed to set v1 enterprise OID\n");
snmp_free_varbind(vblist);
snmp_free_pdu(template_v1pdu);
printf("\n\ Faile 8 \n");
return -1;
}
template_v1pdu->enterprise_length = enterprise_length;

template_v1pdu->flags |= UCD_MSG_FLAG_FORCE_PDU_COPY;
template_v1pdu->variables = vblist;

/*
* ... and convert it into an SNMPv2-style notification PDU.
*/
printf("\nAt stage 3.2\n");
template_v2pdu = convert_v1pdu_to_v2( template_v1pdu );
if (!template_v2pdu) {
snmp_log(LOG_WARNING,
"send_trap: failed to convert v1->v2 template PDU\n");
snmp_free_pdu(template_v1pdu);
printf("\n\ Faile 10 \n");
return -1;
}
printf("\nCompleted stage 3\n");
}

/*
* Check whether we're ignoring authFail traps
*/
printf("\nAt stage 4\n");
if (template_v1pdu->trap_type == SNMP_TRAP_AUTHFAIL &&
snmp_enableauthentraps == SNMP_AUTHENTICATED_TRAPS_DISABLED) {
snmp_free_pdu(template_v1pdu);
snmp_free_pdu(template_v2pdu);
return 0;
}

/*
* Ensure that the v1 trap PDU includes the local IP address
*/
printf("\nAt stage 5\n");
pdu_in_addr_t = (in_addr_t *) template_v1pdu->agent_addr;
*pdu_in_addr_t = get_myaddr();


/*
* Now loop through the list of trap sinks
* and call the trap callback routines,
* providing an appropriately formatted PDU in each case
*/
printf("\nAt stage 6\n");
// My comments
// As far as i understand This for loop
// sends trap to main agent, & when I see log messages
// this for loop never get execute means
// Value of sinks variable is NULL so no trap send by process
// so my subagent code call send_v2trap but
// send_v2trap has return value void so user never come to know
// weather trap send by API or not
for (sink = sinks; sink; sink = sink->next) {
printf("\nAt stage 6.1 loop \n");
#ifndef NETSNMP_DISABLE_SNMPV1
if (sink->version == SNMP_VERSION_1) {
printf("\n\ Sending trap v1 \n");
send_trap_to_sess(sink->sesp, template_v1pdu);
} else {
#endif
printf("\n\ Sending trap v2 \n");
template_v2pdu->command = sink->pdutype;
send_trap_to_sess(sink->sesp, template_v2pdu);
#ifndef NETSNMP_DISABLE_SNMPV1
}
#endif
}
printf("\nAt stage 7\n");
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
SNMPD_CALLBACK_SEND_TRAP1, template_v1pdu);
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
SNMPD_CALLBACK_SEND_TRAP2, template_v2pdu);
snmp_free_pdu(template_v1pdu);
snmp_free_pdu(template_v2pdu);
printf("\nAt stage 8\n");
printf("\n\ returning from netsnmp_send_traps \n");
return 0;
}

According to my comment in above code,
Sinks variable is NULL, this is global variable in agent_trap.c
& this variable fill(updated) by function "add_trap_session" located in same

file i.e. agent_trap.c
when I am looking at code add_trap_session function get call by
function snmpd_parse_config_trapsess, and
snmpd_parse_config_trapsess function used in
init_agent_read_config function located in agent_read_config.c
(libagent directory) & init_agent_read_config function also get call
by init_agent (located in snmp_vars.c).
So I think problem lies here in init_agent, so Is i am sending Correct
Parameter to above function ?
i.e. init_agent("sub-agent"); like this
I tried like this also init_agent("c:\\usr\\etc\\snmp\\snmpd.conf");
still trap are not get send by subagent.
So what is problem ?
Please give me any clue so i investigate problem.
Thanks in advance Friends
Regards
Bhushan E. Sonawane

------=_Part_3919_1696858.1165320057643
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

 Hello Friends
 In Investigation of  problem I put log messages i.e. printf  in
 agent_trap.c (in agent directory)   in function netsnmp_send_traps
 because send_v2trap/ send_easy_trap calls this function
 in turn. updated function look as follows (in this i putted some printfs)

 
int
netsnmp_send_traps(int trap, int specific,
                          oid * enterprise, int enterprise_length,
                          netsnmp_variable_list * vars,
                          char * context, int flags)

{
    netsnmp_pdu           *template_v1pdu;
    netsnmp_pdu           *template_v2pdu;
    netsnmp_variable_list *vblist = NULL;
    netsnmp_variable_list *trap_vb;
    netsnmp_variable_list *var;
    in_addr_t             *pdu_in_addr_t;

    u_long                 uptime;
    struct trap_sink *sink;

    DEBUGMSGTL(( "trap", "send_trap %d %d ", trap, specific));
    DEBUGMSGOID(("trap", enterprise, enterprise_length));

    DEBUGMSG(( "trap", "\n"));
    printf("\nAt Intial stage 1\n");
    if (vars) {
        vblist = snmp_clone_varbind( vars );
        if (!vblist) {
            snmp_log(LOG_WARNING,

                     "send_trap: failed to clone varbind list\n");
            printf("\n\ Faile 1 \n");
            return -1;
        }
    }
    printf("\nAt  stage 2\n");


    if ( trap == -1 ) {
        printf("\nAt  stage 2.1\n");
        /*
         * Construct the SNMPv2-style notification PDU
         */
        if (!vblist) {
            snmp_log(LOG_WARNING,

                     "send_trap: called with NULL v2 information\n");
            printf("\n\ Faile 2 \n");
            return -1;
        }
        template_v2pdu = snmp_pdu_create(SNMP_MSG_TRAP2);

        if (!template_v2pdu) {
            snmp_log(LOG_WARNING,
                     "send_trap: failed to construct v2 template PDU\n");
            snmp_free_varbind(vblist);
            printf("\n\ Faile 3 \n");

            return -1;
        }
        printf("\nAt  stage 2.2\n");

        /*
         * Check the varbind list we've been given.
         * If it starts with a 'sysUptime.0' varbind, then use that.

         * Otherwise, prepend a suitable 'sysUptime.0' varbind.
         */
        if (!snmp_oid_compare( vblist->name,    vblist->name_length,
                               sysuptime_oid, sysuptime_oid_len )) {

            template_v2pdu->variables = vblist;
            trap_vb  = vblist->next_variable;
        } else {
            uptime   = netsnmp_get_agent_uptime();
            var = NULL;
            snmp_varlist_add_variable( &var,

                           sysuptime_oid, sysuptime_oid_len,
                           ASN_TIMETICKS, (u_char*)&uptime, sizeof(uptime));
            if (!var) {
                snmp_log(LOG_WARNING,
                     "send_trap: failed to insert sysUptime varbind\n");

                snmp_free_pdu(template_v2pdu);
                snmp_free_varbind(vblist);
                printf("\n\ Faile 4 \n");
                return -1;
            }
            printf("\nAt  stage
2.3\n");
            template_v2pdu->variables = var;
            var->next_variable        = vblist;
            trap_vb  = vblist;
           
        }
        printf("\nAt  stage 2.4\n
");

        /*
         * 'trap_vb' should point to the snmpTrapOID.0 varbind,
         *   identifying the requested trap.  If not then bomb out.
         * If it's a 'standard' trap, then we need to append an

         *   snmpEnterprise varbind (if there isn't already one).
         */
       
        if (!trap_vb ||
            snmp_oid_compare(trap_vb->name, trap_vb->name_length,
                             snmptrap_oid,  snmptrap_oid_len)) {

            snmp_log(LOG_WARNING,
                     "send_trap: no v2 trapOID varbind provided\n");
            snmp_free_pdu(template_v2pdu);
            printf("\n\ Faile 5 \n");
            return -1;

        }
        printf("\nAt  stage 2.5\n");
        printf("\nAt  stage 4\n");
        if (!snmp_oid_compare(vblist->val.objid, OID_LENGTH(trap_prefix),
                              trap_prefix,       OID_LENGTH(trap_prefix))) {

            var = find_varbind_in_list( template_v2pdu->variables,
                                        snmptrapenterprise_oid,
                                        snmptrapenterprise_oid_len);
            if (!var &&

                !snmp_varlist_add_variable( &(template_v2pdu->variables),
                     snmptrapenterprise_oid, snmptrapenterprise_oid_len,
                     ASN_OBJECT_ID,
                     (char*)enterprise, enterprise_length*sizeof(oid))) {

                snmp_log(LOG_WARNING,
                     "send_trap: failed to add snmpEnterprise to v2 trap\n");
                snmp_free_pdu(template_v2pdu);
                printf("\n\ Faile 6 \n");

                return -1;
            }
        }
        printf("\nAt  stage 2.6\n");

        /*
         * If everything's OK, convert the v2 template into an SNMPv1 trap PDU.
         */

        template_v1pdu = convert_v2pdu_to_v1( template_v2pdu );
        if (!template_v1pdu) {
            snmp_log(LOG_WARNING,
                     "send_trap: failed to convert v2->v1 template PDU\n");

            snmp_free_pdu(template_v2pdu);
            printf("\n\ Faile 7 \n");
            return -1;
        }
        printf("\nStage 2 end\n");

    } else {
        printf("\nAt  stage 3\n");

        /*
         * Construct the SNMPv1 trap PDU....
         */
        template_v1pdu = snmp_pdu_create(SNMP_MSG_TRAP);
        if (!template_v1pdu) {
            snmp_log(LOG_WARNING,
                     "send_trap: failed to construct v1 template PDU\n");

            snmp_free_varbind(vblist);
            printf("\n\ Faile 8 \n");
            return -1;
        }
        template_v1pdu->trap_type     = trap;
        template_v1pdu->specific_type = specific;

        template_v1pdu->time          = netsnmp_get_agent_uptime();
        printf("\nAt  stage 3.1\n");
        if (snmp_clone_mem((void **) &template_v1pdu->enterprise,
                       enterprise, enterprise_length * sizeof(oid))) {

            snmp_log(LOG_WARNING,
                     "send_trap: failed to set v1 enterprise OID\n");
            snmp_free_varbind(vblist);
            snmp_free_pdu(template_v1pdu);
            printf("\n\ Faile 8 \n");

            return -1;
        }
        template_v1pdu->enterprise_length = enterprise_length;

        template_v1pdu->flags    |= UCD_MSG_FLAG_FORCE_PDU_COPY;
        template_v1pdu->variables = vblist;


        /*
         * ... and convert it into an SNMPv2-style notification PDU.
         */
        printf("\nAt  stage 3.2\n");
        template_v2pdu = convert_v1pdu_to_v2( template_v1pdu );

        if (!template_v2pdu) {
            snmp_log(LOG_WARNING,
                     "send_trap: failed to convert v1->v2 template PDU\n");
            snmp_free_pdu(template_v1pdu);
            printf("\n\ Faile 10 \n");

            return -1;
        }
        printf("\nCompleted stage 3\n");
    }

    /*
     * Check whether we're ignoring authFail traps
     */
    printf("\nAt  stage 4\n");

    if (template_v1pdu->trap_type == SNMP_TRAP_AUTHFAIL &&
        snmp_enableauthentraps == SNMP_AUTHENTICATED_TRAPS_DISABLED) {
        snmp_free_pdu(template_v1pdu);
        snmp_free_pdu(template_v2pdu);

        return 0;
    }

    /*
     * Ensure that the v1 trap PDU includes the local IP address
     */
    printf("\nAt  stage 5\n");
     pdu_in_addr_t = (in_addr_t *) template_v1pdu->agent_addr;

    *pdu_in_addr_t = get_myaddr();


    /*
     *  Now loop through the list of trap sinks
     *   and call the trap callback routines,
     *   providing an appropriately formatted PDU in each case

     */
    printf("\nAt  stage 6\n");
    // My comments
    // As far as i understand This for loop

    // sends trap to main agent, & when I see log messages
    // this for loop never get execute means

    // Value of sinks variable is NULL so no trap send by process
    // so my subagent code call send_v2trap but
    // send_v2trap has return value void so user never come to know

    // weather trap send by API or not
    for (sink = sinks; sink; sink = sink->next) {
        printf("\nAt  stage 6.1 loop \n");
#ifndef NETSNMP_DISABLE_SNMPV1
        if (sink->version == SNMP_VERSION_1) {

            printf("\n\ Sending trap v1 \n");
            send_trap_to_sess(sink->sesp, template_v1pdu);
        } else {
#endif
            printf("\n\ Sending trap v2 \n");
            template_v2pdu->command = sink->pdutype;

            send_trap_to_sess(sink->sesp, template_v2pdu);
#ifndef NETSNMP_DISABLE_SNMPV1
        }
#endif
    }
    printf("\nAt  stage 7\n");
    snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,

                        SNMPD_CALLBACK_SEND_TRAP1, template_v1pdu);
    snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
                        SNMPD_CALLBACK_SEND_TRAP2, template_v2pdu);
    snmp_free_pdu(template_v1pdu);

    snmp_free_pdu(template_v2pdu);
    printf("\nAt  stage 8\n");
    printf("\n\ returning from netsnmp_send_traps \n");
    return 0;
}

According to my comment in above code,

Sinks variable is NULL, this is global variable in agent_trap.c
& this variable fill(updated) by function "add_trap_session" located in same
file i.e. agent_trap.c
when I am looking at code add_trap_session function get call by

function snmpd_parse_config_trapsess, and 
snmpd_parse_config_trapsess function used in
init_agent_read_config function located in agent_read_config.c
(libagent directory) & init_agent_read_config function also get call

by init_agent (located in snmp_vars.c).
So I think problem lies here in init_agent, so Is i am sending Correct
Parameter to above function ?
i.e. init_agent("sub-agent"); like this
I tried like this also init_agent("c:\\usr\\etc\\snmp\\snmpd.conf");

still trap are not get send by subagent.
So what is problem ?
Please give me any clue so i investigate problem.
Thanks in advance Friends
Regards
Bhushan E. Sonawane





------=_Part_3919_1696858.1165320057643--


--===============0803639681==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
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?p...rge&CID=DEVDEV
--===============0803639681==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/...et-snmp-coders

--===============0803639681==--