Hi together,

i implemented  a program which receives SNMP-Traps from each source and prints 
the oid and the value of the trap.
My problem is to get the ip-address from the  source which sends the trap.
Here are two functions which I call in main() to receive and print the traps:

int my_asynch_response(int operation, struct snmp_session *sp, int reqid,
                               struct snmp_pdu *pdu, void *magic) {
                char buf[1024];
                struct variable_list *vp;
                int ix;
                struct timeval now;
                struct timezone tz;
                struct tm *tm;

                struct snmp_pdu *req;

                printf("\nGot the message!! Trying to sent it out again\n");

                if (operation == NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE) {
                     print_result(STAT_SUCCESS, sp , pdu);
                }


                return 0;
}


/* simple printing of returned data
*/
int print_result (int status, struct snmp_session *sp, struct snmp_pdu *pdu)
{
char buf[1024];
struct variable_list *vp;
int ix;
struct timeval now;
struct timezone tz;
struct tm *tm;

gettimeofday(&now, &tz);
tm = localtime(&now.tv_sec);
//fprintf(stdout, "%.2d:%.2d:%.2d.%.6d ", tm->tm_hour, tm->tm_min, tm->tm_sec,
        // now.tv_usec);
switch (status) {
case STAT_SUCCESS:
   vp = pdu->variables;

   if (pdu->errstat == SNMP_ERR_NOERROR) {


     while (vp) {
                // PRINT ALLES
       //snprint_variable(buf, sizeof(buf), vp->name, vp->name_length, vp);

        // PRINT ONLY OIDs
       snprint_objid(buf, sizeof(buf), vp->name, vp->name_length);

       fprintf(stdout, "%s\n", buf);



       snprint_value(buf, sizeof(buf), vp->name, vp->name_length, vp);


       fprintf(stdout, "%s\n" , buf);



                vp = vp->next_variable;
     }
   }
   else {
     for (ix = 1; vp && ix != pdu->errindex; vp = vp->next_variable, ix++)
       ;
     if (vp) snprint_objid(buf, sizeof(buf), vp->name, vp->name_length);
     else strcpy(buf, "(none)");
     fprintf(stdout, "%s: %s: %s\n",
                sp->peername, buf, snmp_errstring(pdu->errstat));

   }
   return 1;
case STAT_TIMEOUT:
   fprintf(stdout, "%s: Timeout\n", sp->peername);
   return 0;
case STAT_ERROR:
   snmp_perror(sp->peername);
   return 0;
}
return 0;
}
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to