SNMP convert string representing datetime to dateandtime octetstr

484 views Asked by At

I'm trying to emit a datetime in snmp, for what I understand the DateAndTime string is a string of 11 bytes representind values in this format: ( 1 letter -> 1 Byte)
y -> year
m -> month
d -> day
h -> hour
M -> minute
s -> second
u -> 1/10th of second
^ -> + or - for timezone offset
H -> timezone offset (hours)
N -> timezone offset (minutes)

yymdhMsu^HN

//Array encoding the date: 2022-11-10 12:30:15.11 UTC + 01:33
   uint8_t BFF[11];
        BFF[0] = 22;
        BFF[1] = 20;
        //-
        BFF[2] = 11;
        //-
        BFF[3] = 10;
        //,
        BFF[4] = 12;
        //:
        BFF[5] = 30;
        //:
        BFF[6] = 15;
        //.
        BFF[7] = 11;
        //,
        BFF[8] = '+';
        BFF[9] = 1;
        //:
        BFF[10] = 33;
        BFF[11] = '\0';

How do I convert it to an SNMP++ OctetStr ?

1

There are 1 answers

0
Andrew On

It is not " 1 letter -> 1 Byte". In the EXAMPLE vs. "DISPLAY-HINT" given in defining https://www.rfc-editor.org/rfc/rfc2579.html, there are 11 bytes (could be 8) and no "letters". There is instead 1 two byte decimal field, 8 one byte decimal fields, and 1 1 byte ASCII field. The are 25 characters, but you results may vary.:

"2d-1d-1d,1d:1d:1d.1d,1a1d:1d"  EXAMPLE in DESCRIPTION
"1992-5-26,13:30:15.0,-4:0"     "DISPLAY-HINT"

The whole RFC section for reference, along with two relevant erratum are shown below:

. (This is an INTERNET STANDARD currently, but has been around since ~1999

TimeInterval ::= TEXTUAL-CONVENTION
    STATUS       current
    DESCRIPTION
            "A period of time, measured in units of 0.01 seconds."
    SYNTAX       INTEGER (0..2147483647)

DateAndTime ::= TEXTUAL-CONVENTION
    DISPLAY-HINT "2d-1d-1d,1d:1d:1d.1d,1a1d:1d"
    STATUS       current
    DESCRIPTION
            "A date-time specification.

            field  octets  contents                  range
            -----  ------  --------                  -----
              1      1-2   year*                     0..65536
              2       3    month                     1..12
              3       4    day                       1..31
              4       5    hour                      0..23
              5       6    minutes                   0..59
              6       7    seconds                   0..60
                           (use 60 for leap-second)
              7       8    deci-seconds              0..9
              8       9    direction from UTC        '+' / '-'
              9      10    hours from UTC*           0..13
             10      11    minutes from UTC          0..59

            * Notes:
            - the value of year is in network-byte order
            - daylight saving time in New Zealand is +13

            For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would be
            displayed as:

                             1992-5-26,13:30:15.0,-4:0


McCloghrie, et al.          Standards Track                    [Page 18]

RFC 2579             Textual Conventions for SMIv2            April 1999


            Note that if only local time is known, then timezone
            information (fields 8-10) is not present."
    SYNTAX       OCTET STRING (SIZE (8 | 11))

Note that this RFC has 2 relevant erratas:

Errata ID: 417
Status: Verified
Type: Technical
Publication Format(s) : TEXT
Reported By: Juergen Schoenwaelder
Date Reported: 2001-07-31
Section 2 says:

RFC 2579 lists an invalid range for the year in the DateAndTime TC:

            field  octets  contents                  range
            -----  ------  --------                  -----
              1      1-2   year*                     0..65536
It should say:

            field  octets  contents                  range
            -----  ------  --------                  -----
              1      1-2   year*                     0..65535

Errata ID: 416
Status: Verified
Type: Editorial
Publication Format(s) : TEXT
Reported By: Juergen Schoenwaelder
Date Reported: 2004-07-27
The DateAndTime textual convention did not originally define a special value which can be used in situations where a DateAndTime value is unknown or for some other reason not available. Several MIB modules on the IETF standards-track use the value '0000

              2       3    month                     1..12
              3       4    day                       1..31
It should say:

              2       3    month                 0 | 1..12
              3       4    day                   0 | 1..31