00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <time.h>
00019 #include <oasys/debug/Log.h>
00020
00021 #include "BundleTimestamp.h"
00022
00023 namespace dtn {
00024
00028 u_int32_t BundleTimestamp::TIMEVAL_CONVERSION = 946684800;
00029
00030 u_int32_t
00031 BundleTimestamp::get_current_time()
00032 {
00033 struct timeval now;
00034 ::gettimeofday(&now, 0);
00035
00036 ASSERT((u_int)now.tv_sec > TIMEVAL_CONVERSION);
00037 return now.tv_sec - TIMEVAL_CONVERSION;
00038 }
00039
00040 bool
00041 BundleTimestamp::check_local_clock()
00042 {
00043 struct timeval now;
00044 ::gettimeofday(&now, 0);
00045
00046 if ((u_int)now.tv_sec < TIMEVAL_CONVERSION) {
00047 logf("/dtn/bundle/timestamp", oasys::LOG_ERR,
00048 "invalid local clock setting: "
00049 "current time '%s' is before Jan 1, 2000",
00050 ctime((const time_t*)&now.tv_sec));
00051
00052 log_err_p("/dtn/bundle/timestamp",
00053 "invalid local clock setting: "
00054 "current time '%s' is before Jan 1, 2000",
00055 ctime((const time_t*)&now.tv_sec));
00056 return false;
00057 }
00058
00059 return true;
00060 }
00061 }