1、源码下载
http://doolittle.icarus.com/ntpclient/
代码结构
total 52
-rwx------ 1 root root 1286 May 7 15:44 Makefile
-rwx------ 1 root root 19817 Jan 1 2016 ntpclient.c
-rwx------ 1 root root 353 Dec 28 2010 ntpclient.h
-rwx------ 1 root root 11267 Dec 30 2015 phaselock.c
-rwx------ 1 root root 10431 Jan 1 2016 README
2、编译源码(aarch64-himix100-linux-gcc)
修改Makefile如下
# A long time ago, far, far away, under Solaris, you needed to
# CFLAGS += -xO2 -Xc
# LDLIBS += -lnsl -lsocket
# To cross-compile
CC = aarch64-himix100-linux-gcc
# To use clang
# CC = clang
# To check for lint
# CFLAGS += -Wpointer-arith -Wcast-align -Wcast-qual -Wshadow -Wundef \
# -Waggregate-return -Wnested-externs -Winline -Wwrite-strings \
# -Wstrict-prototypes -Wmissing-prototypes -pedantic
# This was old-school networking code, making the traditional cast between
# struct sockaddr* and struct sockaddr_in*. Thus a modern gcc needed:
#CFLAGS += -fno-strict-aliasing
# but as of ntpclient-2015, I cleaned up those casts enough to make both
# gcc-4.9.2 and clang-3.5.0 happy without it.
CFLAGS += -std=c99 # should also still work with -std=c89
CFLAGS += -D_POSIX_C_SOURCE=199309 -D_BSD_SOURCE
CFLAGS += -W -Wall # -W is spelled -Wextra these days, but -W is stilli
# valid and works with older compilers.
CFLAGS += -O2
CFLAGS += -DPRECISION_SIOCGSTAMP
CFLAGS += -DENABLE_DEBUG
CFLAGS += -DENABLE_REPLAY
CFLAGS += -DUSE_OBSOLETE_GETTIMEOFDAY
LOADLIBES += -lrt
all: ntpclient
test: ntpclient
./ntpclient -d -r <test.dat
ntpclient: ntpclient.o phaselock.o
ntpclient.o phaselock.o: ntpclient.h
clean:
rm -f ntpclient *.o
编译makefile,生成ntpclient
3、用法
Usage: ntpclient [options]
options:
-c count stop after count time measurements (default 0 means go forever)
-d print diagnostics (feature can be disabled at compile time)
-g goodness causes ntpclient to stop after getting a result more accurate
than goodness (microseconds, default 0 means go forever)
-h hostname (mandatory) NTP server, against which to measure system time
-i interval check time every interval seconds (default 600)
-l attempt to lock local clock to server using adjtimex(2)
-p port local NTP client UDP port (default 0 means "any available")
-q min_delay minimum packet delay for transaction (default 800 microseconds)
-r replay analysis code based on stdin
-s simple clock set (implies -c 1)
-t trust network and server, no RFC-4330 recommended cross-checks
./ntpclient -s -d -c 1 -i 5 -h 202.108.6.95