Search code examples
c++csnmp

How to receive and decode SNMP traps in a C (or C++) application?


I am trying to write a very small SNMP trap receiver, listening to UDP port 162.

Traps come in fine, but I can not decode them.

I have found libber, but it can't decode the traps for some reason. I am probably using it wrong. I imagine decoding an SNMP trap should be fairly simple and that I am missing something crucial. Is it possible to use NET-SNMP as a library and create a small trap-receiving program from it? I would not be surprised at all, but can not find any information about it. Maybe my google-fu is weak.


Solution

  • Well, using net-snmp, you usually use snmptrapd daemon that calls for you external commands/scripts. If you cannot use this way, I suggest you look at snmptrapd.c code. Moreover, if I recall correctly, they build a libsnmptrapd library. It should be easy to find the right API calls ...

    If I have time I will update my answer with a snippet ...

    my2c