Hi Pim,

Do you have a test case (i.e. input values) for the case that the return
value is invalid with the 2.4.2 code?

Thanks in advance.

Best regards,
Frank

Am 08.04.2016 um 09:18 schrieb Pim Moerenhout:
Hi Frank,

I was using the org.snmp4j.agent.mo.snmp.DateAndTime class in my Snmp4j
agent.I'm using the latest 2.4.2 release. I discovered that an DateTime
encoded OctetString was not parsed correctly, and having a different
Timezone then UTC generated other epoch values then expected.

When I changed the makeCalendar method as follows, it  works:

public static GregorianCalendar makeCalendar(OctetString dateAndTimeValue) {
   GregorianCalendar gc;
   if (dateAndTimeValue.length() == 11) {
     String timezone = String.format("GMT%c%02d:%02d",
(char)(dateAndTimeValue.get(8)),
         dateAndTimeValue.get(9), dateAndTimeValue.get(10));
     gc = new GregorianCalendar(TimeZone.getTimeZone(timezone));
   }
   else{
     // localtime
     gc = new GregorianCalendar();
   }
   int year = (dateAndTimeValue.get(0) & 0xFF ) * 256 +
       (dateAndTimeValue.get(1) & 0xFF );
   int month = (dateAndTimeValue.get(2) & 0xFF );
   int date = (dateAndTimeValue.get(3) & 0xFF );
   int hour = (dateAndTimeValue.get(4) & 0xFF );
   int minute = (dateAndTimeValue.get(5) & 0xFF );
   int second = (dateAndTimeValue.get(6) & 0xFF );
   int deci = (dateAndTimeValue.get(7) & 0xFF );
   gc.set(year, month-1, date, hour, minute, second);
   gc.set(Calendar.MILLISECOND, deci*100);
   return gc;
}

Could you change this?

Regards, Pim
_______________________________________________
SNMP4J mailing list
[email protected]
https://oosnmp.net/mailman/listinfo/snmp4j

--
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231

_______________________________________________
SNMP4J mailing list
[email protected]
https://oosnmp.net/mailman/listinfo/snmp4j

Reply via email to