---
name: "ntp_adjtime"
section: "2"
platform: "linux"
package: "freebsd-manpages"
version: "6.0-5"
release: "Debian 4.0 (Etch)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/ntp_adjtime"
---

# ntp\_adjtime(2)

NTP daemon application interface

## NAME

**ntp\_adjtime** – NTP daemon application interface

## SYNOPSIS

**#include \<sys/types.h\>**

**#include \<sys/timex.h\>**

*int*\

**ntp\_adjtime**(*struct timex \*tp*);

## DESCRIPTION

The **ntp\_adjtime**() system call is used as a kernel interface for the Network Time Protocol daemon, [ntpd(8)](/ntpd/8.md). Certain fields of the *timex* structure are interpreted in either microseconds or nanoseconds, according to the state of the STA\_NANO bit in the *status* word.

In the FreeBSD kernel, the **ntp\_adjtime**() and [ntp\_gettime(2)](/ntp_gettime/2.md) system calls can be used to determine which resolution is in use, and to select either one at any time. The resolution selected affects the scaling of certain fields in the **ntp\_gettime**() and **ntp\_adjtime**() system calls.

Take note that this API is extremely complex and stateful. Users should not attempt modification without first reviewing the [ntpd(8)](/ntpd/8.md) sources in depth.

```
/*
 * NTP daemon interface (ntp_adjtime()) - used to discipline CPU clock
 * oscillator and determine status.
 *
 * Note: The offset, precision and jitter members are in microseconds if
 * STA_NANO is zero and nanoseconds if not.
 */
struct timex {
	unsigned int modes;	/* clock mode bits (wo) */
	long	offset;		/* time offset (ns/us) (rw) */
	long	freq;		/* frequency offset (scaled PPM) (rw) */
	long	maxerror;	/* maximum error (us) (rw) */
	long	esterror;	/* estimated error (us) (rw) */
	int	status;		/* clock status bits (rw) */
	long	constant;	/* poll interval (log2 s) (rw) */
	long	precision;	/* clock precision (ns/us) (ro) */
	long	tolerance;	/* clock frequency tolerance (scaled
				 * PPM) (ro) */
	/*
	 * The following read-only structure members are implemented
	 * only if the PPS signal discipline is configured in the
	 * kernel. They are included in all configurations to insure
	 * portability.
	 */
	long	ppsfreq;	/* PPS frequency (scaled PPM) (ro) */
	long	jitter;		/* PPS jitter (ns/us) (ro) */
	int	shift;		/* interval duration (s) (shift) (ro) */
	long	stabil;		/* PPS stability (scaled PPM) (ro) */
	long	jitcnt;		/* jitter limit exceeded (ro) */
	long	calcnt;		/* calibration intervals (ro) */
	long	errcnt;		/* calibration errors (ro) */
	long	stbcnt;		/* stability limit exceeded (ro) */
};
```

Upon successful completion, **ntp\_adjtime**() will fill the *tp* argument with the current clock state.

## RETURN VALUES

Upon successful completion the clock state is returned. Otherwise a -1 is returned and the global variable *errno* is set to indicate the error.

Possible states of the clock are:

- TIME\_OK

  Everything okay, no leap second warning.

- TIME\_INS

  insert leap second warning.

- TIME\_DEL

  delete leap second warning.

- TIME\_OOP

  Leap second in progress.

- TIME\_WAIT

  Leap second has occurred.

- TIME\_ERROR

  Clock not synchronized.

## ERRORS

The **ntp\_gettime**() system call may return EPERM if the caller does not have sufficient permissions.

## SEE ALSO

[ntp\_gettime(2)](/ntp_gettime/2.md), [ntpd(8)](/ntpd/8.md)

## AUTHORS

This manual page was written by Tom Rhodes ⟨trhodes@FreeBSD.org⟩.
