NtpClientOptions Class

Configuration options for NtpClient.

public sealed class NtpClientOptions

Constructors

NameDescription
NtpClientOptions()

NtpClientOptions()

NtpClientOptions.cs
public NtpClientOptions()

No documentation is available.

Properties

NameDescription
AuthenticationKeyGets or sets the symmetric key that authenticates the requests and the replies (RFC 5905, RFC 8573), or null to send unauthenticated requests. Default is null.
PortGets or sets the server port. Default is 123.
RetryCountGets or sets the number of times a request is sent again to the same address when no valid reply arrives within NtpClientOptions.Timeout. Default is 0.
TimeoutGets or sets the timeout for querying a single resolved address. Default is 5 seconds. Use Timeout.InfiniteTimeSpan for no timeout.
ValidateResponseGets or sets a value indicating whether responses are validated before being returned. Default is true.
VersionGets or sets the NTP protocol version to use. Default is NtpVersion.V4.

AuthenticationKey

NtpClientOptions.cs

Gets or sets the symmetric key that authenticates the requests and the replies (RFC 5905, RFC 8573), or null to send unauthenticated requests. Default is null.

public NtpAuthenticationKey? AuthenticationKey { get; set; }

Property value

NtpAuthenticationKey?

Remarks

When set, the client appends a message authentication code (MAC) to every request, and ignores every reply that does not end with a valid MAC computed with the same key, whatever NtpClientOptions.ValidateResponse is. The server must be configured with the same key identifier, algorithm and key.

Gets or sets the server port. Default is 123.

public int Port { get; set; }

Property value

int

Gets or sets the number of times a request is sent again to the same address when no valid reply arrives within NtpClientOptions.Timeout. Default is 0.

public int RetryCount { get; set; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is negative.

Remarks

Each attempt sends a new request and waits NtpClientOptions.Timeout for its reply, so an address can take Timeout × (RetryCount + 1). Only a missing reply is retried, not a network error.

Gets or sets the timeout for querying a single resolved address. Default is 5 seconds. Use Timeout.InfiniteTimeSpan for no timeout.

public TimeSpan Timeout { get; set; }

Property value

TimeSpan

Remarks

A host name can resolve to several addresses, and each one gets this much time, so a query can take up to Timeout × addressCount overall. Use the cancellationToken of NtpClient.QueryAsync to bound the total duration.

ValidateResponse

NtpClientOptions.cs

Gets or sets a value indicating whether responses are validated before being returned. Default is true.

public bool ValidateResponse { get; set; }

Property value

bool

Remarks

When enabled, a response is only accepted if its originate timestamp echoes the transmit timestamp of the request (RFC 5905 TEST2), its version is 3 or 4, its stratum is not 0 (Kiss-o'-Death), and the server does not report an alarm condition. Responses that fail are ignored and the client keeps waiting for a valid one until NtpClientOptions.Timeout elapses.

The originate timestamp is what ties a reply to this specific request, so disabling this makes the client accept a forged reply from anyone who can guess its source port. Only turn it off to interoperate with a server known to be non-compliant, and do not use the result to make a security decision. Disabling it does not disable NtpClientOptions.AuthenticationKey.

Gets or sets the NTP protocol version to use. Default is NtpVersion.V4.

public NtpVersion Version { get; set; }

Property value

NtpVersion