LoginSignup
1
0

More than 5 years have passed since last update.

ntpの2036年

Last updated at Posted at 2019-03-20

NICTのjjyグループさんに以下のページがあります。

ntpの秒は1900年からの符号無し32bitなので、もうそんな遠くない将来にオーバーフローします。

Thu Feb 7 15:28:15 2036

最上位ビットが無くなったら、ここを始点とするというページの記載がありました。ちょっとロジックを追加してみました。

#include <stdio.h>
#include <time.h>
#include <stdint.h>

main() {
uint32_t ntptime;
time_t posixtime;

printf("time_t size = %d\n", sizeof(time_t));

ntptime = 0x7fffffff;

if (ntptime < 0x80000000)
    posixtime = (time_t)ntptime + 0x100000000ULL - 2208988800UL;
else
    posixtime = (time_t)ntptime - 2208988800UL;

printf("%s¥n", ctime(&posixtime));
}

32Bit環境でもtime_tが8バイトであればちゃんと動くはずです。

このロジックは

Tue Feb 26 18:42:23 2104

まで有効です。

とは言え2036年を過ぎたら徐々に外していくのが良いと思われます。

lwIPのsntpのサンプルにはこのロジックは入っていないようです。

2038年問題よりも先にこの問題がある事忘れてないですか?

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0