diff --git a/epan/dissectors/asn1/lte-rrc/lte-rrc.cnf b/epan/dissectors/asn1/lte-rrc/lte-rrc.cnf index 819688c10b..601afdf2d7 100644 --- a/epan/dissectors/asn1/lte-rrc/lte-rrc.cnf +++ b/epan/dissectors/asn1/lte-rrc/lte-rrc.cnf @@ -1044,7 +1044,7 @@ SystemInformationBlockType16-r11/timeInfo-r11/localTimeOffset-r11 DISPLAY=BASE_C #.FN_FTR SystemInformationBlockType16-r11/timeInfo-r11/timeInfoUTC-r11 subtree = proto_item_add_subtree(actx->created_item, ett_lte_rrc_timeInfo); - ts.secs = (time_t)(timeInfo/100)-2208988800U; /* epoch is 00:00:00 (midnight) UTC on 1900-01-01 */ + ts.secs = (time_t)(timeInfo/100)-EPOCH_DELTA_1900_01_01_00_00_00_UTC; /* epoch is 00:00:00 (midnight) UTC on 1900-01-01 */ ts.nsecs = (int)(timeInfo%100)*10000000; proto_tree_add_time(subtree, hf_lte_rrc_utc_time, tvb, old_offset>>3, (old_offset&0x07) ? 6 : 5, &ts); proto_tree_add_time(subtree, hf_lte_rrc_local_time, tvb, old_offset>>3, (old_offset&0x07) ? 6 : 5, &ts); diff --git a/epan/dissectors/asn1/lte-rrc/packet-lte-rrc-template.c b/epan/dissectors/asn1/lte-rrc/packet-lte-rrc-template.c index 33d4d7201e..7103851c5a 100644 --- a/epan/dissectors/asn1/lte-rrc/packet-lte-rrc-template.c +++ b/epan/dissectors/asn1/lte-rrc/packet-lte-rrc-template.c @@ -26,6 +26,7 @@ #include #include +#include #include "packet-per.h" #include "packet-rrc.h" diff --git a/epan/dissectors/asn1/nr-rrc/nr-rrc.cnf b/epan/dissectors/asn1/nr-rrc/nr-rrc.cnf index af4906dcd3..c4050bc23d 100644 --- a/epan/dissectors/asn1/nr-rrc/nr-rrc.cnf +++ b/epan/dissectors/asn1/nr-rrc/nr-rrc.cnf @@ -702,7 +702,7 @@ SIB8/messageIdentifier TYPE=FT_UINT16 DISPLAY=BASE_DEC|BASE_EXT_STRING STRINGS=& #.FN_FTR SIB9/timeInfo/timeInfoUTC subtree = proto_item_add_subtree(actx->created_item, ett_nr_rrc_timeInfo); - ts.secs = (time_t)(timeInfo/100)-2208988800U; /* epoch is 00:00:00 (midnight) UTC on 1900-01-01 */ + ts.secs = (time_t)(timeInfo/100)-EPOCH_DELTA_1900_01_01_00_00_00_UTC; /* epoch is 00:00:00 (midnight) UTC on 1900-01-01 */ ts.nsecs = (int)(timeInfo%100)*10000000; proto_tree_add_time(subtree, hf_nr_rrc_utc_time, tvb, old_offset>>3, (old_offset&0x07) ? 6 : 5, &ts); proto_tree_add_time(subtree, hf_nr_rrc_local_time, tvb, old_offset>>3, (old_offset&0x07) ? 6 : 5, &ts); diff --git a/epan/dissectors/asn1/nr-rrc/packet-nr-rrc-template.c b/epan/dissectors/asn1/nr-rrc/packet-nr-rrc-template.c index 72c0d16091..2876ac62d6 100644 --- a/epan/dissectors/asn1/nr-rrc/packet-nr-rrc-template.c +++ b/epan/dissectors/asn1/nr-rrc/packet-nr-rrc-template.c @@ -24,6 +24,7 @@ #include #include +#include #include "packet-per.h" #include "packet-gsm_map.h" diff --git a/epan/dissectors/packet-lte-rrc.c b/epan/dissectors/packet-lte-rrc.c index 2f2aa242ed..f1a72b0fc7 100644 --- a/epan/dissectors/packet-lte-rrc.c +++ b/epan/dissectors/packet-lte-rrc.c @@ -34,6 +34,7 @@ #include #include +#include #include "packet-per.h" #include "packet-rrc.h" @@ -293,7 +294,7 @@ typedef enum _SI_OrPSI_GERAN_enum { } SI_OrPSI_GERAN_enum; /*--- End of included file: packet-lte-rrc-val.h ---*/ -#line 73 "./asn1/lte-rrc/packet-lte-rrc-template.c" +#line 74 "./asn1/lte-rrc/packet-lte-rrc-template.c" /* Initialize the protocol and registered fields */ static int proto_lte_rrc = -1; @@ -7646,7 +7647,7 @@ static int hf_lte_rrc_carrierFreq_r14 = -1; /* CarrierFreq_NB_r13 */ static int dummy_hf_lte_rrc_eag_field = -1; /* never registered */ /*--- End of included file: packet-lte-rrc-hf.c ---*/ -#line 78 "./asn1/lte-rrc/packet-lte-rrc-template.c" +#line 79 "./asn1/lte-rrc/packet-lte-rrc-template.c" static int hf_lte_rrc_eutra_cap_feat_group_ind_1 = -1; static int hf_lte_rrc_eutra_cap_feat_group_ind_2 = -1; @@ -11138,7 +11139,7 @@ static gint ett_lte_rrc_SCPTM_NeighbourCellList_NB_r14 = -1; static gint ett_lte_rrc_PCI_ARFCN_NB_r14 = -1; /*--- End of included file: packet-lte-rrc-ett.c ---*/ -#line 272 "./asn1/lte-rrc/packet-lte-rrc-template.c" +#line 273 "./asn1/lte-rrc/packet-lte-rrc-template.c" static gint ett_lte_rrc_featureGroupIndicators = -1; static gint ett_lte_rrc_featureGroupIndRel9Add = -1; @@ -59835,7 +59836,7 @@ dissect_lte_rrc_T_timeInfoUTC_r11(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t subtree = proto_item_add_subtree(actx->created_item, ett_lte_rrc_timeInfo); - ts.secs = (time_t)(timeInfo/100)-2208988800U; /* epoch is 00:00:00 (midnight) UTC on 1900-01-01 */ + ts.secs = (time_t)(timeInfo/100)-EPOCH_DELTA_1900_01_01_00_00_00_UTC; /* epoch is 00:00:00 (midnight) UTC on 1900-01-01 */ ts.nsecs = (int)(timeInfo%100)*10000000; proto_tree_add_time(subtree, hf_lte_rrc_utc_time, tvb, old_offset>>3, (old_offset&0x07) ? 6 : 5, &ts); proto_tree_add_time(subtree, hf_lte_rrc_local_time, tvb, old_offset>>3, (old_offset&0x07) ? 6 : 5, &ts); @@ -111653,7 +111654,7 @@ static int dissect_UE_RadioPagingInfo_NB_r13_PDU(tvbuff_t *tvb _U_, packet_info /*--- End of included file: packet-lte-rrc-fn.c ---*/ -#line 3182 "./asn1/lte-rrc/packet-lte-rrc-template.c" +#line 3183 "./asn1/lte-rrc/packet-lte-rrc-template.c" static int dissect_lte_rrc_DL_CCCH(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) @@ -141401,7 +141402,7 @@ void proto_register_lte_rrc(void) { "CarrierFreq_NB_r13", HFILL }}, /*--- End of included file: packet-lte-rrc-hfarr.c ---*/ -#line 3557 "./asn1/lte-rrc/packet-lte-rrc-template.c" +#line 3558 "./asn1/lte-rrc/packet-lte-rrc-template.c" { &hf_lte_rrc_eutra_cap_feat_group_ind_1, { "Indicator 1", "lte-rrc.eutra_cap_feat_group_ind_1", @@ -145458,7 +145459,7 @@ void proto_register_lte_rrc(void) { &ett_lte_rrc_PCI_ARFCN_NB_r14, /*--- End of included file: packet-lte-rrc-ettarr.c ---*/ -#line 4316 "./asn1/lte-rrc/packet-lte-rrc-template.c" +#line 4317 "./asn1/lte-rrc/packet-lte-rrc-template.c" &ett_lte_rrc_featureGroupIndicators, &ett_lte_rrc_featureGroupIndRel9Add, @@ -145592,7 +145593,7 @@ void proto_register_lte_rrc(void) { /*--- End of included file: packet-lte-rrc-dis-reg.c ---*/ -#line 4411 "./asn1/lte-rrc/packet-lte-rrc-template.c" +#line 4412 "./asn1/lte-rrc/packet-lte-rrc-template.c" lte_rrc_etws_cmas_dcs_hash = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), g_direct_hash, g_direct_equal); lte_rrc_system_info_value_changed_hash = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), g_direct_hash, g_direct_equal); diff --git a/epan/dissectors/packet-nr-rrc.c b/epan/dissectors/packet-nr-rrc.c index 5c6c1c02f4..4aa7760b4e 100644 --- a/epan/dissectors/packet-nr-rrc.c +++ b/epan/dissectors/packet-nr-rrc.c @@ -32,6 +32,7 @@ #include #include +#include #include "packet-per.h" #include "packet-gsm_map.h" @@ -245,7 +246,7 @@ typedef enum _T_targetRAT_Type_enum { } T_targetRAT_Type_enum; /*--- End of included file: packet-nr-rrc-val.h ---*/ -#line 58 "./asn1/nr-rrc/packet-nr-rrc-template.c" +#line 59 "./asn1/nr-rrc/packet-nr-rrc-template.c" /* Initialize the protocol and registered fields */ static int proto_nr_rrc = -1; @@ -3254,7 +3255,7 @@ static int hf_nr_rrc_overheatingIndicationProhibitTimer = -1; /* T_overheatingI static int dummy_hf_nr_rrc_eag_field = -1; /* never registered */ /*--- End of included file: packet-nr-rrc-hf.c ---*/ -#line 62 "./asn1/nr-rrc/packet-nr-rrc-template.c" +#line 63 "./asn1/nr-rrc/packet-nr-rrc-template.c" static int hf_nr_rrc_serialNumber_gs = -1; static int hf_nr_rrc_serialNumber_msg_code = -1; static int hf_nr_rrc_serialNumber_upd_nb = -1; @@ -4530,7 +4531,7 @@ static gint ett_nr_rrc_T_overheatingAssistanceConfig = -1; static gint ett_nr_rrc_OverheatingAssistanceConfig = -1; /*--- End of included file: packet-nr-rrc-ett.c ---*/ -#line 98 "./asn1/nr-rrc/packet-nr-rrc-template.c" +#line 99 "./asn1/nr-rrc/packet-nr-rrc-template.c" static gint ett_nr_rrc_DedicatedNAS_Message = -1; static gint ett_rr_rrc_targetRAT_MessageContainer = -1; static gint ett_nr_rrc_nas_Container = -1; @@ -11254,7 +11255,7 @@ dissect_nr_rrc_T_timeInfoUTC(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx subtree = proto_item_add_subtree(actx->created_item, ett_nr_rrc_timeInfo); - ts.secs = (time_t)(timeInfo/100)-2208988800U; /* epoch is 00:00:00 (midnight) UTC on 1900-01-01 */ + ts.secs = (time_t)(timeInfo/100)-EPOCH_DELTA_1900_01_01_00_00_00_UTC; /* epoch is 00:00:00 (midnight) UTC on 1900-01-01 */ ts.nsecs = (int)(timeInfo%100)*10000000; proto_tree_add_time(subtree, hf_nr_rrc_utc_time, tvb, old_offset>>3, (old_offset&0x07) ? 6 : 5, &ts); proto_tree_add_time(subtree, hf_nr_rrc_local_time, tvb, old_offset>>3, (old_offset&0x07) ? 6 : 5, &ts); @@ -44429,7 +44430,7 @@ static int dissect_UECapabilityEnquiry_v1560_IEs_PDU(tvbuff_t *tvb _U_, packet_i /*--- End of included file: packet-nr-rrc-fn.c ---*/ -#line 380 "./asn1/nr-rrc/packet-nr-rrc-template.c" +#line 381 "./asn1/nr-rrc/packet-nr-rrc-template.c" void proto_register_nr_rrc(void) { @@ -56438,7 +56439,7 @@ proto_register_nr_rrc(void) { NULL, HFILL }}, /*--- End of included file: packet-nr-rrc-hfarr.c ---*/ -#line 388 "./asn1/nr-rrc/packet-nr-rrc-template.c" +#line 389 "./asn1/nr-rrc/packet-nr-rrc-template.c" { &hf_nr_rrc_serialNumber_gs, { "Geographical Scope", "nr-rrc.serialNumber.gs", @@ -57812,7 +57813,7 @@ proto_register_nr_rrc(void) { &ett_nr_rrc_OverheatingAssistanceConfig, /*--- End of included file: packet-nr-rrc-ettarr.c ---*/ -#line 522 "./asn1/nr-rrc/packet-nr-rrc-template.c" +#line 523 "./asn1/nr-rrc/packet-nr-rrc-template.c" &ett_nr_rrc_DedicatedNAS_Message, &ett_rr_rrc_targetRAT_MessageContainer, &ett_nr_rrc_nas_Container, @@ -57874,7 +57875,7 @@ proto_register_nr_rrc(void) { /*--- End of included file: packet-nr-rrc-dis-reg.c ---*/ -#line 565 "./asn1/nr-rrc/packet-nr-rrc-template.c" +#line 566 "./asn1/nr-rrc/packet-nr-rrc-template.c" nr_rrc_etws_cmas_dcs_hash = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), g_direct_hash, g_direct_equal); diff --git a/epan/dissectors/packet-ntp.c b/epan/dissectors/packet-ntp.c index 68762e50e3..256582e37c 100644 --- a/epan/dissectors/packet-ntp.c +++ b/epan/dissectors/packet-ntp.c @@ -21,6 +21,8 @@ #include #include +#include + #include "packet-ntp.h" void proto_register_ntp(void); @@ -1011,8 +1013,11 @@ static const int *ntppriv_reset_stats_flags[] = { static tvbparse_wanted_t *want; static tvbparse_wanted_t *want_ignore; -/* NTP_BASETIME is in fact epoch - ntp_start_time */ -#define NTP_BASETIME 2208988800u +/* + * NTP_BASETIME is in fact epoch - ntp_start_time; ntp_start_time + * is January 1, 2036, 00:00:00 UTC. + */ +#define NTP_BASETIME EPOCH_DELTA_1900_01_01_00_00_00_UTC #define NTP_FLOAT_DENOM 4294967296.0 #define NTP_TS_SIZE 100 diff --git a/epan/dissectors/packet-tds.c b/epan/dissectors/packet-tds.c index 7e6a7a4a6d..acac96afe0 100644 --- a/epan/dissectors/packet-tds.c +++ b/epan/dissectors/packet-tds.c @@ -143,6 +143,8 @@ #include #include +#include + #include #include "packet-tcp.h" @@ -2030,7 +2032,7 @@ handle_tds_sql_datetime(tvbuff_t *tvb, guint offset, proto_tree *sub_tree, tds_c days = threehndths = 0; } - tv.secs = (time_t)((days * G_GUINT64_CONSTANT(86400)) + (threehndths/300) - G_GUINT64_CONSTANT(2208988800)); /* 2208988800 - seconds between Jan 1, 1900 and Jan 1, 1970 */ + tv.secs = (time_t)((days * G_GUINT64_CONSTANT(86400)) + (threehndths/300) - EPOCH_DELTA_1900_01_01_00_00_00_UTC); /* seconds between Jan 1, 1900 and Jan 1, 1970 */ tv.nsecs = (int)((threehndths%300) * 10000000 / 3); proto_tree_add_time(sub_tree, hf_tds_type_varbyte_data_absdatetime, tvb, offset, 8, &tv); } @@ -2058,7 +2060,7 @@ handle_tds_sql_smalldatetime(tvbuff_t *tvb, guint offset, proto_tree *sub_tree, } - tv.secs = (time_t)((days * G_GUINT64_CONSTANT(86400)) + (minutes * 60) - G_GUINT64_CONSTANT(2208988800)); /* 2208988800 - seconds between Jan 1, 1900 and Jan 1, 1970 */ + tv.secs = (time_t)((days * G_GUINT64_CONSTANT(86400)) + (minutes * 60) - EPOCH_DELTA_1900_01_01_00_00_00_UTC); /* seconds between Jan 1, 1900 and Jan 1, 1970 */ tv.nsecs = 0; proto_tree_add_time(sub_tree, hf_tds_type_varbyte_data_absdatetime, tvb, offset, 8, &tv); } diff --git a/epan/dissectors/packet-time.c b/epan/dissectors/packet-time.c index 2521fbd14b..a3426c7bf0 100644 --- a/epan/dissectors/packet-time.c +++ b/epan/dissectors/packet-time.c @@ -18,6 +18,8 @@ #include #include +#include + void proto_reg_handoff_time(void); void proto_register_time(void); @@ -63,7 +65,7 @@ dissect_time(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ guint32 delta_seconds = tvb_get_ntohl(tvb, 0); proto_tree_add_uint_format(time_tree, hf_time_time, tvb, 0, 4, delta_seconds, "%s", - abs_time_secs_to_str(wmem_packet_scope(), delta_seconds-2208988800U, + abs_time_secs_to_str(wmem_packet_scope(), delta_seconds-EPOCH_DELTA_1900_01_01_00_00_00_UTC, (absolute_time_display_e)time_display_type, TRUE)); } return tvb_captured_length(tvb); diff --git a/epan/proto.c b/epan/proto.c index cbd7c35f6c..1a6bfeac4b 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -47,6 +47,7 @@ #include /* ws_debug_printf */ #include +#include /* Ptvcursor limits */ #define SUBTREE_ONCE_ALLOCATION_NUMBER 8 @@ -1782,6 +1783,8 @@ get_stringzpad_value(wmem_allocator_t *scope, tvbuff_t *tvb, gint start, /* * NTP Era 0: the epoch is January 1, 1900, 00:00:00 (proleptic?) UTC. + * XXX - if it's OK if this is unsigned, can we just use + * EPOCH_DELTA_1900_01_01_00_00_00_UTC? */ #define NTP_TIMEDIFF1900TO1970SEC G_GINT64_CONSTANT(2208988800) @@ -1790,17 +1793,6 @@ get_stringzpad_value(wmem_allocator_t *scope, tvbuff_t *tvb, gint start, */ #define NTP_TIMEDIFF1970TO2036SEC G_GINT64_CONSTANT(2085978496) -/* - * System/370, System/390, and z/Architecture TOD clock: the epoch - * is January 1, 1900, 00:00:00 (proleptic?) UTC. - */ -#define TOD_BASETIME G_GUINT64_CONSTANT(2208988800) - -/* - * Classic Mac OS: the epoch is January 1, 1904, 00:00:00 (proleptic?) UTC. - */ -#define CLASSIC_MAC_OS_BASETIME G_GUINT64_CONSTANT(2082844800) - /* this can be called when there is no tree, so tree may be null */ static void get_time_value(proto_tree *tree, tvbuff_t *tvb, const gint start, @@ -1996,7 +1988,9 @@ get_time_value(proto_tree *tree, tvbuff_t *tvb, const gint start, case ENC_TIME_TOD|ENC_BIG_ENDIAN: /* * S/3x0 and z/Architecture TOD clock time stamp, - * big-endian. + * big-endian. The epoch is January 1, 1900, + * 00:00:00 (proleptic?) UTC. + * * Only supported for absolute times. */ DISSECTOR_ASSERT(!is_relative); @@ -2004,7 +1998,7 @@ get_time_value(proto_tree *tree, tvbuff_t *tvb, const gint start, if (length == 8) { todusecs = tvb_get_ntoh64(tvb, start) >> 12; - time_stamp->secs = (time_t)((todusecs / 1000000) - TOD_BASETIME); + time_stamp->secs = (time_t)((todusecs / 1000000) - EPOCH_DELTA_1900_01_01_00_00_00_UTC); time_stamp->nsecs = (int)((todusecs % 1000000) * 1000); } else { time_stamp->secs = 0; @@ -2016,14 +2010,16 @@ get_time_value(proto_tree *tree, tvbuff_t *tvb, const gint start, case ENC_TIME_TOD|ENC_LITTLE_ENDIAN: /* * S/3x0 and z/Architecture TOD clock time stamp, - * little-endian. + * little-endian. The epoch is January 1, 1900, + * 00:00:00 (proleptic?) UTC. + * * Only supported for absolute times. */ DISSECTOR_ASSERT(!is_relative); if (length == 8) { todusecs = tvb_get_letoh64(tvb, start) >> 12 ; - time_stamp->secs = (time_t)((todusecs / 1000000) - TOD_BASETIME); + time_stamp->secs = (time_t)((todusecs / 1000000) - EPOCH_DELTA_1900_01_01_00_00_00_UTC); time_stamp->nsecs = (int)((todusecs % 1000000) * 1000); } else { time_stamp->secs = 0; @@ -2358,11 +2354,11 @@ get_time_value(proto_tree *tree, tvbuff_t *tvb, const gint start, if (length == 8) { tmp64secs = tvb_get_ntoh64(tvb, start); - time_stamp->secs = (time_t)(tmp64secs - CLASSIC_MAC_OS_BASETIME); + time_stamp->secs = (time_t)(tmp64secs - EPOCH_DELTA_1904_01_01_00_00_00_UTC); time_stamp->nsecs = 0; } else if (length == 4) { tmpsecs = tvb_get_ntohl(tvb, start); - time_stamp->secs = (time_t)(tmpsecs - CLASSIC_MAC_OS_BASETIME); + time_stamp->secs = (time_t)(tmpsecs - EPOCH_DELTA_1904_01_01_00_00_00_UTC); time_stamp->nsecs = 0; } else { time_stamp->secs = 0; diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c index 78ba318ab0..bc9f70bb3b 100644 --- a/wiretap/peekclassic.c +++ b/wiretap/peekclassic.c @@ -24,9 +24,13 @@ #include "config.h" #include #include + +#include + #include "wtap-int.h" #include "file_wrappers.h" #include "peekclassic.h" + /* CREDITS * * This file decoder could not have been writen without examining how @@ -130,8 +134,6 @@ typedef struct peekclassic_utime { #define STATUS_SLICED 0x20 /* Sliced (cut short by snaplen?) */ #define STATUS_HIDDEN 0x80 /* Hidden (in the *Peek GUI?) */ -static const unsigned int mac2unix = 2082844800u; - typedef struct { time_t reference_time; } peekclassic_t; @@ -298,7 +300,7 @@ wtap_open_return_val peekclassic_open(wtap *wth, int *err, gchar **err_info) g_ntohl(ep_hdr.secondary.v567.linkSpeed); /* Get the reference time as a time_t */ - reference_time = ep_hdr.secondary.v567.timeDate - mac2unix; + reference_time = ep_hdr.secondary.v567.timeDate - EPOCH_DELTA_1904_01_01_00_00_00_UTC; break; default: @@ -436,7 +438,7 @@ static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh, rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN|WTAP_HAS_PACK_FLAGS; tsecs = (time_t) (timestamp/1000000); tusecs = (guint32) (timestamp - tsecs*1000000); - rec->ts.secs = tsecs - mac2unix; + rec->ts.secs = tsecs - EPOCH_DELTA_1904_01_01_00_00_00_UTC; rec->ts.nsecs = tusecs * 1000; rec->rec_header.packet_header.len = length; rec->rec_header.packet_header.caplen = sliceLength; diff --git a/writecap/pcapio.c b/writecap/pcapio.c index f071672afa..4f48ac80c8 100644 --- a/writecap/pcapio.c +++ b/writecap/pcapio.c @@ -41,6 +41,8 @@ #include +#include + #include "pcapio.h" /* Magic numbers in "libpcap" files. @@ -655,7 +657,7 @@ pcapng_write_interface_statistics_block(FILE* pfile, * Subtract difference, in microseconds, between January 1, 1601 * 00:00:00 UTC and January 1, 1970, 00:00:00 UTC. */ - timestamp -= G_GUINT64_CONSTANT(11644473600000000); + timestamp -= EPOCH_DELTA_1601_01_01_00_00_00_UTC*1000000; #else /* * Current time, represented as seconds and microseconds since diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index c7d017cf7b..1e1e453e2b 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -34,6 +34,7 @@ set(WSUTIL_PUBLIC_HEADERS crc32.h curve25519.h eax.h + epochs.h filesystem.h frequency-utils.h g711.h diff --git a/wsutil/epochs.h b/wsutil/epochs.h new file mode 100644 index 0000000000..c6f28cea6a --- /dev/null +++ b/wsutil/epochs.h @@ -0,0 +1,57 @@ +/* epochs.h + * Definitions of epoch values for various absolute time types. + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 2006 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __EPOCHS_H__ +#define __EPOCHS_H__ + +#include + +/* + * Deltas between the epochs for various non-UN*X time stamp formats and + * the January 1, 1970, 00:00:00 (proleptic?) UTC epoch for the UN*X time + * stamp format. + */ + +/* + * 1900-01-01 00:00:00 (proleptic?) UTC. + * Used by a number of time formats. + */ +#define EPOCH_DELTA_1900_01_01_00_00_00_UTC 2208988800U + +/* + * 1904-01-01 00:00:00 (proleptic?) UTC. + * Used in the classic Mac OS, and by formats, such as MPEG-4 Part 14 (MP4), + * which is based on Apple's QuickTime format. + */ +#define EPOCH_DELTA_1904_01_01_00_00_00_UTC 2082844800U + +/* + * 1601-01-01 (proleptic Gregorian) 00:00:00 (proleptic?) UTC. + * The Windows NT epoch, used in a number of places. + * + * This is + * + * 369*365.25*24*60*60-(3*24*60*60+6*60*60) + * + * 1970-1601 is 369; 365.25 is the average length of a year in days, + * including leap years. + * + * 3 days are subtracted because 1700, 1800, and 1900 were not leap + * years, as, while they're all evenly divisible by 4, they're also + * evently divisible by 100, but not evently divisible by 400, so + * we need to compensate for using the average length of a year in + * days, which assumes a leap year every 4 years, *including* every + * 100 years. + * + * I'm not sure what the extra 6 hours are that are being subtracted. + */ +#define EPOCH_DELTA_1601_01_01_00_00_00_UTC G_GUINT64_CONSTANT(11644473600) + +#endif /* __EPOCHS_H__ */ diff --git a/wsutil/nstime.c b/wsutil/nstime.c index 456530a5e3..2b2020d340 100644 --- a/wsutil/nstime.c +++ b/wsutil/nstime.c @@ -12,6 +12,7 @@ #include #include "nstime.h" +#include "epochs.h" /* this is #defined so that we can clearly see that we have the right number of zeros, rather than as a guard against the number of nanoseconds in a second @@ -182,29 +183,6 @@ double nstime_to_sec(const nstime_t *nstime) * Copyright (C) Andrew Tridgell 1992-1998 */ -/* - * Number of seconds between the UN*X epoch (January 1, 1970, 00:00:00 GMT) - * and the Windows NT epoch (January 1, 1601 in the proleptic Gregorian - * calendar, 00:00:00 "GMT") - * - * This is - * - * 369*365.25*24*60*60-(3*24*60*60+6*60*60) - * - * 1970-1601 is 369; 365.25 is the average length of a year in days, - * including leap years. - * - * 3 days are subtracted because 1700, 1800, and 1900 were not leap - * years, as, while they're all evenly divisible by 4, they're also - * evently divisible by 100, but not evently divisible by 400, so - * we need to compensate for using the average length of a year in - * days, which assumes a leap year every 4 years, *including* every - * 100 years. - * - * I'm not sure what the extra 6 hours are that are being subtracted. - */ -#define TIME_FIXUP_CONSTANT G_GUINT64_CONSTANT(11644473600) - #ifndef TIME_T_MIN #define TIME_T_MIN ((time_t) ((time_t)0 < (time_t) -1 ? (time_t) 0 \ : (time_t) (~0ULL << (sizeof (time_t) * CHAR_BIT - 1)))) @@ -223,11 +201,11 @@ common_filetime_to_nstime(nstime_t *nstime, guint64 ftsecs, int nsecs) * ftsecs's value should fit in a 64-bit signed variable, as * ftsecs is derived from a 64-bit fractions-of-a-second value, * and is far from the maximum 64-bit signed value, and - * TIME_FIXUP_CONSTANT is also far from the maximum 64-bit - * signed value, so the difference between them should also - * fit in a 64-bit signed value. + * EPOCH_DELTA_1601_01_01_00_00_00_UTC is also far from the + * maximum 64-bit signed value, so the difference between them + * should also fit in a 64-bit signed value. */ - secs = (gint64)ftsecs - TIME_FIXUP_CONSTANT; + secs = (gint64)ftsecs - EPOCH_DELTA_1601_01_01_00_00_00_UTC; if (!(TIME_T_MIN <= secs && secs <= TIME_T_MAX)) { /* The result won't fit in a time_t */ diff --git a/wsutil/time_util.c b/wsutil/time_util.c index 32cbc81a85..98df723a9b 100644 --- a/wsutil/time_util.c +++ b/wsutil/time_util.c @@ -12,6 +12,8 @@ #include +#include + #include "time_util.h" #ifndef _WIN32 @@ -147,7 +149,7 @@ create_timestamp(void) { * Subtract difference, in microseconds, between January 1, 1601 * 00:00:00 UTC and January 1, 1970, 00:00:00 UTC. */ - timestamp -= G_GUINT64_CONSTANT(11644473600000000); + timestamp -= EPOCH_DELTA_1601_01_01_00_00_00_UTC*1000000; #else /* * Current time, represented as seconds and microseconds since