/* * Copyright (c) 2023 Valtteri Koskivuori * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef _MACNTP_H #define _MACNTP_H enum MacNTPError { Success = 0, MacTCPInitFailed, InvalidURL, BadNtpStructSize, UDPCreateFailed, UDPSendFailed, UDPRcvFailed, InvalidNTPResponse, OriginTimestampMismatch, DNSResolveFailed, // Below only for SetSystemTime ClockWriteFailed, ClockReadFailed, UDPRcvTimedOut, PacketParamNull }; struct ntp_ts { unsigned long upper; /* Seconds since 1904-01-01 */ unsigned long lower; /* FIXME: These values seem to be wrong */ }; struct ntp_packet { unsigned char li_vn_mode; unsigned char stratum; unsigned char poll; char precision; unsigned long root_delay; unsigned long root_dispersion; unsigned long reference_id; struct ntp_ts reference_timestamp; struct ntp_ts origin_timestamp; struct ntp_ts receive_timestamp; struct ntp_ts transmit_timestamp; }; typedef long minutes_t; enum MacNTPError MacNTPFetchTime(char *ntp_url, struct ntp_packet *packet, OSErr *supplemental, minutes_t utc_offset); // For convenience, you can just pass ntp_packet from above to set the system time // Optionally, you can care about the contents of ntp_packet and do things with it. enum MacNTPError MacNTPSetSystemTime(struct ntp_packet *ntp, minutes_t utc_offset); #endif