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