[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

8990.0. "esnmp callback function doesn't work." by NETRIX::"[email protected]" (Keith Austin) Thu Feb 27 1997 15:58

I can't seem to get the esnmp API callback function to work.  The callback
function does get invoked; however, referencing the parameters that were
passed
to it (int level and char* msg) seems wrong.  The code and output is below.

I'm compiling on a DU V3.2G AS 8200.

TIA!

-Keith Austin


esnmptrap.c
===========
/* cc -o esnmptrap esnmptrap.c -lesnmp */

#include <esnmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

void log_handler ( int level, char *msg );

int main(void)
{

int status = 0;
int rc = ESNMP_LIB_NOTOK;
int esnmp_subsocket = 0;
char conn_name[15];

        set_debug_level ( ERROR | WARNING | EXTERN_LOG,
                                   (LOG_CALLBACK_ROUTINE) log_handler ) ;

        sprintf(conn_name,"pid_%d",(int)getpid());

        status = esnmp_init(&esnmp_subsocket, conn_name);
        rc = esnmp_poll();

        ESNMP_LOG( WARNING, ("KEA"));
        esnmp_term();
        exit(0);
}

void log_handler ( int level, char* msg ) 
{
         printf("Level: ***%d***  Msg: ***%s***\n\n", level, msg);
         printf("Level: ***%d***  Msg: ***%s***\n", level, msg-25);
}

Actual Output
=============
Level: ***536865600***  Msg: ***EAdata***

Level: ***536865600***  Msg: ****EAdata***

.c line 26: KEAdata***

Expected Output
===============
Level: ***4096*** Msg: ***KEA***

Level: ***4096*** Msg: ***Some-String***

[Posted by WWW Notes gateway]
T.RTitleUserPersonal
Name
DateLines
8990.1RDGENG::HAQUEShaheed R. Haque, 830-3531, reo2-f/b3Fri Feb 28 1997 05:2611
Just a guess, but since conn_name is allocate on the stack, can you be sure that
the storage is still around when the callback executes? What happens if you
declare it like this:

...main(...)
{
...
static char conn_name[15];
...
}
8990.2SMURF::DANIELEFri Feb 28 1997 09:578
Also answered in the SNMP conference.

The callback function is passed the address of a LOG_CALLBACK
structure, not an int and a char *.

See esnmp.h.

Mike