diff options
Diffstat (limited to 'ports/winnt/include')
-rw-r--r-- | ports/winnt/include/arpa/inet.h | 4 | ||||
-rw-r--r-- | ports/winnt/include/clockstuff.h | 44 | ||||
-rw-r--r-- | ports/winnt/include/config.h | 554 | ||||
-rw-r--r-- | ports/winnt/include/gaa_compat.h | 771 | ||||
-rw-r--r-- | ports/winnt/include/hopf_PCI_io.h | 91 | ||||
-rw-r--r-- | ports/winnt/include/netdb.h | 4 | ||||
-rw-r--r-- | ports/winnt/include/ntp_iocompletionport.h | 27 | ||||
-rw-r--r-- | ports/winnt/include/ntp_timer.h | 6 | ||||
-rw-r--r-- | ports/winnt/include/ntservice.h | 31 | ||||
-rw-r--r-- | ports/winnt/include/stdint.h | 244 | ||||
-rw-r--r-- | ports/winnt/include/stdnoreturn.h | 61 | ||||
-rw-r--r-- | ports/winnt/include/sys/ioctl.h | 11 | ||||
-rw-r--r-- | ports/winnt/include/sys/param.h | 4 | ||||
-rw-r--r-- | ports/winnt/include/sys/resource.h | 10 | ||||
-rw-r--r-- | ports/winnt/include/sys/signal.h | 4 | ||||
-rw-r--r-- | ports/winnt/include/sys/time.h | 25 | ||||
-rw-r--r-- | ports/winnt/include/sys/wait.h | 4 | ||||
-rw-r--r-- | ports/winnt/include/syslog.h | 82 | ||||
-rw-r--r-- | ports/winnt/include/termios.h | 214 | ||||
-rw-r--r-- | ports/winnt/include/timepps.h | 811 | ||||
-rw-r--r-- | ports/winnt/include/unistd.h | 4 | ||||
-rw-r--r-- | ports/winnt/include/win32_io.h | 7 |
22 files changed, 3013 insertions, 0 deletions
diff --git a/ports/winnt/include/arpa/inet.h b/ports/winnt/include/arpa/inet.h new file mode 100644 index 0000000..5e15997 --- /dev/null +++ b/ports/winnt/include/arpa/inet.h @@ -0,0 +1,4 @@ +/************************************************************** + * Dummy Header for Unix to Windows NT portability + * Created for NTP package + **************************************************************/ diff --git a/ports/winnt/include/clockstuff.h b/ports/winnt/include/clockstuff.h new file mode 100644 index 0000000..df85699 --- /dev/null +++ b/ports/winnt/include/clockstuff.h @@ -0,0 +1,44 @@ +#ifndef _CLOCKSTUFF_H +#define _CLOCKSTUFF_H + +#include <time.h> +#include <sys\timeb.h> + +#include "ntp_fp.h" +#include "ntp_syslog.h" + + +void init_winnt_time(void); +void reset_winnt_time(void); +void lock_thread_to_processor(HANDLE); + +/* 100ns intervals between 1/1/1601 and 1/1/1970 as reported by + * SystemTimeToFileTime() + */ + +#define FILETIME_1970 0x019db1ded53e8000 +#define HECTONANOSECONDS 10000000 + +/* + * Multimedia Timer + */ + +void set_mm_timer(int); + +enum { + MM_TIMER_LORES, + MM_TIMER_HIRES +}; + +/* + * get_sys_time_as_filetime is a function pointer to + * either GetSystemTimeAsFileTime provided by Windows + * or ntpd's interpolating replacement. + */ +typedef void (WINAPI *PGSTAFT)(LPFILETIME pftResult); +extern PGSTAFT get_sys_time_as_filetime; +extern PGSTAFT pGetSystemTimePreciseAsFileTime; + +void lock_thread_to_processor(HANDLE); + +#endif diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h new file mode 100644 index 0000000..b99aaa7 --- /dev/null +++ b/ports/winnt/include/config.h @@ -0,0 +1,554 @@ +/* + * ports/winnt/include/config.h - static Windows config.h + * + * On most systems config.h is generated by the configure script. + * For the Windows port, it's hand-maintained. Compilers earlier + * than Visual C++ 2005 are no longer supported, enabling + * portable use of "long long" and "%lld". + */ + +#ifndef CONFIG_H +#define CONFIG_H + +/* + * Known predifined MS compiler version codes: + * 1800: MSVC++ 12.0 (Visual Studio 2013) + * 1700: MSVC++ 11.0 (Visual Studio 2012) + * 1600: MSVC++ 10.0 (Visual Studio 2010) + * 1500: MSVC++ 9.0 (Visual Studio 2008) + * 1400: MSVC++ 8.0 (Visual Studio 2005) + * 1310: MSVC++ 7.1 (Visual Studio 2003) + * 1300: MSVC++ 7.0 + * 1200: MSVC++ 6.0 (Visual C++ 6) + * 1100: MSVC++ 5.0 + */ + +#if defined(_MSC_VER) && _MSC_VER < 1400 +#error Minimum supported Microsoft compiler is Visual C++ 2005. +#endif + +/* + * We want structures and prototypes added after Windows NT 4.0 exposed + * by Windows header files, so we define _WIN32_WINNT to target Windows + * XP (version 5.1). By default, _WIN32_WINNT also controls the minimum + * required Windows version to launch the .exe. As we want a single + * binary to work on all supported Windows versions, we runtime link + * newer functions, and use the linker /version:0x0400 option to + * override the .EXE header minimum Windows version. + * + * When using the VC++ 2008 and later compilers, the resulting binaries + * will not work on versions earlier than Windows XP, due to runtime + * library dependencies. That is, Visual C++ 2005 is the last version + * capable of producing binaries usable with Windows NT 4 and 2000. + */ +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 +#endif + +#define __attribute__(x) /* empty */ +#define _CRT_SECURE_NO_DEPRECATE 1 + +/* + * ANSI C compliance enabled + */ +#define __STDC__ 1 + +/* + * Enable the debug build of MS C runtime to dump leaks + * at exit time (currently only if run under a debugger). + */ +#if defined(_MSC_VER) && defined(_DEBUG) +# define _CRTDBG_MAP_ALLOC +# include <stdlib.h> +# include <malloc.h> +# include <crtdbg.h> +/* # define MALLOC_LINT */ /* defers free() */ +# define EREALLOC_IMPL(ptr, newsz, filenm, loc) \ + _realloc_dbg(ptr, newsz, _NORMAL_BLOCK, filenm, loc) +#endif + +/* + * We need to include stdio.h first before we #define snprintf + * otherwise we can get errors during the build + */ +#include <stdio.h> + +/* Prevent inclusion of winsock.h in windows.h */ +#ifndef _WINSOCKAPI_ +#define _WINSOCKAPI_ +#endif + +#ifndef __RPCASYNC_H__ +#define __RPCASYNC_H__ +#endif + +/* + * On Unix struct sock_timeval is equivalent to struct timeval. + * On Windows built with 64-bit time_t, sock_timeval.tv_sec is a long + * as required by Windows' socket() interface timeout argument, while + * timeval.tv_sec is time_t for the more common use as a UTC time + * within NTP. + * + * winsock.h unconditionally defines struct timeval with long tv_sec + * instead of time_t tv_sec. We redirect its declaration to struct + * sock_timeval instead of struct timeval with a #define. + */ +#define timeval sock_timeval + +/* Include Windows headers */ +#include <windows.h> +#include <winsock2.h> +#include <ws2tcpip.h> + +#undef timeval /* see sock_timeval #define and comment above */ + +/* + * Some definitions we are using are missing in the headers + * shipping with VC6. However, if the SDK is installed then the + * SDK's headers may declare the missing types. This is at least + * the case in the Oct 2001 SDK. That SDK and all subsequent + * versions also define the symbol _W64, so we can use that one + * to determine whether some types need to be defined, or not. + */ +#ifdef _W64 +/* VC6 can include wspiapi.h only if the SDK is installed */ +#include <wspiapi.h> +#endif + +#undef interface +#include <process.h> +#include <time.h> /* time_t for timeval decl */ +#include <io.h> +#include <isc/strerror.h> + +/* --------------------------------------------------------------------- + * Above this line are #include lines and the few #define lines + * needed before including headers. + */ + +struct timeval { + time_t tv_sec; + long tv_usec; +}; + +/* + * ntohl and friends are actual functions on Windows, use our own + * macros instead to save the function call overhead. All releases + * of Windows are little-endian. + */ +#ifdef ntohl +#error ntohl is already defined in ports/winnt/include/config.h +#else +#define ntohl(ul) (((u_long)(ul) & 0xff) << 24 | \ + ((u_long)(ul) & 0xff00) << 8 | \ + ((u_long)(ul) & 0xff0000) >> 8 | \ + ((u_long)(ul) & 0xff000000) >> 24) +#define htonl(ul) ntohl(ul) +#define ntohs(us) ((u_short) \ + (((u_short)(us) & 0xff) << 8 | \ + ((u_short)(us) & 0xff00) >> 8)) +#define htons(us) ntohs(us) +#endif + +/* + * On Unix open() works for tty (serial) devices just fine, while on + * Windows refclock serial devices are opened using CreateFile, a lower + * level than the CRT-provided descriptors, because the C runtime lacks + * tty APIs. For refclocks which wish to use open() as well as or + * instead of refclock_open(), tty_open() is equivalent to open() on + * Unix and implemented in the Windows port similarly to + * refclock_open(). + */ +extern int tty_open(char *, int, int); + +/* + * disable use of __declspec(dllexport) by libisc routines + */ +#define ISC_STATIC_WIN 1 + +/* + * ntp_rfc2553.h has cruft under #ifdef SYS_WINNT which is + * appropriate for older Microsoft IPv6 definitions, such + * as in_addr6 being the struct type. We can differentiate + * the RFC2553-compliant newer headers because they have + * #define in_addr6 in6_addr + * for backward compatibility. With the newer headers, + * we define ISC_PLATFORM_HAVEIPV6 and disable the cruft. + */ +#ifdef in_addr6 +#define WANT_IPV6 +#define ISC_PLATFORM_HAVEIPV6 +#define ISC_PLATFORM_HAVESCOPEID +#define HAVE_STRUCT_SOCKADDR_STORAGE +#define ISC_PLATFORM_HAVEIN6PKTINFO +#endif /* in_addr6 / RFC2553-compliant IPv6 headers */ + +#define NO_OPTION_NAME_WARNINGS + +#if !defined( _W64 ) + /* + * if ULONG_PTR needs to be defined then the build environment + * is pure 32 bit Windows. Since ULONG_PTR and DWORD have + * the same size in 32 bit Windows we can safely define + * a replacement. + */ +typedef DWORD ULONG_PTR; +/* VC6 doesn't know about socklen_t, except if the SDK is installed */ +typedef int socklen_t; +#endif /* _W64 */ + +#define ISC_PLATFORM_NEEDIN6ADDRANY +#define HAVE_SOCKADDR_IN6 + +/* + * The type of the socklen_t defined for getnameinfo() and getaddrinfo() + * is int for VS compilers on Windows but the type is already declared + */ +#define GETSOCKNAME_SOCKLEN_TYPE socklen_t + +/* + * Older SDKs do not define SO_EXCLUSIVEADDRUSE in winsock2.h + */ +#ifndef SO_EXCLUSIVEADDRUSE +#define SO_EXCLUSIVEADDRUSE ((int)(~SO_REUSEADDR)) +#endif + +#if defined _MSC_VER && _MSC_VER < 1400 +/* + * Use 32-bit time definitions for versions prior to VS 2005 + * VS 2005 defaults to 64-bit time + */ +# define SIZEOF_TIME_T 4 +#else +# define SIZEOF_TIME_T 8 +#endif + + +/* + * An attempt to cut down the number of warnings generated during compilation. + * All of these should be benign to disable. + */ + +#pragma warning(disable: 4100) /* unreferenced formal parameter */ +#pragma warning(disable: 4127) /* conditional expression is constant */ +#pragma warning(disable: 4996) /* more secure replacement available */ + +/* + * Windows NT Configuration Values + */ +#if defined _DEBUG /* Use VC standard macro definitions */ +# define DEBUG 1 +#endif + +#define __windows__ 1 +/* Define if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +#define OPEN_BCAST_SOCKET 1 /* for ntp_io.c */ +#define TYPEOF_IP_MULTICAST_LOOP BOOL +#define SETSOCKOPT_ARG_CAST (const char *) +#define HAVE_RANDOM +#define AUTOKEY +#define SAVECONFIG 1 + +/* + * Multimedia timer enable + */ +#define USE_MM_TIMER + +/* Enable OpenSSL */ +#define OPENSSL 1 + +/* + * Keywords and functions that Microsoft maps + * to other names + */ +#define inline __inline +#define stricmp _stricmp +#define strcasecmp _stricmp +#define isascii __isascii +#define finite _finite +#define random rand +#define srandom srand +#define fdopen _fdopen +#define read _read +#define open _open +#ifndef close +#define close _close +#endif +#define write _write +#define strdup _strdup +#define alloca _alloca +#define stat _stat /*struct stat from <sys/stat.h> */ +#define fstat _fstat +#define unlink _unlink +/* + * punt on fchmod on Windows + */ +#define fchmod(x,y) {} +#define lseek _lseek +#define pipe _pipe +#define dup2 _dup2 +/* + * scale, unix sleep is seconds, Windows Sleep is msec + */ +#define sleep(x) Sleep((unsigned)(x) * 1000) +#define fileno _fileno +#define isatty _isatty +#define mktemp _mktemp +#define getpid _getpid +#define timegm _mkgmtime +#define errno_to_str isc__strerror + +typedef int pid_t; /* PID is an int */ +typedef int ssize_t; /* ssize is an int */ + +/* + * Map the stream to the file number + */ +#define STDOUT_FILENO _fileno(stdout) +#define STDERR_FILENO _fileno(stderr) + +/* + * To minimize Windows-specific changes to the rest of the NTP code, + * particularly reference clocks, ntp_stdlib.h will + * + * #define strerror(e) ntp_strerror(e) + * + * to deal with our mixture of C runtime (open, write) and Windows + * (sockets, serial ports) error codes. This is an ugly hack because + * both use the lowest values differently, but particularly for ntpd, + * it's not a problem. + */ +#define NTP_REDEFINE_STRERROR + +#define MCAST /* Enable Multicast Support */ +#define MULTICAST_NONEWSOCKET /* Don't create a new socket for mcast address */ + +# define REFCLOCK /* from ntpd.mak */ + +/* #define CLOCK_PARSE */ +#define CLOCK_ACTS +#define CLOCK_ARBITER +#define CLOCK_ARCRON_MSF +#define OWN_PPS_NTP_TIMESTAMP_FROM_COUNTER /* timepps.h */ +#define HAVE_TIMEPPS_H +#define HAVE_PPSAPI +#define CLOCK_ATOM +#define CLOCK_CHU +#define CLOCK_CHRONOLOG +#define CLOCK_DUMBCLOCK +#define CLOCK_HOPF_SERIAL /* device 38, hopf DCF77/GPS serial line receiver */ +#define CLOCK_HOPF_PCI /* device 39, hopf DCF77/GPS PCI-Bus receiver */ +#define CLOCK_JUPITER +#define CLOCK_LOCAL +#define CLOCK_NMEA +#define CLOCK_ONCORE +#define CLOCK_PALISADE /* from ntpd.mak */ +#define CLOCK_PARSE +/* parse component drivers */ +#define CLOCK_COMPUTIME +#define CLOCK_DCF7000 +#define CLOCK_HOPF6021 +#define CLOCK_MEINBERG +#define CLOCK_RAWDCF +#define CLOCK_RCC8000 +#define CLOCK_SCHMID +#define CLOCK_TRIMTAIP +#define CLOCK_TRIMTSIP +#define CLOCK_VARITEXT +#define CLOCK_WHARTON_400A +/* end parse component drivers */ +/* # define CLOCK_SHM */ +#define CLOCK_SPECTRACOM /* refclock_wwvb.c */ +#define CLOCK_TRIMBLEDC +#define CLOCK_TRUETIME + +#define NTP_LITTLE_ENDIAN /* from libntp.mak */ +#define NTP_POSIX_SOURCE + +#define SYSLOG_FILE /* from libntp.mak */ + +#define HAVE_LONG_LONG_INT 1 +#define HAVE_UNSIGNED_LONG_LONG_INT 1 +#define HAVE_SIZE_T 1 +#define HAVE_PTRDIFF_T 1 + +# define SIZEOF_SIGNED_CHAR 1 +# define SIZEOF_SHORT 2 +# define SIZEOF_INT 4 +# define SIZEOF_LONG 4 +# define SIZEOF_LONG_LONG 8 + +/* libntp/snprintf.c doesn't know %I64d */ +#define ISC_PLATFORM_QUADFORMAT "ll" + +# define HAVE_ERRNO_H 1 +# define HAVE_FCNTL_H 1 +# define HAVE_LIMITS_H 1 +# define HAVE_STDARG_H 1 +# define HAVE_SYS_RESOURCE_H 1 +# define HAVE_SYS_TIME_H 1 +# define HAVE_TERMIOS_H 1 + +# define HAVE_ALLOCA 1 +# define HAVE_GETCLOCK 1 +# define HAVE_MEMMOVE 1 +# define HAVE_MKTIME 1 +# define HAVE_SETVBUF 1 +# define HAVE_STRCHR 1 /* for libopts */ +# define HAVE_STRDUP 1 +# define HAVE_TIMEGM 1 /* actually _mkgmtime */ + +# define HAVE_STRUCT_TIMESPEC +# define HAVE_IO_COMPLETION_PORT +# define ISC_PLATFORM_NEEDNTOP +# define ISC_PLATFORM_NEEDPTON + +#define HAVE_BSD_NICE /* emulate BSD setpriority() */ + +#define HW_WANT_RPL_VSNPRINTF 1 +#define vsnprintf rpl_vsnprintf +#include <stdarg.h> +int rpl_vsnprintf(char *, size_t, const char *, va_list); +#define HW_WANT_RPL_SNPRINTF 1 +#define snprintf rpl_snprintf +int rpl_snprintf(char *, size_t, const char *, ...); +#define HAVE_VSNPRINTF 1 +#define HAVE_SNPRINTF 1 + +typedef char *caddr_t; + +#ifdef _WCTYPE_T_DEFINED /* see vc/include/crtdefs.h */ +#define HAVE_WINT_T 1 +#endif + +#ifndef _INTPTR_T_DEFINED +typedef long intptr_t; +#define _INTPTR_T_DEFINED +#endif +#define HAVE_INTPTR_T 1 + +#ifndef _UINTPTR_T_DEFINED +typedef unsigned long uintptr_t; +#define _UINTPTR_T_DEFINED +#endif +#define HAVE_UINTPTR_T 1 + +#if !defined( _W64 ) + /* + * if DWORD_PTR needs to be defined then the build environment + * is pure 32 bit Windows. Since DWORD_PTR and DWORD have + * the same size in 32 bit Windows we can safely define + * a replacement. + */ + typedef DWORD DWORD_PTR; +#endif + +#define NEED_S_CHAR_TYPEDEF + + +/* C99 exact size integer support. */ +#if defined(_MSC_VER) && _MSC_VER<1800 +# define MISSING_INTTYPES_H 1 /* not provided by VS2012 and earlier */ +# define MISSING_STDBOOL_H 1 /* not provided by VS2012 and earlier */ +#else +#if defined(_MSC_VER) && _MSC_VER>=1800 +/* VS2013 and above support C99 types */ +# define HAVE_INT8_T 1 +# define HAVE_UINT8_T 1 +# define HAVE_INT16_T 1 +# define HAVE_UINT16_T 1 +# define HAVE_INT32_T 1 +# define HAVE_UINT32_T 1 +#endif +#endif + +#if !defined (MISSING_STDBOOL_H) +# define HAVE_STDBOOL_H +#endif +#if !defined(MISSING_INTTYPES_H) +# define HAVE_INTTYPES_H 1 +#elif !defined(MISSING_STDINT_H) +# define HAVE_STDINT_H 1 +#elif !defined(ADDED_EXACT_SIZE_INTEGERS) +# define ADDED_EXACT_SIZE_INTEGERS 1 + typedef __int8 int8_t; + typedef unsigned __int8 uint8_t; + + typedef __int16 int16_t; + typedef unsigned __int16 uint16_t; + + typedef __int32 int32_t; + typedef unsigned __int32 uint32_t; + + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; +#endif + + +/* Directory separator, usually / or \ */ +#define DIR_SEP '\\' + +#define POSIX_SHELL "/bin/sh" /* libopts/makeshell.c */ + +#define ULONG_CONST(a) a ## UL + +#define NOKMEM +#define RETSIGTYPE void + +#ifndef STR_SYSTEM +#define STR_SYSTEM "Windows" +#endif + +#ifndef STR_PROCESSOR + +#define STRINGIZE(arg) #arg + +#ifdef _M_IX86 +#ifndef _M_IX86_FP +#define STR_PROCESSOR "x86" +#else +#if !_M_IX86_FP +#define STR_PROCESSOR "x86" +#else +#if _M_IX86_FP > 2 +#define STR_PROCESSOR "x86-FP-" STRINGIZE(_M_IX86_FP) +#else +#if _M_IX86_FP == 2 +#define STR_PROCESSOR "x86-SSE2" +#else +#define STR_PROCESSOR "x86-SSE" +#endif /* _M_IX86 == 2 */ +#endif /* _M_IX86_FP > 2 */ +#endif /* !_M_IX86_FP */ +#endif /* !defined(_M_IX86_FP) */ +#endif /* !defined(_M_IX86) */ + +#ifdef _M_IA64 +#define STR_PROCESSOR "Itanium" +#endif + +#ifdef _M_X64 +#define STR_PROCESSOR "x64" +#endif + +#endif /* !defined(STR_PROCESSOR) */ + +#undef STRINGIZE + +#define SIOCGIFFLAGS SIO_GET_INTERFACE_LIST /* used in ntp_io.c */ +/* + * Below this line are includes which must happen after the bulk of + * config.h is processed. If you need to add another #include to this + * file the preferred location is near the top, above the similar + * line of hyphens. + * --------------------------------------------------------------------- + */ + +/* + * Include standard stat information + */ +#include <isc/stat.h> + +#endif /* CONFIG_H */ diff --git a/ports/winnt/include/gaa_compat.h b/ports/winnt/include/gaa_compat.h new file mode 100644 index 0000000..fdacaf0 --- /dev/null +++ b/ports/winnt/include/gaa_compat.h @@ -0,0 +1,771 @@ +/* + * ports/winnt/include/gaa_compat.h + * + * This header allows systems without a recent-enough SDK to build NTP + * which can use GetAdaptersAddresses(), related functions and macros. + */ +#ifndef GAA_COMPAT_H +#define GAA_COMPAT_H + +#ifdef _W64 +# include <iphlpapi.h> +#else /* !_W64 follows */ + +#pragma warning(push) +/* warning C4201: nonstandard extension used : nameless struct/union */ +#pragma warning(disable:4201) +/* warning C4214: nonstandard extension used : bit field types other than int */ +#pragma warning(disable:4214) + +/* +++++++++++++++++++++++ from nldef.h */ +typedef enum { + // + // These values are from iptypes.h. + // They need to fit in a 4 bit field. + // + IpPrefixOriginOther = 0, + IpPrefixOriginManual, + IpPrefixOriginWellKnown, + IpPrefixOriginDhcp, + IpPrefixOriginRouterAdvertisement, + IpPrefixOriginUnchanged = 1 << 4 +} NL_PREFIX_ORIGIN; + +typedef enum { + // + // These values are from in iptypes.h. + // They need to fit in a 4 bit field. + // + IpSuffixOriginOther = 0, + IpSuffixOriginManual, + IpSuffixOriginWellKnown, + IpSuffixOriginDhcp, + IpSuffixOriginLinkLayerAddress, + IpSuffixOriginRandom, + IpSuffixOriginUnchanged = 1 << 4 +} NL_SUFFIX_ORIGIN; + +typedef enum { + // + // These values are from in iptypes.h. + // + IpDadStateInvalid = 0, + IpDadStateTentative, + IpDadStateDuplicate, + IpDadStateDeprecated, + IpDadStatePreferred, +} NL_DAD_STATE; +/* +++++++++++++++++++++++ from nldef.h */ + + +/* +++++++++++++++++++++++ from ifdef.h */ +typedef ULONG32 NET_IF_OBJECT_ID, *PNET_IF_OBJECT_ID; + + +typedef enum _NET_IF_ADMIN_STATUS // ifAdminStatus +{ + NET_IF_ADMIN_STATUS_UP = 1, + NET_IF_ADMIN_STATUS_DOWN = 2, + NET_IF_ADMIN_STATUS_TESTING = 3 +} NET_IF_ADMIN_STATUS, *PNET_IF_ADMIN_STATUS; + +typedef enum _NET_IF_OPER_STATUS // ifOperStatus +{ + NET_IF_OPER_STATUS_UP = 1, + NET_IF_OPER_STATUS_DOWN = 2, + NET_IF_OPER_STATUS_TESTING = 3, + NET_IF_OPER_STATUS_UNKNOWN = 4, + NET_IF_OPER_STATUS_DORMANT = 5, + NET_IF_OPER_STATUS_NOT_PRESENT = 6, + NET_IF_OPER_STATUS_LOWER_LAYER_DOWN = 7 +} NET_IF_OPER_STATUS, *PNET_IF_OPER_STATUS; + +// +// Flags to extend operational status +// +#define NET_IF_OPER_STATUS_DOWN_NOT_AUTHENTICATED 0x00000001 +#define NET_IF_OPER_STATUS_DOWN_NOT_MEDIA_CONNECTED 0x00000002 +#define NET_IF_OPER_STATUS_DORMANT_PAUSED 0x00000004 +#define NET_IF_OPER_STATUS_DORMANT_LOW_POWER 0x00000008 + +typedef UINT32 NET_IF_COMPARTMENT_ID, *PNET_IF_COMPARTMENT_ID; + +// +// Define compartment ID type: +// +#define NET_IF_COMPARTMENT_ID_UNSPECIFIED (NET_IF_COMPARTMENT_ID)0 +#define NET_IF_COMPARTMENT_ID_PRIMARY (NET_IF_COMPARTMENT_ID)1 + +#define NET_IF_OID_IF_ALIAS 0x00000001 // identifies the ifAlias string for an interface +#define NET_IF_OID_COMPARTMENT_ID 0x00000002 // identifies the compartment ID for an interface. +#define NET_IF_OID_NETWORK_GUID 0x00000003 // identifies the NetworkGuid for an interface. +#define NET_IF_OID_IF_ENTRY 0x00000004 // identifies statistics for an interface. + +// +// Define NetworkGUID type: +// +typedef GUID NET_IF_NETWORK_GUID, *PNET_IF_NETWORK_GUID; + +// +// Define macros for an "unspecified" NetworkGUID value to be used in structures +// that haven't had the NET_LUID field filled in yet. +// +#define NET_SET_UNSPECIFIED_NETWORK_GUID(_pNetworkGuid) +#define NET_IS_UNSPECIFIED_NETWORK_GUID(_NetworkGuidValue) + +// +// To prevent collisions between user-assigned and system-assigend site-ids, +// we partition the site-id space into two: +// 1. User-Assigned: NET_SITEID_UNSPECIFIED < SiteId < NET_SITEID_MAXUSER +// 2. System-Assigned: NET_SITEID_MAXUSER < SiteId < NET_SITEID_MAXSYSTEM +// +// Note: A network's SiteId doesn't really need to be settable. +// 1. The network profile manager creates a network per network profile. +// 2. NDIS/IF assigns a unique SiteId to each network. +// +#define NET_SITEID_UNSPECIFIED (0) +#define NET_SITEID_MAXUSER (0x07ffffff) +#define NET_SITEID_MAXSYSTEM (0x0fffffff) +C_ASSERT(NET_SITEID_MAXUSER < NET_SITEID_MAXSYSTEM); + +typedef enum _NET_IF_RCV_ADDRESS_TYPE // ifRcvAddressType +{ + NET_IF_RCV_ADDRESS_TYPE_OTHER = 1, + NET_IF_RCV_ADDRESS_TYPE_VOLATILE = 2, + NET_IF_RCV_ADDRESS_TYPE_NON_VOLATILE = 3 +} NET_IF_RCV_ADDRESS_TYPE, *PNET_IF_RCV_ADDRESS_TYPE; + +typedef struct _NET_IF_RCV_ADDRESS_LH +{ + NET_IF_RCV_ADDRESS_TYPE ifRcvAddressType; + USHORT ifRcvAddressLength; + USHORT ifRcvAddressOffset; // from beginning of this struct +} NET_IF_RCV_ADDRESS_LH, *PNET_IF_RCV_ADDRESS_LH; + +typedef struct _NET_IF_ALIAS_LH +{ + USHORT ifAliasLength; // in bytes, of ifAlias string + USHORT ifAliasOffset; // in bytes, from beginning of this struct +} NET_IF_ALIAS_LH, *PNET_IF_ALIAS_LH; + +#pragma warning(push) +#pragma warning(disable:4214) // bit field types other than int +typedef union _NET_LUID_LH +{ + ULONG64 Value; + struct + { + ULONG64 Reserved:24; + ULONG64 NetLuidIndex:24; + ULONG64 IfType:16; // equal to IANA IF type + }Info; +} NET_LUID_LH, *PNET_LUID_LH; +#pragma warning(pop) + +#if (NTDDI_VERSION >= NTDDI_LONGHORN) +typedef NET_IF_RCV_ADDRESS_LH NET_IF_RCV_ADDRESS; +typedef NET_IF_RCV_ADDRESS* PNET_IF_RCV_ADDRESS; + +typedef NET_IF_ALIAS_LH NET_IF_ALIAS; +typedef NET_IF_ALIAS* PNET_IF_ALIAS; +#endif //NTDDI_LONGHORN + +// +// Need to make this visible on all platforms (for the purpose of IF_LUID). +// +typedef NET_LUID_LH NET_LUID; +typedef NET_LUID* PNET_LUID; + +// +// IF_LUID +// +// Define the locally unique datalink interface identifier type. +// This type is persistable. +// +typedef NET_LUID IF_LUID, *PIF_LUID; + +typedef ULONG NET_IFINDEX, *PNET_IFINDEX; // Interface Index (ifIndex) +typedef UINT16 NET_IFTYPE, *PNET_IFTYPE; // Interface Type (IANA ifType) + +#define NET_IFINDEX_UNSPECIFIED (NET_IFINDEX)(0) // Not a valid ifIndex +#define NET_IFLUID_UNSPECIFIED (0) // Not a valid if Luid + +// +// Definitions for NET_IF_INFORMATION.Flags +// +#define NIIF_HARDWARE_INTERFACE 0x00000001 // Set iff hardware +#define NIIF_FILTER_INTERFACE 0x00000002 +#define NIIF_NDIS_RESERVED1 0x00000004 +#define NIIF_NDIS_RESERVED2 0x00000008 +#define NIIF_NDIS_RESERVED3 0x00000010 +#define NIIF_NDIS_WDM_INTERFACE 0x00000020 +#define NIIF_NDIS_ENDPOINT_INTERFACE 0x00000040 + +#define NIIF_WAN_TUNNEL_TYPE_UNKNOWN ((ULONG)(-1)) + +// +// Define datalink interface access types. +// +typedef enum _NET_IF_ACCESS_TYPE +{ + NET_IF_ACCESS_LOOPBACK = 1, + NET_IF_ACCESS_BROADCAST = 2, + NET_IF_ACCESS_POINT_TO_POINT = 3, + NET_IF_ACCESS_POINT_TO_MULTI_POINT = 4, + NET_IF_ACCESS_MAXIMUM = 5 +} NET_IF_ACCESS_TYPE, *PNET_IF_ACCESS_TYPE; + + +// +// Define datalink interface direction types. +// +typedef enum _NET_IF_DIRECTION_TYPE +{ + NET_IF_DIRECTION_SENDRECEIVE, + NET_IF_DIRECTION_SENDONLY, + NET_IF_DIRECTION_RECEIVEONLY, + NET_IF_DIRECTION_MAXIMUM +} NET_IF_DIRECTION_TYPE, *PNET_IF_DIRECTION_TYPE; + + +typedef enum _NET_IF_CONNECTION_TYPE +{ + NET_IF_CONNECTION_DEDICATED = 1, + NET_IF_CONNECTION_PASSIVE = 2, + NET_IF_CONNECTION_DEMAND = 3, + NET_IF_CONNECTION_MAXIMUM = 4 +} NET_IF_CONNECTION_TYPE, *PNET_IF_CONNECTION_TYPE; + + +typedef enum _NET_IF_MEDIA_CONNECT_STATE +{ + MediaConnectStateUnknown, + MediaConnectStateConnected, + MediaConnectStateDisconnected +} NET_IF_MEDIA_CONNECT_STATE, *PNET_IF_MEDIA_CONNECT_STATE; + +#define NET_IF_LINK_SPEED_UNKNOWN ((ULONG64)(-1)) + +// +// Defines the duplex state of media +// +typedef enum _NET_IF_MEDIA_DUPLEX_STATE +{ + MediaDuplexStateUnknown, + MediaDuplexStateHalf, + MediaDuplexStateFull +} NET_IF_MEDIA_DUPLEX_STATE, *PNET_IF_MEDIA_DUPLEX_STATE; + + +// Special values for fields in NET_PHYSICAL_LOCATION +#define NIIF_BUS_NUMBER_UNKNOWN ((ULONG)(-1)) +#define NIIF_SLOT_NUMBER_UNKNOWN ((ULONG)(-1)) +#define NIIF_FUNCTION_NUMBER_UNKNOWN ((ULONG)(-1)) + +typedef struct _NET_PHYSICAL_LOCATION_LH +{ + ULONG BusNumber; // Physical location + ULONG SlotNumber; // ... for hardware + ULONG FunctionNumber; // ... devices. +} NET_PHYSICAL_LOCATION_LH, *PNET_PHYSICAL_LOCATION_LH; + +// +// maximum string size in -wchar- units +// +#define IF_MAX_STRING_SIZE 256 + +typedef struct _IF_COUNTED_STRING_LH +{ + USHORT Length; // in -Bytes- + WCHAR String[IF_MAX_STRING_SIZE + 1]; +} IF_COUNTED_STRING_LH, *PIF_COUNTED_STRING_LH; + +#define IF_MAX_PHYS_ADDRESS_LENGTH 32 + +typedef struct _IF_PHYSICAL_ADDRESS_LH +{ + USHORT Length; + UCHAR Address[IF_MAX_PHYS_ADDRESS_LENGTH]; +} IF_PHYSICAL_ADDRESS_LH, *PIF_PHYSICAL_ADDRESS_LH; + +#if (NTDDI_VERSION >= NTDDI_LONGHORN) +typedef NET_PHYSICAL_LOCATION_LH NET_PHYSICAL_LOCATION; +typedef NET_PHYSICAL_LOCATION* PNET_PHYSICAL_LOCATION; + +typedef IF_COUNTED_STRING_LH IF_COUNTED_STRING; +typedef IF_COUNTED_STRING* PIF_COUNTED_STRING; + +typedef IF_PHYSICAL_ADDRESS_LH IF_PHYSICAL_ADDRESS; +typedef IF_PHYSICAL_ADDRESS* PIF_PHYSICAL_ADDRESS; +#endif + + +// +// IF_INDEX +// +// Define the interface index type. +// This type is not persistable. +// This must be unsigned (not an enum) to replace previous uses of +// an index that used a DWORD type. +// + +typedef NET_IFINDEX IF_INDEX, *PIF_INDEX; +#define IFI_UNSPECIFIED NET_IFINDEX_UNSPECIFIED + + +// +// Get definitions for IFTYPE and IF_ACCESS_TYPE. +// +#include <ipifcons.h> + + +// +// Types of tunnels (sub-type of IF_TYPE when IF_TYPE is IF_TYPE_TUNNEL). +// See http://www.iana.org/assignments/ianaiftype-mib. +// +typedef enum { + TUNNEL_TYPE_NONE = 0, + TUNNEL_TYPE_OTHER = 1, + TUNNEL_TYPE_DIRECT = 2, + TUNNEL_TYPE_6TO4 = 11, + TUNNEL_TYPE_ISATAP = 13, + TUNNEL_TYPE_TEREDO = 14, +} TUNNEL_TYPE, *PTUNNEL_TYPE; + +// +// IF_ADMINISTRATIVE_STATE +// +// Datalink Interface Administrative State. +// Indicates whether the interface has been administratively enabled. +// + +typedef enum _IF_ADMINISTRATIVE_STATE { + IF_ADMINISTRATIVE_DISABLED, + IF_ADMINISTRATIVE_ENABLED, + IF_ADMINISTRATIVE_DEMANDDIAL, +} IF_ADMINISTRATIVE_STATE, *PIF_ADMINISTRATIVE_STATE; + + +// +// Note: Interface is Operational iff +// ((MediaSense is Connected) and (AdministrativeState is Enabled)) +// or +// ((MediaSense is Connected) and (AdministrativeState is OnDemand)) +// +// !Operational iff +// ((MediaSense != Connected) or (AdministrativeState is Disabled)) +// + +// +// OperStatus values from RFC 2863 +// +typedef enum { + IfOperStatusUp = 1, + IfOperStatusDown, + IfOperStatusTesting, + IfOperStatusUnknown, + IfOperStatusDormant, + IfOperStatusNotPresent, + IfOperStatusLowerLayerDown +} IF_OPER_STATUS; +/* +++++++++++++++++++++++ from ifdef.h */ + + +/* +++++++++++++++++++++++ from iptypes.h */ +// Definitions and structures used by getnetworkparams and getadaptersinfo apis + +#define MAX_ADAPTER_DESCRIPTION_LENGTH 128 // arb. +#define MAX_ADAPTER_NAME_LENGTH 256 // arb. +#define MAX_ADAPTER_ADDRESS_LENGTH 8 // arb. +#define DEFAULT_MINIMUM_ENTITIES 32 // arb. +#define MAX_HOSTNAME_LEN 128 // arb. +#define MAX_DOMAIN_NAME_LEN 128 // arb. +#define MAX_SCOPE_ID_LEN 256 // arb. +#define MAX_DHCPV6_DUID_LENGTH 130 // RFC 3315. + +// +// types +// + +// Node Type + +#define BROADCAST_NODETYPE 1 +#define PEER_TO_PEER_NODETYPE 2 +#define MIXED_NODETYPE 4 +#define HYBRID_NODETYPE 8 + +// +// IP_ADDRESS_STRING - store an IP address as a dotted decimal string +// + +typedef struct { + char String[4 * 4]; +} IP_ADDRESS_STRING, *PIP_ADDRESS_STRING, IP_MASK_STRING, *PIP_MASK_STRING; + +// +// IP_ADDR_STRING - store an IP address with its corresponding subnet mask, +// both as dotted decimal strings +// + +typedef struct _IP_ADDR_STRING { + struct _IP_ADDR_STRING* Next; + IP_ADDRESS_STRING IpAddress; + IP_MASK_STRING IpMask; + DWORD Context; +} IP_ADDR_STRING, *PIP_ADDR_STRING; + +// +// ADAPTER_INFO - per-adapter information. All IP addresses are stored as +// strings +// + +typedef struct _IP_ADAPTER_INFO { + struct _IP_ADAPTER_INFO* Next; + DWORD ComboIndex; + char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4]; + char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4]; + UINT AddressLength; + BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH]; + DWORD Index; + UINT Type; + UINT DhcpEnabled; + PIP_ADDR_STRING CurrentIpAddress; + IP_ADDR_STRING IpAddressList; + IP_ADDR_STRING GatewayList; + IP_ADDR_STRING DhcpServer; + BOOL HaveWins; + IP_ADDR_STRING PrimaryWinsServer; + IP_ADDR_STRING SecondaryWinsServer; + time_t LeaseObtained; + time_t LeaseExpires; +} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO; + +#ifdef _WINSOCK2API_ + +// +// The following types require Winsock2. +// + +typedef NL_PREFIX_ORIGIN IP_PREFIX_ORIGIN; +typedef NL_SUFFIX_ORIGIN IP_SUFFIX_ORIGIN; +typedef NL_DAD_STATE IP_DAD_STATE; + +typedef struct _IP_ADAPTER_UNICAST_ADDRESS_LH { + union { + ULONGLONG Alignment; + struct { + ULONG Length; + DWORD Flags; + }; + }; + struct _IP_ADAPTER_UNICAST_ADDRESS_LH *Next; + SOCKET_ADDRESS Address; + + IP_PREFIX_ORIGIN PrefixOrigin; + IP_SUFFIX_ORIGIN SuffixOrigin; + IP_DAD_STATE DadState; + + ULONG ValidLifetime; + ULONG PreferredLifetime; + ULONG LeaseLifetime; + UINT8 OnLinkPrefixLength; +} IP_ADAPTER_UNICAST_ADDRESS_LH, + *PIP_ADAPTER_UNICAST_ADDRESS_LH; + +typedef struct _IP_ADAPTER_UNICAST_ADDRESS_XP { + union { + ULONGLONG Alignment; + struct { + ULONG Length; + DWORD Flags; + }; + }; + struct _IP_ADAPTER_UNICAST_ADDRESS_XP *Next; + SOCKET_ADDRESS Address; + + IP_PREFIX_ORIGIN PrefixOrigin; + IP_SUFFIX_ORIGIN SuffixOrigin; + IP_DAD_STATE DadState; + + ULONG ValidLifetime; + ULONG PreferredLifetime; + ULONG LeaseLifetime; +} IP_ADAPTER_UNICAST_ADDRESS_XP, *PIP_ADAPTER_UNICAST_ADDRESS_XP; + +#if (NTDDI_VERSION >= NTDDI_LONGHORN) +typedef IP_ADAPTER_UNICAST_ADDRESS_LH IP_ADAPTER_UNICAST_ADDRESS; +typedef IP_ADAPTER_UNICAST_ADDRESS_LH *PIP_ADAPTER_UNICAST_ADDRESS; +#elif (NTDDI_VERSION >= NTDDI_WINXP) +typedef IP_ADAPTER_UNICAST_ADDRESS_XP IP_ADAPTER_UNICAST_ADDRESS; +typedef IP_ADAPTER_UNICAST_ADDRESS_XP *PIP_ADAPTER_UNICAST_ADDRESS; +#endif + +// +// Bit values of IP_ADAPTER_UNICAST_ADDRESS Flags field. +// +#define IP_ADAPTER_ADDRESS_DNS_ELIGIBLE 0x01 +#define IP_ADAPTER_ADDRESS_TRANSIENT 0x02 + +typedef struct _IP_ADAPTER_ANYCAST_ADDRESS_XP { + union { + ULONGLONG Alignment; + struct { + ULONG Length; + DWORD Flags; + }; + }; + struct _IP_ADAPTER_ANYCAST_ADDRESS_XP *Next; + SOCKET_ADDRESS Address; +} IP_ADAPTER_ANYCAST_ADDRESS_XP, *PIP_ADAPTER_ANYCAST_ADDRESS_XP; +#if (NTDDI_VERSION >= NTDDI_WINXP) +typedef IP_ADAPTER_ANYCAST_ADDRESS_XP IP_ADAPTER_ANYCAST_ADDRESS; +typedef IP_ADAPTER_ANYCAST_ADDRESS_XP *PIP_ADAPTER_ANYCAST_ADDRESS; +#endif + +typedef struct _IP_ADAPTER_MULTICAST_ADDRESS_XP { + union { + ULONGLONG Alignment; + struct { + ULONG Length; + DWORD Flags; + }; + }; + struct _IP_ADAPTER_MULTICAST_ADDRESS_XP *Next; + SOCKET_ADDRESS Address; +} IP_ADAPTER_MULTICAST_ADDRESS_XP, *PIP_ADAPTER_MULTICAST_ADDRESS_XP; +#if (NTDDI_VERSION >= NTDDI_WINXP) +typedef IP_ADAPTER_MULTICAST_ADDRESS_XP IP_ADAPTER_MULTICAST_ADDRESS; +typedef IP_ADAPTER_MULTICAST_ADDRESS_XP *PIP_ADAPTER_MULTICAST_ADDRESS; +#endif + +typedef struct _IP_ADAPTER_DNS_SERVER_ADDRESS_XP { + union { + ULONGLONG Alignment; + struct { + ULONG Length; + DWORD Reserved; + }; + }; + struct _IP_ADAPTER_DNS_SERVER_ADDRESS_XP *Next; + SOCKET_ADDRESS Address; +} IP_ADAPTER_DNS_SERVER_ADDRESS_XP, *PIP_ADAPTER_DNS_SERVER_ADDRESS_XP; +#if (NTDDI_VERSION >= NTDDI_WINXP) +typedef IP_ADAPTER_DNS_SERVER_ADDRESS_XP IP_ADAPTER_DNS_SERVER_ADDRESS; +typedef IP_ADAPTER_DNS_SERVER_ADDRESS_XP *PIP_ADAPTER_DNS_SERVER_ADDRESS; +#endif + +typedef struct _IP_ADAPTER_WINS_SERVER_ADDRESS_LH { + union { + ULONGLONG Alignment; + struct { + ULONG Length; + DWORD Reserved; + }; + }; + struct _IP_ADAPTER_WINS_SERVER_ADDRESS_LH *Next; + SOCKET_ADDRESS Address; +} IP_ADAPTER_WINS_SERVER_ADDRESS_LH, *PIP_ADAPTER_WINS_SERVER_ADDRESS_LH; +#if (NTDDI_VERSION >= NTDDI_LONGHORN) +typedef IP_ADAPTER_WINS_SERVER_ADDRESS_LH IP_ADAPTER_WINS_SERVER_ADDRESS; +typedef IP_ADAPTER_WINS_SERVER_ADDRESS_LH *PIP_ADAPTER_WINS_SERVER_ADDRESS; +#endif + + +typedef struct _IP_ADAPTER_GATEWAY_ADDRESS_LH { + union { + ULONGLONG Alignment; + struct { + ULONG Length; + DWORD Reserved; + }; + }; + struct _IP_ADAPTER_GATEWAY_ADDRESS_LH *Next; + SOCKET_ADDRESS Address; +} IP_ADAPTER_GATEWAY_ADDRESS_LH, *PIP_ADAPTER_GATEWAY_ADDRESS_LH; +#if (NTDDI_VERSION >= NTDDI_LONGHORN) +typedef IP_ADAPTER_GATEWAY_ADDRESS_LH IP_ADAPTER_GATEWAY_ADDRESS; +typedef IP_ADAPTER_GATEWAY_ADDRESS_LH *PIP_ADAPTER_GATEWAY_ADDRESS; +#endif + +typedef struct _IP_ADAPTER_PREFIX_XP { + union { + ULONGLONG Alignment; + struct { + ULONG Length; + DWORD Flags; + }; + }; + struct _IP_ADAPTER_PREFIX_XP *Next; + SOCKET_ADDRESS Address; + ULONG PrefixLength; +} IP_ADAPTER_PREFIX_XP, *PIP_ADAPTER_PREFIX_XP; +#if (NTDDI_VERSION >= NTDDI_WINXP) +typedef IP_ADAPTER_PREFIX_XP IP_ADAPTER_PREFIX; +typedef IP_ADAPTER_PREFIX_XP *PIP_ADAPTER_PREFIX; +#endif + +// +// Bit values of IP_ADAPTER_ADDRESSES Flags field. +// +#define IP_ADAPTER_DDNS_ENABLED 0x00000001 +#define IP_ADAPTER_REGISTER_ADAPTER_SUFFIX 0x00000002 +#define IP_ADAPTER_DHCP_ENABLED 0x00000004 +#define IP_ADAPTER_RECEIVE_ONLY 0x00000008 +#define IP_ADAPTER_NO_MULTICAST 0x00000010 +#define IP_ADAPTER_IPV6_OTHER_STATEFUL_CONFIG 0x00000020 +#define IP_ADAPTER_NETBIOS_OVER_TCPIP_ENABLED 0x00000040 +#define IP_ADAPTER_IPV4_ENABLED 0x00000080 +#define IP_ADAPTER_IPV6_ENABLED 0x00000100 + +typedef struct _IP_ADAPTER_ADDRESSES_LH { + union { + ULONGLONG Alignment; + struct { + ULONG Length; + IF_INDEX IfIndex; + }; + }; + struct _IP_ADAPTER_ADDRESSES_LH *Next; + PCHAR AdapterName; + PIP_ADAPTER_UNICAST_ADDRESS_LH FirstUnicastAddress; + PIP_ADAPTER_ANYCAST_ADDRESS_XP FirstAnycastAddress; + PIP_ADAPTER_MULTICAST_ADDRESS_XP FirstMulticastAddress; + PIP_ADAPTER_DNS_SERVER_ADDRESS_XP FirstDnsServerAddress; + PWCHAR DnsSuffix; + PWCHAR Description; + PWCHAR FriendlyName; + BYTE PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH]; + ULONG PhysicalAddressLength; + union { + ULONG Flags; + struct { + ULONG DdnsEnabled : 1; + ULONG RegisterAdapterSuffix : 1; + ULONG Dhcpv4Enabled : 1; + ULONG ReceiveOnly : 1; + ULONG NoMulticast : 1; + ULONG Ipv6OtherStatefulConfig : 1; + ULONG NetbiosOverTcpipEnabled : 1; + ULONG Ipv4Enabled : 1; + ULONG Ipv6Enabled : 1; + ULONG Ipv6ManagedAddressConfigurationSupported : 1; + }; + }; + ULONG Mtu; + IFTYPE IfType; + IF_OPER_STATUS OperStatus; + IF_INDEX Ipv6IfIndex; + ULONG ZoneIndices[16]; + PIP_ADAPTER_PREFIX_XP FirstPrefix; + + ULONG64 TransmitLinkSpeed; + ULONG64 ReceiveLinkSpeed; + PIP_ADAPTER_WINS_SERVER_ADDRESS_LH FirstWinsServerAddress; + PIP_ADAPTER_GATEWAY_ADDRESS_LH FirstGatewayAddress; + ULONG Ipv4Metric; + ULONG Ipv6Metric; + IF_LUID Luid; + SOCKET_ADDRESS Dhcpv4Server; + NET_IF_COMPARTMENT_ID CompartmentId; + NET_IF_NETWORK_GUID NetworkGuid; + NET_IF_CONNECTION_TYPE ConnectionType; + TUNNEL_TYPE TunnelType; + // + // DHCP v6 Info. + // + SOCKET_ADDRESS Dhcpv6Server; + BYTE Dhcpv6ClientDuid[MAX_DHCPV6_DUID_LENGTH]; + ULONG Dhcpv6ClientDuidLength; + ULONG Dhcpv6Iaid; +} IP_ADAPTER_ADDRESSES_LH, + *PIP_ADAPTER_ADDRESSES_LH; + +typedef struct _IP_ADAPTER_ADDRESSES_XP { + union { + ULONGLONG Alignment; + struct { + ULONG Length; + DWORD IfIndex; + }; + }; + struct _IP_ADAPTER_ADDRESSES_XP *Next; + PCHAR AdapterName; + PIP_ADAPTER_UNICAST_ADDRESS_XP FirstUnicastAddress; + PIP_ADAPTER_ANYCAST_ADDRESS_XP FirstAnycastAddress; + PIP_ADAPTER_MULTICAST_ADDRESS_XP FirstMulticastAddress; + PIP_ADAPTER_DNS_SERVER_ADDRESS_XP FirstDnsServerAddress; + PWCHAR DnsSuffix; + PWCHAR Description; + PWCHAR FriendlyName; + BYTE PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH]; + DWORD PhysicalAddressLength; + DWORD Flags; + DWORD Mtu; + DWORD IfType; + IF_OPER_STATUS OperStatus; + DWORD Ipv6IfIndex; + DWORD ZoneIndices[16]; + PIP_ADAPTER_PREFIX_XP FirstPrefix; +} IP_ADAPTER_ADDRESSES_XP, + *PIP_ADAPTER_ADDRESSES_XP; + +#if (NTDDI_VERSION >= NTDDI_LONGHORN) +typedef IP_ADAPTER_ADDRESSES_LH IP_ADAPTER_ADDRESSES; +typedef IP_ADAPTER_ADDRESSES_LH *PIP_ADAPTER_ADDRESSES; +#elif (NTDDI_VERSION >= NTDDI_WINXP) +typedef IP_ADAPTER_ADDRESSES_XP IP_ADAPTER_ADDRESSES; +typedef IP_ADAPTER_ADDRESSES_XP *PIP_ADAPTER_ADDRESSES; +#else +// +// For platforms other platforms that are including +// the file but not using the types. +// +typedef IP_ADAPTER_ADDRESSES_XP IP_ADAPTER_ADDRESSES; +typedef IP_ADAPTER_ADDRESSES_XP *PIP_ADAPTER_ADDRESSES; +#endif + + +// +// Flags used as argument to GetAdaptersAddresses(). +// "SKIP" flags are added when the default is to include the information. +// "INCLUDE" flags are added when the default is to skip the information. +// +#define GAA_FLAG_SKIP_UNICAST 0x0001 +#define GAA_FLAG_SKIP_ANYCAST 0x0002 +#define GAA_FLAG_SKIP_MULTICAST 0x0004 +#define GAA_FLAG_SKIP_DNS_SERVER 0x0008 +#define GAA_FLAG_INCLUDE_PREFIX 0x0010 +#define GAA_FLAG_SKIP_FRIENDLY_NAME 0x0020 +#define GAA_FLAG_INCLUDE_WINS_INFO 0x0040 +#define GAA_FLAG_INCLUDE_GATEWAYS 0x0080 +#define GAA_FLAG_INCLUDE_ALL_INTERFACES 0x0100 +#define GAA_FLAG_INCLUDE_ALL_COMPARTMENTS 0x0200 +#define GAA_FLAG_INCLUDE_TUNNEL_BINDINGORDER 0x0400 + +#endif /* _WINSOCK2API_ */ +/* +++++++++++++++++++++++ from iptypes.h */ + + +/* +++++++++++++++++++++++ from iphlpapi.h */ +#ifdef _WINSOCK2API_ + +// +// The following functions require Winsock2. +// + +ULONG +WINAPI +GetAdaptersAddresses( + IN ULONG Family, + IN ULONG Flags, + IN PVOID Reserved, + __out_bcount_opt(*SizePointer) PIP_ADAPTER_ADDRESSES AdapterAddresses, + IN OUT PULONG SizePointer + ); + +#endif +/* +++++++++++++++++++++++ from iphlpapi.h */ + +#pragma warning(pop) +#endif /* !_W64 */ +#endif /* GAA_COMPAT_H */ diff --git a/ports/winnt/include/hopf_PCI_io.h b/ports/winnt/include/hopf_PCI_io.h new file mode 100644 index 0000000..7bca1d3 --- /dev/null +++ b/ports/winnt/include/hopf_PCI_io.h @@ -0,0 +1,91 @@ +/* + * hopf_PCI_io.h + * structur definition and prototype Function declarations + * + * Date: 21.03.2000 Revision: 01.10 + * + * Copyright (C) 1999, 2000 by Bernd Altmeier altmeier@ATLSoft.de + * + */ + +#if defined(__cplusplus) +extern "C"{ +#endif + +#ifndef __inpREAD_H +#define __inpREAD_H + + +typedef struct _CLOCKVER { + CHAR cVersion[255]; +} CLOCKVER, *PCLOCKVER, *LPCLOCKVER; + +typedef struct _HOPFTIME { + WORD wYear; + WORD wMonth; + WORD wDayOfWeek; + WORD wDay; + WORD wHour; + WORD wMinute; + WORD wSecond; + WORD wMilliseconds; + WORD wStatus; +} HOPFTIME, *PHOPFTIME, *LPHOPFTIME; + +typedef struct _SATSTAT { + BYTE wVisible; + BYTE wMode; + BYTE wSat0; + BYTE wRat0; + BYTE wSat1; + BYTE wRat1; + BYTE wSat2; + BYTE wRat2; + BYTE wSat3; + BYTE wRat3; + BYTE wSat4; + BYTE wRat4; + BYTE wSat5; + BYTE wRat5; + BYTE wSat6; + BYTE wRat6; + BYTE wSat7; + BYTE wRat7; +} SATSTAT, *PSATSTAT, *LPSATSTAT; + + +typedef struct _GPSPOS { + LONG wAltitude; // Höhe immer 0 + LONG wLongitude; // Länge in Msec + LONG wLatitude; // Breite in Msec +} GPSPOS, *PGPSPOS, *LPGPSPOS; + + +typedef struct _DCFANTENNE { + BYTE bStatus; + BYTE bStatus1; + WORD wAntValue; +} DCFANTENNE, *PDCFANTENNE, *LPDCFANTENNE; + + + +// Function declarations +BOOL OpenHopfDevice(); +BOOL CloseHopfDevice(); +VOID GetHopfTime(LPHOPFTIME Data, DWORD Offset); +VOID GetHopfLocalTime(LPHOPFTIME Data); +VOID GetHopfSystemTime(LPHOPFTIME Data); +VOID GetSatData(LPSATSTAT Data); +VOID GetDiffTime(LPLONG Data); +VOID GetPosition(LPGPSPOS Data); +VOID GetHardwareVersion(LPCLOCKVER Data); +VOID GetHardwareData(LPDWORD Data,WORD Ofs); +VOID GetDCFAntenne(LPDCFANTENNE Data); + + +#if defined(__cplusplus) +} +#endif + +#endif /* inpREAD_H */ + diff --git a/ports/winnt/include/netdb.h b/ports/winnt/include/netdb.h new file mode 100644 index 0000000..5e15997 --- /dev/null +++ b/ports/winnt/include/netdb.h @@ -0,0 +1,4 @@ +/************************************************************** + * Dummy Header for Unix to Windows NT portability + * Created for NTP package + **************************************************************/ diff --git a/ports/winnt/include/ntp_iocompletionport.h b/ports/winnt/include/ntp_iocompletionport.h new file mode 100644 index 0000000..7d7ff7c --- /dev/null +++ b/ports/winnt/include/ntp_iocompletionport.h @@ -0,0 +1,27 @@ +#if !defined __ntp_iocompletionport_h +# define __ntp_iocompletionport_h + +#include "ntp_fp.h" +#include "ntp.h" +#include "clockstuff.h" +#include "ntp_worker.h" + +# if defined(HAVE_IO_COMPLETION_PORT) + +extern void init_io_completion_port(void); +extern void uninit_io_completion_port(void); + +extern int io_completion_port_add_socket(SOCKET fd, struct interface *); + +struct refclockio; /* in ntp_refclock.h but inclusion here triggers problems */ +extern int io_completion_port_add_clock_io(struct refclockio *rio); +extern void io_completion_port_remove_clock_io(struct refclockio *rio); +extern int io_completion_port_sendto(int, void *, size_t, sockaddr_u *); + +extern int GetReceivedBuffers(void); + +extern HANDLE WaitableExitEventHandle; + +# endif + +#endif diff --git a/ports/winnt/include/ntp_timer.h b/ports/winnt/include/ntp_timer.h new file mode 100644 index 0000000..15328a6 --- /dev/null +++ b/ports/winnt/include/ntp_timer.h @@ -0,0 +1,6 @@ +#ifndef NTP_TIMER_H +#define NTP_TIMER_H + +extern void timer_clr_stats(void); + +#endif /* NTP_TIMER_H */ diff --git a/ports/winnt/include/ntservice.h b/ports/winnt/include/ntservice.h new file mode 100644 index 0000000..f44335f --- /dev/null +++ b/ports/winnt/include/ntservice.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 1999-2001 Internet Software Consortium. + * + * 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 INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM 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 NTSERVICE_H +#define NTSERVICE_H + +#define NTP_DISPLAY_NAME "NetworkTimeProtocol" +#define NTP_SERVICE_NAME "ntpd" + +void ntservice_init(void); +void UpdateSCM(DWORD); +void WINAPI ServiceControl(DWORD dwCtrlCode); +void ntservice_shutdown(void); +BOOL ntservice_systemisshuttingdown(void); +BOOL WINAPI OnConsoleEvent(DWORD dwCtrlType); + +#endif /* NTSERVICE_H */ diff --git a/ports/winnt/include/stdint.h b/ports/winnt/include/stdint.h new file mode 100644 index 0000000..4040c24 --- /dev/null +++ b/ports/winnt/include/stdint.h @@ -0,0 +1,244 @@ +/* + * stdint_msvc.h - C99 integer types for older Visual C compilers + * + * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. + * The contents of 'html/copyright.html' apply. + * + * ---------------------------------------------------------------------- + * + * Fairly straight forward implementation of the C99 standard integer + * types. + */ + +#ifndef __STDINT_INCLUDED +#define __STDINT_INCLUDED + +#if !defined(_MSC_VER) || _MSC_VER >= 1800 +# error Use only with MSVC6 - MSVC11(VS2012) +#endif + +#include <crtdefs.h> +#include <limits.h> + +/* --------------------------------------------------------------------- + * We declare the min/max values, using the MSVC syntax for literals of + * a given bit width. + */ + +#define _VC_SI_LIT(lit,wbit) (lit ## i ## wbit) +#define _VC_UI_LIT(lit,wbit) (lit ## ui ## wbit) + +/* --------------------------------------------------------------------- + * Exact width integer types + */ +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; + +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) +# define INT8_MIN _I8_MIN +# define INT8_MAX _I8_MAX +# define UINT8_MAX _UI8_MAX +# define INT16_MIN _I16_MIN +# define INT16_MAX _I16_MAX +# define UINT16_MAX _UI16_MAX +# define INT32_MIN _I32_MIN +# define INT32_MAX _I32_MAX +# define UINT32_MAX _UI32_MAX +# define INT64_MIN _I64_MIN +# define INT64_MAX _I64_MAX +# define UINT64_MAX _UI64_MAX +#endif + +/* --------------------------------------------------------------------- + * Least-size integers + * + * These are mapped to exact size. + */ +typedef __int8 int_least8_t; +typedef __int16 int_least16_t; +typedef __int32 int_least32_t; +typedef __int64 int_least64_t; + +typedef unsigned __int8 uint_least8_t; +typedef unsigned __int16 uint_least16_t; +typedef unsigned __int32 uint_least32_t; +typedef unsigned __int64 uint_least64_t; + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) +#define INT_LEAST8_MIN _I8_MIN +#define INT_LEAST8_MAX _I8_MAX +#define UINT_LEAST8_MAX _UI8_MAX +#define INT_LEAST16_MIN _I16_MIN +#define INT_LEAST16_MAX _I16_MAX +#define UINT_LEAST16_MAX _UI16_MAX +#define INT_LEAST32_MIN _I32_MIN +#define INT_LEAST32_MAX _I32_MAX +#define UINT_LEAST32_MAX _UI32_MAX +#define INT_LEAST64_MIN _I64_MIN +#define INT_LEAST64_MAX _I64_MAX +#define UINT_LEAST64_MAX _UI64_MAX +#endif + +/* --------------------------------------------------------------------- + * least-size, fastest integer + * + * The 'FAST' types are all 32 bits, except the 64 bit quantity; as the + * natural register width is 32 bits, quantities of that size are fastest + * to operate on naturally. (This even holds for the x86_64; MSVC uses + * the 'llp64' model. + */ +typedef __int32 int_fast8_t; +typedef __int32 int_fast16_t; +typedef __int32 int_fast32_t; +typedef __int64 int_fast64_t; + +typedef unsigned __int32 uint_fast8_t; +typedef unsigned __int32 uint_fast16_t; +typedef unsigned __int32 uint_fast32_t; +typedef unsigned __int64 uint_fast64_t; + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) +#define INT_FAST8_MIN _I32_MIN +#define INT_FAST8_MAX _I32_MAX +#define UINT_FAST8_MAX _UI32_MAX +#define INT_FAST16_MIN _I32_MIN +#define INT_FAST16_MAX _I32_MAX +#define UINT_FAST16_MAX _UI32_MAX +#define INT_FAST32_MIN _I32_MIN +#define INT_FAST32_MAX _I32_MAX +#define UINT_FAST32_MAX _UI32_MAX +#define INT_FAST64_MIN _I64_MIN +#define INT_FAST64_MAX _I64_MAX +#define UINT_FAST64_MAX _UI64_MAX +#endif + +/* --------------------------------------------------------------------- + * The (u)intptr_t, ptrdiff_t and size_t definitions depend on the + * target: 32bit for x86, and 64bit for x64, aka amd64. Well, we + * have to bite the bullet. + */ + +/* ------------------------------------------------------------------ */ +# if defined(_WIN64) || defined(WIN64) +/* ------------------------------------------------------------------ */ + +# ifndef _INTPTR_T_DEFINED +# define _INTPTR_T_DEFINED + typedef __int64 intptr_t; +# endif + +# ifndef _UINTPTR_T_DEFINED +# define _UINTPTR_T_DEFINED + typedef unsigned __int64 uintptr_t; +# endif + +# ifndef _PTRDIFF_T_DEFINED +# define _PTRDIFF_T_DEFINED + typedef __int64 ptrdiff_t; +# endif + +# if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) +# ifndef INTPTR_MIN +# define INTPTR_MIN _I64_MIN +# endif +# ifndef INTPTR_MAX +# define INTPTR_MAX _I64_MAX +# endif +# ifndef UINTPTR_MAX +# define UINTPTR_MAX _UI64_MAX +# endif +# ifndef PTRDIFF_MIN +# define PTRDIFF_MIN _I64_MIN +# endif +# ifndef PTRDIFF_MAX +# define PTRDIFF_MAX _I64_MAX +# endif +# endif + +/* ------------------------------------------------------------------ */ +#else /* 32 bit target assumed here! */ +/* ------------------------------------------------------------------ */ + +# ifndef _INTPTR_T_DEFINED +# define _INTPTR_T_DEFINED + typedef __int32 intptr_t; +# endif + +# ifndef _UINTPTR_T_DEFINED +# define _UINTPTR_T_DEFINED + typedef unsigned __int32 uintptr_t; +# endif + +# ifndef _PTRDIFF_T_DEFINED +# define _PTRDIFF_T_DEFINED + typedef __int64 ptrdiff_t; +# endif + +# if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) +# ifndef INTPTR_MIN +# define INTPTR_MIN _I32_MIN +# endif +# ifndef INTPTR_MAX +# define INTPTR_MAX _I32_MAX +# endif +# ifndef UINTPTR_MAX +# define UINTPTR_MAX _UI32_MAX +# endif +# ifndef PTRDIFF_MIN +# define PTRDIFF_MIN _I32_MIN +# endif +# ifndef PTRDIFF_MAX +# define PTRDIFF_MAX _I32_MAX +# endif +# endif +#endif /* platform dependent stuff */ + + +/* --------------------------------------------------------------------- + * max integer is 64-bit integer + */ +typedef __int64 intmax_t; +typedef unsigned __int64 uintmax_t; + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) +# define INTMAX_MIN _I64_MIN +# define INTMAX_MAX _I64_MAX +# define UINTMAX_MAX _UI64_MAX +#endif + +/* --------------------------------------------------------------------- + * limit for size_t (older MSVC versions lack that one) + */ +#if _MSC_VER <=1200 +# if defined(_WIN64) || defined(WIN64) +# define SIZE_MAX _UI64_MAX +#else +# define SIZE_MAX _UI32_MAX +# endif +#endif + +/* --------------------------------------------------------------------- + * construct numerical literals with precise size + */ +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) +# define INT8_C(lit) _VC_SI_LIT(lit,8) +# define UINT8_C(lit) _VC_UI_LIT(lit,8) +# define INT16_C(lit) _VC_SI_LIT(lit,16) +# define UINT16_C(lit) _VC_UI_LIT(lit,16) +# define INT32_C(lit) _VC_SI_LIT(lit,32) +# define UINT32_C(lit) _VC_UI_LIT(lit,32) +# define INT64_C(lit) _VC_SI_LIT(lit,64) +# define UINT64_C(lit) _VC_UI_LIT(lit,64) +# define INTMAX_C(lit) _VC_SI_LIT(lit,64) +# define UINTMAX_C(lit) _VC_UI_LIT(lit,64) +#endif + +#endif +/**** EOF ****/ diff --git a/ports/winnt/include/stdnoreturn.h b/ports/winnt/include/stdnoreturn.h new file mode 100644 index 0000000..65702e0 --- /dev/null +++ b/ports/winnt/include/stdnoreturn.h @@ -0,0 +1,61 @@ +/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ +/* A substitute for ISO C11 <stdnoreturn.h>. + + Copyright 2012-2014 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#ifndef noreturn + +/* ISO C11 <stdnoreturn.h> for platforms that lack it. + + References: + ISO C11 (latest free draft + <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>) + section 7.23 */ + +/* The definition of _Noreturn is copied here. */ +#if !defined _Noreturn && __STDC_VERSION__ < 201112 +# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \ + || 0x5110 <= __SUNPRO_C) +# define _Noreturn __attribute__ ((__noreturn__)) +# elif 1200 <= _MSC_VER +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn +# endif +#endif + +#if 1200 <= _MSC_VER +/* Standard include files on this platform contain declarations like + "__declspec (noreturn) void abort (void);". "#define noreturn + _Noreturn" would cause this declaration to be rewritten to the + invalid "__declspec (__declspec (noreturn)) void abort (void);". + Instead, define noreturn to empty, so that such declarations are + rewritten to "__declspec () void abort (void);", which is + equivalent to "void abort (void);"; this gives up on noreturn's + advice to the compiler but at least it is valid code. */ +# define noreturn /*empty*/ +#else +# define noreturn _Noreturn +#endif + +/* Did he ever return? + No he never returned + And his fate is still unlearn'd ... + -- Steiner J, Hawes BL. M.T.A. (1949) */ + +#endif /* noreturn */ diff --git a/ports/winnt/include/sys/ioctl.h b/ports/winnt/include/sys/ioctl.h new file mode 100644 index 0000000..6f4b076 --- /dev/null +++ b/ports/winnt/include/sys/ioctl.h @@ -0,0 +1,11 @@ +/************************************************************** + * Dummy Header for Unix to Windows NT portability + * Created for NTP package + **************************************************************/ + +#ifndef _IOCTL_H +#define _IOCTL_H + +#include "win32_io.h" + +#endif
\ No newline at end of file diff --git a/ports/winnt/include/sys/param.h b/ports/winnt/include/sys/param.h new file mode 100644 index 0000000..5e15997 --- /dev/null +++ b/ports/winnt/include/sys/param.h @@ -0,0 +1,4 @@ +/************************************************************** + * Dummy Header for Unix to Windows NT portability + * Created for NTP package + **************************************************************/ diff --git a/ports/winnt/include/sys/resource.h b/ports/winnt/include/sys/resource.h new file mode 100644 index 0000000..01f4c81 --- /dev/null +++ b/ports/winnt/include/sys/resource.h @@ -0,0 +1,10 @@ +/* + * ports/winnt/include/sys/resource.h + * + * routines declared in Unix systems' sys/resource.h + */ + +#define PRIO_PROCESS 0 +#define NTP_PRIO (-12) + +int setpriority(int, int, int); /* winnt\libntp\setpriority.c */ diff --git a/ports/winnt/include/sys/signal.h b/ports/winnt/include/sys/signal.h new file mode 100644 index 0000000..5e15997 --- /dev/null +++ b/ports/winnt/include/sys/signal.h @@ -0,0 +1,4 @@ +/************************************************************** + * Dummy Header for Unix to Windows NT portability + * Created for NTP package + **************************************************************/ diff --git a/ports/winnt/include/sys/time.h b/ports/winnt/include/sys/time.h new file mode 100644 index 0000000..b448917 --- /dev/null +++ b/ports/winnt/include/sys/time.h @@ -0,0 +1,25 @@ +/* + * ports/winnt/include/sys/time.h + * + * routines declared in Unix systems' sys/time.h + */ + +#ifndef SYS_TIME_H +#define SYS_TIME_H + +#include "ntp_types.h" +#include <time.h> +#include <sys/timeb.h> + +typedef struct timespec { + time_t tv_sec; + long tv_nsec; +} timespec_t; + +#define TIMEOFDAY 0 /* getclock() clktyp arg */ +extern int getclock(int, struct timespec *ts); +extern int gettimeofday(struct timeval *, void *); +extern int settimeofday(struct timeval *); +extern void init_win_precise_time(void); + +#endif /* SYS_TIME_H */ diff --git a/ports/winnt/include/sys/wait.h b/ports/winnt/include/sys/wait.h new file mode 100644 index 0000000..5e15997 --- /dev/null +++ b/ports/winnt/include/sys/wait.h @@ -0,0 +1,4 @@ +/************************************************************** + * Dummy Header for Unix to Windows NT portability + * Created for NTP package + **************************************************************/ diff --git a/ports/winnt/include/syslog.h b/ports/winnt/include/syslog.h new file mode 100644 index 0000000..5cbf30a --- /dev/null +++ b/ports/winnt/include/syslog.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2001 Internet Software Consortium. + * + * 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 INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM 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. + */ + +/* From BIND 9 lib/isc/include/isc/: syslog.h,v 1.4 2002/08/01 03:43:31 mayer */ + +#ifndef _SYSLOG_H +#define _SYSLOG_H + +#include <stdio.h> + +/* Constant definitions for openlog() */ +#define LOG_PID 1 +#define LOG_CONS 2 +/* NT event log does not support facility level */ +#define LOG_KERN 0 +#define LOG_USER 0 +#define LOG_MAIL 0 +#define LOG_DAEMON 0 +#define LOG_AUTH 0 +#define LOG_SYSLOG 0 +#define LOG_LPR 0 +#define LOG_LOCAL0 0 +#define LOG_LOCAL1 0 +#define LOG_LOCAL2 0 +#define LOG_LOCAL3 0 +#define LOG_LOCAL4 0 +#define LOG_LOCAL5 0 +#define LOG_LOCAL6 0 +#define LOG_LOCAL7 0 + +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but signification condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +/* + * These are ignored on NT + */ +#define LOG_NDELAY 0 /* Open the connection to syslogd immediately */ + +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +void +syslog(int level, const char *fmt, ...); + +void +openlog(const char *, int, ...); + +void +closelog(void); + +void +ModifyLogLevel(int level); + +int +setlogmask(int maskpri); + +void +InitNTLogging(FILE *, int); + +void +NTReportError(const char *, const char *); + +#endif diff --git a/ports/winnt/include/termios.h b/ports/winnt/include/termios.h new file mode 100644 index 0000000..9c1cc62 --- /dev/null +++ b/ports/winnt/include/termios.h @@ -0,0 +1,214 @@ +#ifndef NTP_WIN_TERMIOS_H +#define NTP_WIN_TERMIOS_H + +/* Flag definitions for compatibility + * ================================== +*/ + +#include <fcntl.h> + +#define NCCS 18 /* refclock_arc.c uses VTIME (17) */ +#define VEOL 3 +typedef unsigned char cc_t; +typedef unsigned int speed_t; +typedef unsigned int tcflag_t; + +struct termios +{ + tcflag_t c_iflag; /* input mode flags */ + tcflag_t c_oflag; /* output mode flags */ + tcflag_t c_cflag; /* control mode flags */ + tcflag_t c_lflag; /* local mode flags */ + cc_t c_line; /* line discipline */ + cc_t c_cc[NCCS]; /* control characters */ + speed_t c_ispeed; /* input speed */ + speed_t c_ospeed; /* output speed */ +}; + +/* c_cc characters +#define VINTR 0 +#define VQUIT 1 +#define VERASE 2 +#define VKILL 3 +#define VEOF 4 +#define VTIME 5 +#define VMIN 6 +#define VSWTC 7 +#define VSTART 8 +#define VSTOP 9 +#define VSUSP 10 +#define VEOL 11 +#define VREPRINT 12 +#define VDISCARD 13 +#define VWERASE 14 +#define VLNEXT 15 +#define VEOL2 16 +*/ + +/* c_iflag bits */ +#define IGNBRK 0000001 +#define BRKINT 0000002 +#define IGNPAR 0000004 +#define PARMRK 0000010 +#define INPCK 0000020 +#define ISTRIP 0000040 +#define INLCR 0000100 +#define IGNCR 0000200 +#define ICRNL 0000400 +#define IUCLC 0001000 +#define IXON 0002000 +#define IXANY 0004000 +#define IXOFF 0010000 +#define IMAXBEL 0020000 + +/* c_oflag bits */ +#define OPOST 0000001 +#define OLCUC 0000002 +#define ONLCR 0000004 +#define OCRNL 0000010 +#define ONOCR 0000020 +#define ONLRET 0000040 +#define OFILL 0000100 +#define OFDEL 0000200 + +#define NLDLY 0000400 +#define NL0 0000000 +#define NL1 0000400 + +#define CRDLY 0003000 +#define CR0 0000000 +#define CR1 0001000 +#define CR2 0002000 +#define CR3 0003000 + +#define TABDLY 0014000 +#define TAB0 0000000 +#define TAB1 0004000 +#define TAB2 0010000 +#define TAB3 0014000 +#define XTABS 0014000 + +#define BSDLY 0020000 +#define BS0 0000000 +#define BS1 0020000 + +#define VTDLY 0040000 +#define VT0 0000000 +#define VT1 0040000 + +#define FFDLY 0100000 +#define FF0 0000000 +#define FF1 0100000 + +/* c_cflag bit meaning */ +#define CBAUD 0010017 +#define B0 0000000 /* hang up */ +#define B50 0000001 +#define B75 0000002 +#define B110 0000003 +#define B134 0000004 +#define B150 0000005 +#define B200 0000006 +#define B300 0000007 +#define B600 0000010 +#define B1200 0000011 +#define B1800 0000012 +#define B2400 0000013 +#define B4800 0000014 +#define B9600 0000015 +#define B19200 0000016 +#define B38400 0000017 + +#define EXTA B19200 +#define EXTB B38400 + +#define CSIZE 0000060 +#define CS5 0000000 +#define CS6 0000020 +#define CS7 0000040 +#define CS8 0000060 + +#define CSTOPB 0000100 +#define CREAD 0000200 +#define PARENB 0000400 +#define PARODD 0001000 +#define HUPCL 0002000 +#define CLOCAL 0004000 + +#define CBAUDEX 0010000 +#define B57600 0010001 +#define B115200 0010002 +#define B230400 0010003 +#define B460800 0010004 + +#define CIBAUD 002003600000 /* input baud rate (not used) */ +#define CRTSCTS 020000000000 /* flow control */ + +/* c_lflag bits */ +#define ISIG 0000001 +#define ICANON 0000002 +#define XCASE 0000004 +#define ECHO 0000010 +#define ECHOE 0000020 +#define ECHOK 0000040 +#define ECHONL 0000100 +#define NOFLSH 0000200 +#define TOSTOP 0000400 +#define ECHOCTL 0001000 +#define ECHOPRT 0002000 +#define ECHOKE 0004000 +#define FLUSHO 0010000 +#define PENDIN 0040000 +#define IEXTEN 0100000 + +/* tcflow() and TCXONC use these */ +#define TCOOFF 0 +#define TCOON 1 +#define TCIOFF 2 +#define TCION 3 + +/* tcflush() and TCFLSH use these */ +#define TCIFLUSH 0 +#define TCOFLUSH 1 +#define TCIOFLUSH 2 + +/* tcsetattr uses these */ +#define TCSANOW 0 +#define TCSADRAIN 1 +#define TCSAFLUSH 2 +#define VMIN 16 +#define VTIME 17 + +/* modem lines */ +#define TIOCM_LE 0x001 +#define TIOCM_DTR 0x002 +#define TIOCM_RTS 0x004 +#define TIOCM_ST 0x008 +#define TIOCM_SR 0x010 +#define TIOCM_CTS 0x020 +#define TIOCM_CAR 0x040 +#define TIOCM_RNG 0x080 +#define TIOCM_DSR 0x100 +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RI TIOCM_RNG +#define TIOCM_OUT1 0x2000 +#define TIOCM_OUT2 0x4000 + +/* ioctl */ +#define TIOCMGET 1 +#define TIOCMSET 2 +#define TIOCMBIC 3 +#define TIOCMBIS 4 + +/* NOP cfsetospeed() and cfsetispeed() for now */ +#define cfsetospeed(dcb, spd) (0) +#define cfsetispeed(dcb, spd) (0) + +extern int closeserial (int); +extern int ioctl (int, int, int *); +extern int tcsetattr (int, int, const struct termios *); +extern int tcgetattr (int, struct termios *); +extern int tcflush (int, int); +extern int isserialhandle (HANDLE); + +#endif /* NTP_WIN_TERMIOS_H */ diff --git a/ports/winnt/include/timepps.h b/ports/winnt/include/timepps.h new file mode 100644 index 0000000..76b1bfa --- /dev/null +++ b/ports/winnt/include/timepps.h @@ -0,0 +1,811 @@ +/*********************************************************************** + * * + * Copyright (c) David L. Mills 1999-2009 * + * * + * Permission to use, copy, modify, and distribute this software and * + * its documentation for any purpose and with or without fee is hereby * + * granted, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission * + * notice appear in supporting documentation, and that the name * + * University of Delaware not be used in advertising or publicity * + * pertaining to distribution of the software without specific, * + * written prior permission. The University of Delaware makes no * + * representations about the suitability this software for any * + * purpose. It is provided "as is" without express or implied * + * warranty. * + * * + *********************************************************************** + * * + * This header file complies with "Pulse-Per-Second API for UNIX-like * + * Operating Systems, Version 1.0", rfc2783. Credit is due Jeff Mogul * + * and Marc Brett, from whom much of this code was shamelessly stolen. * + * * + * This modified timepps.h can be used to provide a PPSAPI interface * + * to a machine running Windows with one or more backend provider DLLs * + * implementing the provider interfaces defined herein. * + * * + * This Windows version was derived by Dave Hart * + * <davehart@davehart.com> from Mills' timepps-Solaris.h * + * * + *********************************************************************** + * * + * Some of this include file * + * Copyright (c) 1999 by Ulrich Windl, * + * based on code by Reg Clemens <reg@dwf.com> * + * based on code by Poul-Henning Kamp <phk@FreeBSD.org> * + * * + *********************************************************************** + * * + * "THE BEER-WARE LICENSE" (Revision 42): * + * <phk@FreeBSD.org> wrote this file. As long as you retain this * + * notice you can do whatever you want with this stuff. If we meet some* + * day, and you think this stuff is worth it, you can buy me a beer * + * in return. Poul-Henning Kamp * + * * + **********************************************************************/ + +#ifndef TIMEPPS_H +#define TIMEPPS_H + +#include "sys/time.h" /* in ntp ref source declares struct timespec */ + +/* + * The following definitions are architecture independent + */ + +#define PPS_API_VERS_1 1 /* API version number */ +#define PPS_JAN_1970 2208988800UL /* 1970 - 1900 in seconds */ +#define PPS_NANOSECOND 1000000000L /* one nanosecond in decimal */ +#define PPS_FRAC 4294967296. /* 2^32 as a double */ +#define PPS_HECTONANOSECONDS 10000000 /* 100ns units in a second */ +#define PPS_FILETIME_1970 0x019db1ded53e8000 /* unix epoch to Windows */ + +#define PPS_NORMALIZE(x) /* normalize timespec */ \ + do { \ + if ((x).tv_nsec >= PPS_NANOSECOND) { \ + (x).tv_nsec -= PPS_NANOSECOND; \ + (x).tv_sec++; \ + } else if ((x).tv_nsec < 0) { \ + (x).tv_nsec += PPS_NANOSECOND; \ + (x).tv_sec--; \ + } \ + } while (0) + +#define PPS_TSPECTONTP(x) /* convert timespec to ntp_fp */ \ + do { \ + double d_frac; \ + \ + d_frac = ((struct timespec)&(x))->tv_nsec \ + * PPS_FRAC / PPS_NANOSECOND; \ + (x).integral = ((struct timespec)&(x))->tv_sec \ + + PPS_JAN_1970; \ + (x).fractional = (unsigned int)d_frac; \ + if (d_frac >= PPS_FRAC) \ + (x).integral++; \ + } while (0) + +#define PPS_NTPTOTSPEC(x) /* convert ntp_fp to timespec */ \ + do { \ + double d_frac; \ + \ + /* careful, doing in place and tv_sec may be 64bit */ \ + d_frac = (double)((ntp_fp_t *)&(x))->fractional \ + * PPS_NANOSECOND / PPS_FRAC; \ + (x).tv_sec = ((ntp_fp_t *)&(x))->integral \ + - (time_t)PPS_JAN_1970; \ + (x).tv_nsec = (long)d_frac; \ + } while (0) + + +/* + * Device/implementation parameters (mode) + */ + +#define PPS_CAPTUREASSERT 0x01 /* capture assert events */ +#define PPS_CAPTURECLEAR 0x02 /* capture clear events */ +#define PPS_CAPTUREBOTH 0x03 /* capture assert and clear events */ + +#define PPS_OFFSETASSERT 0x10 /* apply compensation for assert ev. */ +#define PPS_OFFSETCLEAR 0x20 /* apply compensation for clear ev. */ +#define PPS_OFFSETBOTH 0x30 /* apply compensation for both */ + +#define PPS_CANWAIT 0x100 /* Can we wait for an event? */ +#define PPS_CANPOLL 0x200 /* "This bit is reserved for */ + +/* + * Kernel actions (mode) + */ + +#define PPS_ECHOASSERT 0x40 /* feed back assert event to output */ +#define PPS_ECHOCLEAR 0x80 /* feed back clear event to output */ + +/* + * Timestamp formats (tsformat) + */ + +#define PPS_TSFMT_TSPEC 0x1000 /* select timespec format */ +#define PPS_TSFMT_NTPFP 0x2000 /* select NTP format */ +#define PPS_TSFMT_BOTH (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP) + +/* + * Kernel discipline actions (not used in Windows yet) + */ + +#define PPS_KC_HARDPPS 0 /* enable kernel consumer */ +#define PPS_KC_HARDPPS_PLL 1 /* phase-lock mode */ +#define PPS_KC_HARDPPS_FLL 2 /* frequency-lock mode */ + +/* + * Type definitions + */ + +typedef unsigned long pps_seq_t; /* sequence number */ + +#pragma warning(push) +#pragma warning(disable: 201) /* nonstd extension nameless union */ + +typedef struct ntp_fp { + union ntp_fp_sec { + unsigned int integral; + int s_integral; + }; + unsigned int fractional; +} ntp_fp_t; /* NTP-compatible time stamp */ + +#pragma warning(pop) + +typedef union pps_timeu { /* timestamp format */ + struct timespec tspec; + ntp_fp_t ntpfp; + unsigned long longpad[3]; +} pps_timeu_t; /* generic data type to represent time stamps */ + +/* addition of NTP fixed-point format */ + +#define NTPFP_M_ADD(r_i, r_f, a_i, a_f) /* r += a */ \ + do { \ + register u_int32 lo_tmp; \ + register u_int32 hi_tmp; \ + \ + lo_tmp = ((r_f) & 0xffff) + ((a_f) & 0xffff); \ + hi_tmp = (((r_f) >> 16) & 0xffff) + (((a_f) >> 16) & 0xffff); \ + if (lo_tmp & 0x10000) \ + hi_tmp++; \ + (r_f) = ((hi_tmp & 0xffff) << 16) | (lo_tmp & 0xffff); \ + \ + (r_i) += (a_i); \ + if (hi_tmp & 0x10000) \ + (r_i)++; \ + } while (0) + +#define NTPFP_L_ADDS(r, a) NTPFP_M_ADD((r)->integral, (r)->fractional, \ + (a)->s_integral, (a)->fractional) + + +/* + * Timestamp information structure + */ + +typedef struct pps_info { + pps_seq_t assert_sequence; /* seq. num. of assert event */ + pps_seq_t clear_sequence; /* seq. num. of clear event */ + pps_timeu_t assert_tu; /* time of assert event */ + pps_timeu_t clear_tu; /* time of clear event */ + int current_mode; /* current mode bits */ +} pps_info_t; + +#define assert_timestamp assert_tu.tspec +#define clear_timestamp clear_tu.tspec + +#define assert_timestamp_ntpfp assert_tu.ntpfp +#define clear_timestamp_ntpfp clear_tu.ntpfp + +/* + * Parameter structure + */ + +typedef struct pps_params { + int api_version; /* API version # */ + int mode; /* mode bits */ + pps_timeu_t assert_off_tu; /* offset compensation for assert */ + pps_timeu_t clear_off_tu; /* offset compensation for clear */ +} pps_params_t; + +#define assert_offset assert_off_tu.tspec +#define clear_offset clear_off_tu.tspec + +#define assert_offset_ntpfp assert_off_tu.ntpfp +#define clear_offset_ntpfp clear_off_tu.ntpfp + +/* + *------ Here begins the implementation-specific part! ------ + */ + +#include <windows.h> +#include <errno.h> +#include <stddef.h> /* offsetof() */ +#include <io.h> /* _get_osfhandle() */ + +#ifndef EOPNOTSUPP +#define EOPNOTSUPP 45 +#endif + +typedef UINT_PTR pps_handle_t; /* pps handlebars */ + +#ifndef inline +#define inline __inline +#endif + +/* + * ntpd on Windows is typically distributed as a binary as few users + * have the tools needed to build from source. Rather than build + * a single timepps.h for Windows which knows how to talk to all + * PPS implementations frozen in time as of compiling, this timepps.h + * allows one or more backend providers to be used by naming a DLL + * which exports the provider interfaces defined here. + */ +typedef enum ppsapi_magic_tag { + PPSAPI_MAGIC_UNIT = 0x70707355, /* ppsU */ +} ppsapi_magic; + +typedef struct { + struct pps_provider_tag *provider; + void * context;/* provider's unit pointer */ + ppsapi_magic magic; /* to detect invalid handles */ + pps_params_t params; /* PPS parameters set by user */ +} pps_unit_t; + +typedef void (*ppps_ntp_timestamp_from_counter)( + ntp_fp_t *result, + ULONGLONG Timestamp, + ULONGLONG Counterstamp + ); + +typedef pps_handle_t (*pcreate_pps_handle)( + void * prov_context + ); + +/* + * ppsapi_prov_init() - exported by backend DLLs + * + * Return value is pps capabilities available to PPSAPI consumers + * via time_pps_getcaps(). + */ +#define PPSAPI_TIMEPPS_PROV_VER 2 + +typedef int (WINAPI *pppsapi_prov_init)( + int ppsapi_timepps_prov_ver, + pcreate_pps_handle create_pps_handle, + ppps_ntp_timestamp_from_counter ntp_timestamp_from_counter, + char * short_name_buf, + size_t short_name_size, + char * full_name_buf, + size_t full_name_size + ); + +typedef int (WINAPI *provtime_pps_create)( + HANDLE winhandle, /* user device handle */ + pps_handle_t *phandle /* returned handle */ + ); + +typedef int (WINAPI *provtime_pps_destroy)( + pps_unit_t * unit, + void * context + ); + +typedef int (WINAPI *provtime_pps_setparams)( + pps_unit_t * unit, + void * context, + const pps_params_t * params + ); + +typedef int (WINAPI *provtime_pps_fetch)( + pps_unit_t * unit, + void * context, + const int tsformat, + pps_info_t * pinfo, + const struct timespec * timeout + ); + +typedef int (WINAPI *provtime_pps_kcbind)( + pps_unit_t * unit, + void * context, + const int kernel_consumer, + const int edge, + const int tsformat + ); + +typedef struct pps_provider_tag { + struct pps_provider_tag *next; + int caps; + char * short_name; + char * full_name; + provtime_pps_create ptime_pps_create; + provtime_pps_destroy ptime_pps_destroy; + provtime_pps_setparams ptime_pps_setparams; + provtime_pps_fetch ptime_pps_fetch; + provtime_pps_kcbind ptime_pps_kcbind; +} ppsapi_provider; + +static ppsapi_provider * g_provider_list; +static ppsapi_provider * g_curr_provider; + + +static inline pps_handle_t +internal_create_pps_handle( + void * prov_context + ) +{ + pps_unit_t * punit; + + if (NULL == g_curr_provider) { + fprintf(stderr, "create_pps_handle: provider backend called me outside time_pps_create\n"); + punit = NULL; + } else + punit = malloc(sizeof(*punit)); + if (punit != NULL) { + punit->provider = g_curr_provider; + punit->context = prov_context; + punit->magic = PPSAPI_MAGIC_UNIT; + memset(&punit->params, 0, sizeof(punit->params)); + } + return (pps_handle_t)punit; +} + +static inline pps_unit_t * +unit_from_ppsapi_handle( + pps_handle_t handle + ) +{ + pps_unit_t *punit; + + punit = (pps_unit_t *)handle; + if (PPSAPI_MAGIC_UNIT != punit->magic) + punit = NULL; + return punit; +} + +/* + * ntpd on Windows only looks to errno after finding + * GetLastError returns NO_ERROR. To accomodate its + * use of msyslog in portable code such as refclock_atom.c, + * this implementation always clears the Windows + * error code using SetLastError(NO_ERROR) when + * returning an errno. This is also a good idea + * for any non-ntpd clients as they should rely only + * the errno for PPSAPI functions. + */ +#define RETURN_PPS_ERRNO(e) \ +do { \ + SetLastError(NO_ERROR); \ + errno = (e); \ + return -1; \ +} while (0) + + +#ifdef OWN_PPS_NTP_TIMESTAMP_FROM_COUNTER +extern void pps_ntp_timestamp_from_counter(ntp_fp_t *, ULONGLONG, ULONGLONG); +#else +/* + * helper routine for serialpps.sys ioctl which returns + * performance counter "timestamp" as well as a system + * FILETIME timestamp. Converts one of the inputs to + * NTP fixed-point format. + * + * You will probably want to supply your own and #define + * OWN_PPS_NTP_TIMESTAMP_FROM_COUNTER, as this stub + * converts only the low-resolution system timestamp. + * + * When implementing a provider, use the pointer to this + * conversion function supplied to your prov_init(), as + * the copy in your DLL will likely be the stub below, + * where you want the one provided by the PPSAPI client + * such as ntpd. + */ +static inline void +pps_ntp_timestamp_from_counter( + ntp_fp_t *result, + ULONGLONG Timestamp, + ULONGLONG Counterstamp) +{ + ULONGLONG BiasedTimestamp; + + /* convert from 100ns units to NTP fixed point format */ + + BiasedTimestamp = Timestamp - PPS_FILETIME_1970; + result->integral = PPS_JAN_1970 + + (unsigned)(BiasedTimestamp / PPS_HECTONANOSECONDS); + result->fractional = + (unsigned) ((BiasedTimestamp % PPS_HECTONANOSECONDS) * + (PPS_FRAC / PPS_HECTONANOSECONDS)); +} +#endif + + +static inline int +load_pps_provider( + char * dllpath + ) +{ + char short_name[16]; + char full_name[64]; + ppsapi_provider * prov; + HMODULE hmod; + pppsapi_prov_init pprov_init; + + prov = malloc(sizeof(*prov)); + if (NULL == prov) + return ENOMEM; + + hmod = LoadLibrary(dllpath); + if (NULL == hmod) { + fprintf(stderr, "load_pps_provider: LoadLibrary(%s) error %u\n", dllpath, GetLastError()); + free(prov); + return ENOENT; + } + + pprov_init = (pppsapi_prov_init)GetProcAddress(hmod, "ppsapi_prov_init"); + if (NULL == pprov_init) { + fprintf(stderr, "load_pps_provider: entrypoint ppsapi_prov_init not found in %s\n", dllpath); + free(prov); + FreeLibrary(hmod); + return EFAULT; + } + + prov->caps = (*pprov_init)(PPSAPI_TIMEPPS_PROV_VER, + &internal_create_pps_handle, + &pps_ntp_timestamp_from_counter, + short_name, sizeof(short_name), + full_name, sizeof(full_name)); + + if (!prov->caps) { + free(prov); + FreeLibrary(hmod); + return EACCES; + } + + prov->short_name = _strdup(short_name); + prov->full_name = _strdup(full_name); + + if (NULL == prov->short_name || !prov->short_name[0] + || NULL == prov->full_name || !prov->full_name[0]) { + + if (prov->short_name) + free(prov->short_name); + if (prov->full_name) + free(prov->full_name); + free(prov); + FreeLibrary(hmod); + return EINVAL; + } + + prov->ptime_pps_create = (provtime_pps_create) + GetProcAddress(hmod, "prov_time_pps_create"); + prov->ptime_pps_destroy = (provtime_pps_destroy) + GetProcAddress(hmod, "prov_time_pps_destroy"); + prov->ptime_pps_setparams = (provtime_pps_setparams) + GetProcAddress(hmod, "prov_time_pps_setparams"); + prov->ptime_pps_fetch = (provtime_pps_fetch) + GetProcAddress(hmod, "prov_time_pps_fetch"); + prov->ptime_pps_kcbind = (provtime_pps_kcbind) + GetProcAddress(hmod, "prov_time_pps_kcbind"); + + if (NULL == prov->ptime_pps_create + || NULL == prov->ptime_pps_destroy + || NULL == prov->ptime_pps_setparams + || NULL == prov->ptime_pps_fetch + || NULL == prov->ptime_pps_kcbind) { + + fprintf(stderr, "PPSAPI provider %s missing entrypoint\n", + prov->short_name); + free(prov->short_name); + free(prov->full_name); + free(prov); + FreeLibrary(hmod); + return EINVAL; + } + + fprintf(stderr, "loaded PPSAPI provider %s caps 0x%x provider %p\n", + prov->full_name, prov->caps, prov); + + prov->next = g_provider_list; + g_provider_list = prov; + + return 0; +} + + +/* + * time_pps_create - create PPS handle from file descriptor + * + * This is the initial entrypoint of PPSAPI from the client. Note + * to maintain source compatibility with Unix, the input file + * descriptor really is a descriptor from the C runtime low-numbered + * descriptor namespace, though it may have been converted from a + * native Windows HANDLE using _open_osfhandle(). + */ +static inline int +time_pps_create( + int filedes,/* device file descriptor */ + pps_handle_t * phandle /* returned handle */ + ) +{ + HANDLE winhandle; + char * dlls; + char * dll; + char * pch; + ppsapi_provider * prov; + pps_handle_t ppshandle; + int err; + + if (NULL == phandle) + RETURN_PPS_ERRNO(EFAULT); + + winhandle = (HANDLE)_get_osfhandle(filedes); + fprintf(stderr, "time_pps_create(%d) got winhandle %p\n", filedes, winhandle); + if (INVALID_HANDLE_VALUE == winhandle) + RETURN_PPS_ERRNO(EBADF); + + /* + * For initial testing the list of PPSAPI backend + * providers is provided by the environment variable + * PPSAPI_DLLS, separated by semicolons such as + * PPSAPI_DLLS=c:\ntp\serial_ppsapi.dll;..\parport_ppsapi.dll + * There are a million better ways, such as a well-known + * registry key under which a value is created for each + * provider DLL installed, or even a platform-specific + * ntp.conf directive or command-line switch. + */ + dlls = getenv("PPSAPI_DLLS"); + if (dlls != NULL && NULL == g_provider_list) { + dlls = dll = _strdup(dlls); + fprintf(stderr, "getenv(PPSAPI_DLLS) gives %s\n", dlls); + } else + dlls = dll = NULL; + + while (dll != NULL && dll[0]) { + pch = strchr(dll, ';'); + if (pch != NULL) + *pch = 0; + err = load_pps_provider(dll); + if (err) { + fprintf(stderr, "load_pps_provider(%s) got errno %d\n", dll, err); + RETURN_PPS_ERRNO(err); + } + dll = (NULL == pch) + ? NULL + : pch + 1; + } + + if (NULL != dlls) + free(dlls); + dlls = dll = NULL; + + /* + * Hand off to each provider in turn until one returns a PPS + * handle or they've all declined. + */ + for (prov = g_provider_list; prov != NULL; prov = prov->next) { + ppshandle = 0; + g_curr_provider = prov; + err = (*prov->ptime_pps_create)(winhandle, &ppshandle); + g_curr_provider = NULL; + fprintf(stderr, "%s prov_time_pps_create(%p) returned %d\n", + prov->short_name, winhandle, err); + if (!err && ppshandle) { + *phandle = ppshandle; + return 0; + } + } + + fprintf(stderr, "PPSAPI provider list %p\n", g_provider_list); + + RETURN_PPS_ERRNO(ENOEXEC); +} + + +/* + * release PPS handle + */ + +static inline int +time_pps_destroy( + pps_handle_t handle + ) +{ + pps_unit_t * punit; + int err; + + if (!handle) + RETURN_PPS_ERRNO(EBADF); + + punit = unit_from_ppsapi_handle(handle); + + if (NULL == punit) + RETURN_PPS_ERRNO(EBADF); + + err = (*punit->provider->ptime_pps_destroy)(punit, punit->context); + + free(punit); + + if (err) + RETURN_PPS_ERRNO(err); + else + return 0; +} + +/* + * set parameters for handle + */ + +static inline int +time_pps_setparams( + pps_handle_t handle, + const pps_params_t *params + ) +{ + pps_unit_t * punit; + int err; + + /* + * Check for valid arguments and set parameters. + */ + if (!handle) + RETURN_PPS_ERRNO(EBADF); + + punit = unit_from_ppsapi_handle(handle); + + if (NULL == punit) + RETURN_PPS_ERRNO(EBADF); + + if (NULL == params) + RETURN_PPS_ERRNO(EFAULT); + + err = (*punit->provider->ptime_pps_setparams)(punit, punit->context, params); + + if (err) + RETURN_PPS_ERRNO(err); + else + return 0; +} + +/* + * get parameters for handle + */ + +static inline int +time_pps_getparams( + pps_handle_t handle, + pps_params_t *params_buf + ) +{ + pps_unit_t * punit; + + /* + * Check for valid arguments and get parameters. + */ + if (!handle) + RETURN_PPS_ERRNO(EBADF); + + punit = unit_from_ppsapi_handle(handle); + + if (NULL == punit) + RETURN_PPS_ERRNO(EBADF); + + if (NULL == params_buf) + RETURN_PPS_ERRNO(EFAULT); + + *params_buf = punit->params; + return 0; +} + + +/* + * time_pps_getcap - get capabilities for handle + */ +static inline int +time_pps_getcap( + pps_handle_t handle, + int *pmode + ) +{ + pps_unit_t * punit; + + /* + * Check for valid arguments and get capabilities. + */ + if (!handle) + RETURN_PPS_ERRNO(EBADF); + + punit = unit_from_ppsapi_handle(handle); + + if (NULL == punit) + RETURN_PPS_ERRNO(EBADF); + + if (NULL == pmode) + RETURN_PPS_ERRNO(EFAULT); + + *pmode = punit->provider->caps; + return 0; +} + +/* + * Fetch timestamps + */ + +static inline int +time_pps_fetch( + pps_handle_t handle, + const int tsformat, + pps_info_t * pinfo, + const struct timespec * ptimeout + ) +{ + pps_unit_t * punit; + int err; + + /* + * Check for valid arguments and fetch timestamps + */ + if (!handle) + RETURN_PPS_ERRNO(EBADF); + + if (NULL == pinfo) + RETURN_PPS_ERRNO(EFAULT); + + punit = unit_from_ppsapi_handle(handle); + + if (NULL == punit) + RETURN_PPS_ERRNO(EBADF); + + err = (*punit->provider->ptime_pps_fetch)(punit, + punit->context, + tsformat, + pinfo, + ptimeout); + + if (err) + RETURN_PPS_ERRNO(err); + else + return 0; +} + +/* + * time_pps_kcbind - specify kernel consumer + * + * Not supported so far by Windows. + */ + +static inline int +time_pps_kcbind( + pps_handle_t handle, + const int kernel_consumer, + const int edge, const int tsformat + ) +{ + pps_unit_t * punit; + int err; + + if (!handle) + RETURN_PPS_ERRNO(EBADF); + + punit = unit_from_ppsapi_handle(handle); + + if (NULL == punit) + RETURN_PPS_ERRNO(EBADF); + + err = (*punit->provider->ptime_pps_kcbind)( + punit, + punit->context, + kernel_consumer, + edge, + tsformat); + + if (err) + RETURN_PPS_ERRNO(err); + else + return 0; +} + + +#endif /* TIMEPPS_H */ diff --git a/ports/winnt/include/unistd.h b/ports/winnt/include/unistd.h new file mode 100644 index 0000000..5e15997 --- /dev/null +++ b/ports/winnt/include/unistd.h @@ -0,0 +1,4 @@ +/************************************************************** + * Dummy Header for Unix to Windows NT portability + * Created for NTP package + **************************************************************/ diff --git a/ports/winnt/include/win32_io.h b/ports/winnt/include/win32_io.h new file mode 100644 index 0000000..8f67ca1 --- /dev/null +++ b/ports/winnt/include/win32_io.h @@ -0,0 +1,7 @@ +#ifndef WIN32_IO_H +#define WIN32_IO_H + +extern void InitSockets(void); +extern void connection_reset_fix(SOCKET fd, sockaddr_u *addr); + +#endif /* WIN32_IO_H */ |