【问题标题】:SNMP convert string representing datetime to dateandtime octetstrSNMP 将表示日期时间的字符串转换为日期和时间 octetstr
【发布时间】:2022-12-20 02:16:23
【问题描述】:

我试图在 snmp 中发出日期时间, 据我了解,DateAndTime 字符串是一个 11 字节的字符串,代表这种格式的值:(1 个字母 -> 1 个字节)
y -> 年
米 -> 月
d -> 天
小时 -> 小时
M -> 分钟
s -> 第二
u -> 1/10 秒
^ -> + 或 - 用于时区偏移
H -> 时区偏移量(小时)
N -> 时区偏移量(分钟)

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';

如何将其转换为 SNMP++ OctetStr

【问题讨论】:

    标签: c++ snmp octetstring


    【解决方案1】:

    它不是“1 个字母 -> 1 个字节”。在定义https://www.rfc-editor.org/rfc/rfc2579.html 时给出的示例与“DISPLAY-HINT”对比中,有 11 个字节(可能是 8 个)并且没有“字母”。取而代之的是 1 个两字节十进制字段、8 个一字节十进制字段和 1 个 1 字节 ASCII 字段。共有 25 个字符,但您的结果可能会有所不同。:

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

    供参考的整个 RFC 部分以及两个相关的勘误表如下所示:

    . (这是目前的互联网标准,但自 ~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))
    

    请注意,此 RFC 有 2 个相关勘误表:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-17
      • 2011-09-08
      • 1970-01-01
      • 2022-08-18
      • 2014-04-23
      • 1970-01-01
      • 2017-05-20
      相关资源
      最近更新 更多