Skip to content
Snippets Groups Projects
Commit 0e611221 authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Adam Wujek
Browse files

util: add the perverse SNMP 'string' time format


/var/lib/mibs/ietf/SNMPv2-TC

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

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

Signed-off-by: default avatarAlessandro Rubini <rubini@gnudd.com>
parent d0595f5c
Branches
Tags
No related merge requests found
......@@ -20,6 +20,7 @@ char *format_time(uint64_t sec, int format);
#define TIME_FORMAT_LEGACY 0
#define TIME_FORMAT_SYSLOG 1
#define TIME_FORMAT_SORTED 2
#define TIME_FORMAT_SNMP 3
/* Color printf() variant. */
void cprintf(int color, const char *fmt, ...);
......
......@@ -85,6 +85,18 @@ char *format_time(uint64_t sec, int format)
t.tm_year + YEAR0, t.tm_mon + 1, t.tm_mday,
t.tm_hour, t.tm_min, t.tm_sec);
break;
case TIME_FORMAT_SNMP: /* See "DateAndTime" in mibs/ietf/SNMPv2-TC */
t.tm_year += YEAR0;
buf[0] = t.tm_year >> 8;
buf[1] = t.tm_year & 0xff;
buf[2] = t.tm_mon;
buf[3] = t.tm_mday;
buf[4] = t.tm_hour;
buf[5] = t.tm_min;
buf[6] = t.tm_sec;
buf[7] = 0;
/* we stop here, no time zone. Size is 8 */
break;
}
return buf;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment