Pretify dissection of date and Time.

svn path=/trunk/; revision=49905
This commit is contained in:
Anders Broman 2013-06-12 15:08:08 +00:00
parent 6de25d3897
commit 82e220f2bd
4 changed files with 191 additions and 9 deletions

View File

@ -364,6 +364,91 @@ dissect_snmp_variable_string(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *
return tvb_length(tvb);
}
/*
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))
*/
static proto_item *
dissect_snmp_variable_date_and_time(proto_tree *tree,int hfid, tvbuff_t *tvb, int offset, int length)
{
guint16 year;
guint8 month;
guint8 day;
guint8 hour;
guint8 minutes;
guint8 seconds;
guint8 deci_seconds;
guint8 hour_from_utc;
guint8 min_from_utc;
gchar *str;
year = tvb_get_ntohs(tvb,offset);
month = tvb_get_guint8(tvb,offset+2);
day = tvb_get_guint8(tvb,offset+3);
hour = tvb_get_guint8(tvb,offset+4);
minutes = tvb_get_guint8(tvb,offset+5);
seconds = tvb_get_guint8(tvb,offset+6);
deci_seconds = tvb_get_guint8(tvb,offset+7);
if(length > 8){
hour_from_utc = tvb_get_guint8(tvb,offset+9);
min_from_utc = tvb_get_guint8(tvb,offset+10);
str = ep_strdup_printf("%u-%u-%u, %u:%u:%u.%u UTC %s%u:%u",
year,
month,
day,
hour,
minutes,
seconds,
deci_seconds,
tvb_get_ephemeral_string(tvb,offset+8,1),
hour_from_utc,
min_from_utc);
}else{
str = ep_strdup_printf("%u-%u-%u, %u:%u:%u.%u",
year,
month,
day,
hour,
minutes,
seconds,
deci_seconds);
}
return proto_tree_add_string(tree, hfid, tvb, offset, length, str);
}
/*
* dissect_snmp_VarBind
* this routine dissects variable bindings, looking for the oid information in our oid reporsitory
@ -835,7 +920,7 @@ indexing_done:
goto already_added;
}
case BER_CLASS_UNI|(BER_UNI_TAG_OCTETSTRING<<4):
if((oid_info->value_hfid> -1)&& (oid_info->value_type->keytype == OID_KEY_TYPE_STRING)){
if(oid_info->value_hfid> -1){
hfid = oid_info->value_hfid;
}else{
hfid = hf_snmp_octetstring_value;
@ -926,7 +1011,12 @@ indexing_done:
goto already_added;
}
}
pi_value = proto_tree_add_item(pt_varbind,hfid,tvb,value_offset,value_len,ENC_BIG_ENDIAN);
/* Special case DATE AND TIME */
if((oid_info->value_type)&&(oid_info->value_type->keytype == OID_KEY_TYPE_DATE_AND_TIME)&&(value_len > 7)){
pi_value = dissect_snmp_variable_date_and_time(pt_varbind, hfid, tvb, value_offset, value_len);
}else{
pi_value = proto_tree_add_item(pt_varbind,hfid,tvb,value_offset,value_len,ENC_BIG_ENDIAN);
}
if (format_error != BER_NO_ERROR) {
expert_add_info(actx->pinfo, pi_value, &ei_snmp_missing_mib);
}

View File

@ -466,6 +466,91 @@ dissect_snmp_variable_string(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *
return tvb_length(tvb);
}
/*
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))
*/
static proto_item *
dissect_snmp_variable_date_and_time(proto_tree *tree,int hfid, tvbuff_t *tvb, int offset, int length)
{
guint16 year;
guint8 month;
guint8 day;
guint8 hour;
guint8 minutes;
guint8 seconds;
guint8 deci_seconds;
guint8 hour_from_utc;
guint8 min_from_utc;
gchar *str;
year = tvb_get_ntohs(tvb,offset);
month = tvb_get_guint8(tvb,offset+2);
day = tvb_get_guint8(tvb,offset+3);
hour = tvb_get_guint8(tvb,offset+4);
minutes = tvb_get_guint8(tvb,offset+5);
seconds = tvb_get_guint8(tvb,offset+6);
deci_seconds = tvb_get_guint8(tvb,offset+7);
if(length > 8){
hour_from_utc = tvb_get_guint8(tvb,offset+9);
min_from_utc = tvb_get_guint8(tvb,offset+10);
str = ep_strdup_printf("%u-%u-%u, %u:%u:%u.%u UTC %s%u:%u",
year,
month,
day,
hour,
minutes,
seconds,
deci_seconds,
tvb_get_ephemeral_string(tvb,offset+8,1),
hour_from_utc,
min_from_utc);
}else{
str = ep_strdup_printf("%u-%u-%u, %u:%u:%u.%u",
year,
month,
day,
hour,
minutes,
seconds,
deci_seconds);
}
return proto_tree_add_string(tree, hfid, tvb, offset, length, str);
}
/*
* dissect_snmp_VarBind
* this routine dissects variable bindings, looking for the oid information in our oid reporsitory
@ -937,7 +1022,7 @@ indexing_done:
goto already_added;
}
case BER_CLASS_UNI|(BER_UNI_TAG_OCTETSTRING<<4):
if((oid_info->value_hfid> -1)&& (oid_info->value_type->keytype == OID_KEY_TYPE_STRING)){
if(oid_info->value_hfid> -1){
hfid = oid_info->value_hfid;
}else{
hfid = hf_snmp_octetstring_value;
@ -1028,7 +1113,12 @@ indexing_done:
goto already_added;
}
}
pi_value = proto_tree_add_item(pt_varbind,hfid,tvb,value_offset,value_len,ENC_BIG_ENDIAN);
/* Special case DATE AND TIME */
if((oid_info->value_type)&&(oid_info->value_type->keytype == OID_KEY_TYPE_DATE_AND_TIME)&&(value_len > 7)){
pi_value = dissect_snmp_variable_date_and_time(pt_varbind, hfid, tvb, value_offset, value_len);
}else{
pi_value = proto_tree_add_item(pt_varbind,hfid,tvb,value_offset,value_len,ENC_BIG_ENDIAN);
}
if (format_error != BER_NO_ERROR) {
expert_add_info(actx->pinfo, pi_value, &ei_snmp_missing_mib);
}
@ -2894,7 +2984,7 @@ static void dissect_SMUX_PDUs_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, pro
/*--- End of included file: packet-snmp-fn.c ---*/
#line 1678 "../../asn1/snmp/packet-snmp-template.c"
#line 1768 "../../asn1/snmp/packet-snmp-template.c"
guint
@ -3820,7 +3910,7 @@ void proto_register_snmp(void) {
NULL, HFILL }},
/*--- End of included file: packet-snmp-hfarr.c ---*/
#line 2339 "../../asn1/snmp/packet-snmp-template.c"
#line 2429 "../../asn1/snmp/packet-snmp-template.c"
};
/* List of subtrees */
@ -3860,7 +3950,7 @@ void proto_register_snmp(void) {
&ett_snmp_RReqPDU_U,
/*--- End of included file: packet-snmp-ettarr.c ---*/
#line 2355 "../../asn1/snmp/packet-snmp-template.c"
#line 2445 "../../asn1/snmp/packet-snmp-template.c"
};
static ei_register_info ei[] = {
{ &ei_snmp_failed_decrypted_data_pdu, { "snmp.failed_decrypted_data_pdu", PI_MALFORMED, PI_WARN, "Failed to decrypt encryptedPDU", EXPFILL }},

View File

@ -81,6 +81,7 @@ static const oid_value_type_t float_type = { FT_FLOAT, BASE_DEC, BER_CLAS
static const oid_value_type_t double_type = { FT_DOUBLE, BASE_DEC, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 8, 8, OID_KEY_TYPE_WRONG, 0};
static const oid_value_type_t ether_type = { FT_ETHER, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 6, 6, OID_KEY_TYPE_ETHER, 6};
static const oid_value_type_t string_type = { FT_STRING, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 0, -1, OID_KEY_TYPE_STRING, 0};
static const oid_value_type_t date_and_time_type = { FT_STRING, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 8, 11, OID_KEY_TYPE_DATE_AND_TIME, 0};
static const oid_value_type_t unknown_type = { FT_BYTES, BASE_NONE, BER_CLASS_ANY, BER_TAG_ANY, 0, -1, OID_KEY_TYPE_WRONG, 0};
static oid_info_t oid_root = { 0, NULL, OID_KIND_UNKNOWN, NULL, &unknown_type, -2, NULL, NULL, NULL};
@ -304,7 +305,7 @@ static const oid_value_type_t* get_typedata(SmiType* smiType) {
{"TimeStamp",SMI_BASETYPE_UNKNOWN,&timeticks_type},
{"DisplayString",SMI_BASETYPE_UNKNOWN,&string_type},
{"SnmpAdminString",SMI_BASETYPE_UNKNOWN,&string_type},
{"DateAndTime",SMI_BASETYPE_UNKNOWN,&bytes_type},
{"DateAndTime",SMI_BASETYPE_UNKNOWN,&date_and_time_type},
{"Counter",SMI_BASETYPE_UNKNOWN,&counter32_type},
{"Counter32",SMI_BASETYPE_UNKNOWN,&counter32_type},
{"Unsigned32",SMI_BASETYPE_UNKNOWN,&unsigned32_type},

View File

@ -58,7 +58,8 @@ typedef enum _oid_key_type_t {
OID_KEY_TYPE_IMPLIED_OID,
OID_KEY_TYPE_IMPLIED_STRING,
OID_KEY_TYPE_IMPLIED_BYTES,
OID_KEY_TYPE_ETHER
OID_KEY_TYPE_ETHER,
OID_KEY_TYPE_DATE_AND_TIME
} oid_key_type_t;
typedef struct _oid_value_type_t {