btfak / sntp Goto Github PK
View Code? Open in Web Editor NEWA implementation of NTP server,RFC2030
A implementation of NTP server,RFC2030
如题!
NTP client only gets the time of the server, and does not process the time through NTP protocol
// generate
/*
Field Name Request Reply
----------------------------------------------------------
LI 0 or 3 0
VN 1-4 copied from request
Mode 3 4
Stratum ignore 1
Poll ignore copied from request
Precision ignore -log2 server significant bits
Root Delay ignore 0
Root Dispersion ignore 0
Reference Identifier ignore source ident
Reference Timestamp ignore time of last radio update
Originate Timestamp ignore copied from transmit timestamp
Receive Timestamp ignore time of day
Transmit Timestamp (see text) time of day
*/
func generate(req []byte) []byte {
var second = unix2ntp(time.Now().Unix())
var fraction = unix2ntp(int64(time.Now().Nanosecond()))
var res = make([]byte, 48)
var vn = req[0] & 0x38
res[0] = vn + 4
res[1] = 1
res[2] = req[2]
res[3] = 0xEC
res[12] = 0x4E
res[13] = 0x49
res[14] = 0x43
res[15] = 0x54
copy(res[16:20], int2bytes(second)[0:])
copy(res[24:32], req[40:48])
copy(res[32:36], int2bytes(second)[0:])
copy(res[36:40], int2bytes(fraction)[0:])
copy(res[40:48], res[32:40])
return res
}
44-48这几个字节数放的是纳秒数,为什么通过函数unix2ntp增加一个时间呢,40-44保存了秒数,44-48保存纳秒不就可以了么?
func int2bytes(i int64) []byte 这个函数把int64 8个字节的数据放在4个字节的byte数组里面放得下么?
还有就是这个库现在稳定么?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.