On 26/12/06, Clement Hsu wrote:
> I meet a problem of how to debug snmp codes
> the following is my code...


> void
> init_ustScalarSet(void)
> {
>
> DEBUGMSGTL(("ustScalarSet", "Initializing\n"));
>
> REGISTER_MIB("ustScalarSet", ustScalarSet_variables, variable4,
> ustScalarSet_variables_oid);

[snip]


That would be activated by running the agent using

snmpd -DustScalarSet -f -Le

(The '-f -Le' isn;t strictly necessary, but it often helps to see debug out=
put
if the agent is run directly on the command line).




> unsigned char *
> var_ustScalarSet(struct variable *vp,
> oid * name,
> size_t *length,
> int exact, size_t *var_len, WriteMethod ** write_method)
> {


I'd probably have some debug code here, to tell if the routine is called at=
all.


> if (header_generic(vp, name, length, exact, var_len, write_method)
> =3D=3D MATCH_FAILED)
> return NULL;
>
> switch (vp->magic) {
> case USTSSSIMPLESTRING:
> *write_method =3D write_ustSSSimpleString;
>
> printf("check some thing");


I'd use the same DEBUGMSG() style code - rather than direct print statement=
s.
That way it works even when the agent is run as a daemon.

>
> return (u_char *);


But return what?
I wouldn't expect this code to even compile!



> case USTSSSECONDSSINCECHANGED:
>
> printf("check error , this is snmpget");


Again, use DEBUGMSG()




> After I give the command as belowed:
>
> gcc -I/usr/local/include -fPIC -shared =96c =96o ustScalarSet.c ustScala=

rSet.o
> gcc -I/usr/local/include -fPIC -shared =96o ustScalarSet.so ustScalarSet=

..o
>
>
> and add a line to snmpd.conf :
> dlmod ustScalarSet /usr/local/temp/ustScalarSet.so
>
> After I pass the gcc compile, when I use snmpget, the message show there
> doesn't exist such objet, I don't know why, and how to give the exact com=

mand to
> debug the above codes and how to find out the problem where it is


Please see the FAQ entry
" I've added my code to this template and it still doesn't work. Why no=
t?"

(http://net-snmp.sourceforge.net/wiki.../FAQ:Coding_13)

That gives you a checklist of things to work through.

Dave

-------------------------------------------------------------------------
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...orge&CID=3DDE=
VDEV
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/...et-snmp-coders