Search code examples
javadecodesnmpbytebuffersnmp4j

Decode a ByteBuffer, result of an snmp trap message


I'm using this to receive an snmpv1 trap message:

transport.addTransportListener(new TransportListener() {
    public void processMessage(TransportMapping transportmapping, 
            Address address, ByteBuffer byteBuffer) {
        BERInputStream berStream = new BERInputStream(byteBuffer);
        BER.decodeString(berStream, new BER.MutableByte());
    }
)};

My problem is that I do not know how to parse byteBuffer to obtain the data the agent sent in a clear way. This is what I obtain if I execute my code now:

java.io.IOException: Wrong ASN.1 type. Not a string: 48 at position 1

I've tried with some other MutableTypes but I'm really confused which one to use. Is this correct? Do you know which MutableType to use if so?


Solution

  • I was doing it totally wrong.

    Thanks to a colleague of mine, here's the correction (ignore the above):

    Snmp snmp = new Snmp(transport);
    CommandResponder trapPrinter = new CommandResponder() {
        public synchronized void processPdu(CommandResponderEvent e) {
            PDU command = e.getPDU();
        }
    };
    

    command contains all the informations, no need to decode anything.