mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-18 23:54:49 +03:00
0af29f50c0
* UDP Test Increases UDP test timeout Pref exception Fix Add Minecraft Bedrock Edition Test * Optimization * Refactor * Rename
38 lines
798 B
C#
38 lines
798 B
C#
namespace ServiceLib.UdpTest.Tester;
|
|
|
|
public class NtpService : IUdpTest
|
|
{
|
|
private const int NtpDefaultPort = 123;
|
|
private const string NtpDefaultServer = "pool.ntp.org";
|
|
|
|
public byte[] BuildUdpRequestPacket()
|
|
{
|
|
var ntpReq = new byte[48];
|
|
ntpReq[0] = 0x23; // LI=0, VN=4, Mode=3
|
|
return ntpReq;
|
|
}
|
|
|
|
public bool VerifyAndExtractUdpResponse(byte[] ntpResponseBytes)
|
|
{
|
|
if (ntpResponseBytes.Length < 48)
|
|
{
|
|
return false;
|
|
}
|
|
if ((ntpResponseBytes[0] & 0x07) != 4)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public ushort GetDefaultTargetPort()
|
|
{
|
|
return NtpDefaultPort;
|
|
}
|
|
|
|
public string GetDefaultTargetHost()
|
|
{
|
|
return NtpDefaultServer;
|
|
}
|
|
}
|