1/* 2 * Collect all machine dependent idiosyncrasies in one place. 3 */ 4 5#ifndef NTP_MACHINE_H 6#define NTP_MACHINE_H 7 8#ifdef HAVE_CONFIG_H 9# include <config.h> 10#endif 11 12#ifdef TIME_WITH_SYS_TIME 13# include <sys/time.h> 14# include <time.h> 15#else 16# ifdef HAVE_SYS_TIME_H 17# include <sys/time.h> 18# else 19# include <time.h> 20# endif 21#endif 22 23#include "ntp_proto.h" 24 25/* 26 27 HEY! CHECK THIS OUT! 28 29 The first half of this file is obsolete, and is only there to help 30 reconcile "what went before" with "current behavior". 31 32 The per-system SYS_* #defins ARE NO LONGER USED, with the temporary 33 exception of SYS_WINNT. 34 35 If you find a hunk of code that is bracketed by a SYS_* macro and you 36 *know* that it is still needed, please let us know. In many cases the 37 code fragment is now handled somewhere else by autoconf choices. 38 39*/ 40 41/* 42 43INFO ON NEW KERNEL PLL SYS CALLS 44 45 NTP_SYSCALLS_STD - use the "normal" ones 46 NTP_SYSCALL_GET - SYS_ntp_gettime id 47 NTP_SYSCALL_ADJ - SYS_ntp_adjtime id 48 NTP_SYSCALLS_LIBC - ntp_adjtime() and ntp_gettime() are in libc. 49 50HOW TO GET IP INTERFACE INFORMATION 51 52 Some UNIX V.4 machines implement a sockets library on top of 53 streams. For these systems, you must use send the SIOCGIFCONF down 54 the stream in an I_STR ioctl. This ususally also implies 55 USE_STREAMS_DEVICE FOR IF_CONFIG. Dell UNIX is a notable exception. 56 57WHAT DOES IOCTL(SIOCGIFCONF) RETURN IN THE BUFFER 58 59 UNIX V.4 machines implement a sockets library on top of streams. 60 When requesting the IP interface configuration with an ioctl(2) calll, 61 an array of ifreq structures are placed in the provided buffer. Some 62 implementations also place the length of the buffer information in 63 the first integer position of the buffer. 64 65 SIZE_RETURNED_IN_BUFFER - size integer is in the buffer 66 67WILL IOCTL(SIOCGIFCONF) WORK ON A SOCKET 68 69 Some UNIX V.4 machines do not appear to support ioctl() requests for the 70 IP interface configuration on a socket. They appear to require the use 71 of the streams device instead. 72 73 USE_STREAMS_DEVICE_FOR_IF_CONFIG - use the /dev/ip device for configuration 74 75MISC 76 77 DOSYNCTODR - Resync TODR clock every hour. 78 RETSIGTYPE - Define signal function type. 79 NO_SIGNED_CHAR_DECL - No "signed char" see include/ntp.h 80 LOCK_PROCESS - Have plock. 81*/ 82 83#if !defined(HAVE_NTP_ADJTIME) && defined(HAVE___ADJTIMEX) 84# define ntp_adjtime __adjtimex 85#endif 86 87#if 0 88 89/* 90 * IRIX 4.X and IRIX 5.x 91 */ 92#if defined(SYS_IRIX4)||defined(SYS_IRIX5) 93# define ADJTIME_IS_ACCURATE 94# define LOCK_PROCESS 95#endif 96 97/* 98 * Ultrix 99 * Note: posix version has NTP_POSIX_SOURCE and HAVE_SIGNALED_IO 100 */ 101#if defined(SYS_ULTRIX) 102# define S_CHAR_DEFINED 103# define NTP_SYSCALLS_STD 104# define HAVE_MODEM_CONTROL 105#endif 106 107/* 108 * AUX 109 */ 110#if defined(SYS_AUX2) || defined(SYS_AUX3) 111# define NO_SIGNED_CHAR_DECL 112# define LOCK_PROCESS 113# define NTP_POSIX_SOURCE 114/* 115 * This requires that _POSIX_SOURCE be forced on the 116 * compiler command flag. We can't do it here since this 117 * file is included _after_ the system header files and we 118 * need to let _them_ know we're POSIX. We do this in 119 * compilers/aux3.gcc... 120 */ 121# define LOG_NTP LOG_LOCAL1 122#endif 123 124/* 125 * HPUX 126 */ 127#if defined(SYS_HPUX) 128# define getdtablesize() sysconf(_SC_OPEN_MAX) 129# define setlinebuf(f) setvbuf(f, NULL, _IOLBF, 0) 130# define NO_SIGNED_CHAR_DECL 131# define LOCK_PROCESS 132#endif 133 134/* 135 * BSD/OS 2.0 and above 136 */ 137#if defined(SYS_BSDI) 138# define USE_FSETOWNCTTY /* this funny system demands a CTTY for FSETOWN */ 139#endif 140 141/* 142 * FreeBSD 2.0 and above 143 */ 144#ifdef SYS_FREEBSD 145# define KERNEL_PLL 146#endif 147 148/* 149 * Linux 150 */ 151#if defined(SYS_LINUX) 152# define ntp_adjtime __adjtimex 153#endif 154 155/* 156 * PTX 157 */ 158#if defined(SYS_PTX) 159# define LOCK_PROCESS 160struct timezone { int __0; }; /* unused placebo */ 161/* 162 * no comment !@! 163 */ 164typedef unsigned int u_int; 165# ifndef _NETINET_IN_SYSTM_INCLUDED /* i am about to comment... */ 166typedef unsigned char u_char; 167typedef unsigned short u_short; 168typedef unsigned long u_long; 169# endif 170#endif 171 172/* 173 * UNIX V.4 on and NCR 3000 174 */ 175#if defined(SYS_SVR4) 176# define STREAM 177# define LOCK_PROCESS 178# define SIZE_RETURNED_IN_BUFFER 179#endif 180 181/* 182 * (Univel/Novell) Unixware1 SVR4 on intel x86 processor 183 */ 184#if defined(SYS_UNIXWARE1) 185/* #define _POSIX_SOURCE */ 186# define STREAM 187# define STREAMS 188# undef STEP_SLEW /* TWO step */ 189# define LOCK_PROCESS 190# define SIZE_RETURNED_IN_BUFFER 191# include <sys/sockio.h> 192# include <sys/types.h> 193# include <netinet/in_systm.h> 194#endif 195 196/* 197 * DomainOS 198 */ 199#if defined(SYS_DOMAINOS) 200# define NTP_SYSCALLS_STD 201/* older versions of domain/os don't have class D */ 202# ifndef IN_CLASSD 203# define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) 204# define IN_CLASSD_NET 0xf0000000 205# define IN_CLASSD_NSHIFT 28 206# define IN_CLASSD_HOST 0xfffffff 207# define IN_MULTICAST(i) IN_CLASSD(i) 208# endif 209#endif 210 211/* 212 * Fujitsu UXP/V 213 */ 214#if defined(SYS_UXPV) 215# define LOCK_PROCESS 216# define SIZE_RETURNED_IN_BUFFER 217#endif 218 219 220#endif /* 0 */ 221 222/* 223 * Define these here for non-Windows NT systems 224 * SOCKET and INVALID_SOCKET are native macros 225 * on Windows NT and since they have different 226 * requirements we use them in the code and 227 * make them macros for everyone else 228 */ 229#ifndef SYS_WINNT 230typedef int SOCKET; 231# define INVALID_SOCKET -1 232# define SOCKET_ERROR -1 233# define closesocket(fd) close(fd) 234#endif 235 236int ntp_set_tod (struct timeval *tvp, void *tzp); 237 238#if defined (SYS_CYGWIN32) 239#include <windows.h> 240#define __int64 long long 241#endif 242 243/*casey Tue May 27 15:45:25 SAT 1997*/ 244#ifdef SYS_VXWORKS 245 246/* casey's new defines */ 247#define NO_MAIN_ALLOWED 1 248#define NO_NETDB 1 249#define NO_RENAME 1 250 251/* in vxWorks we use FIONBIO, but the others are defined for old systems, so 252 * all hell breaks loose if we leave them defined we define USE_FIONBIO to 253 * undefine O_NONBLOCK FNDELAY O_NDELAY where necessary. 254 */ 255#define USE_FIONBIO 1 256/* end my new defines */ 257 258#define TIMEOFDAY 0x0 /* system wide realtime clock */ 259#define HAVE_GETCLOCK 1 /* configure does not set this ... */ 260#define HAVE_NO_NICE 1 /* configure does not set this ... */ 261#define HAVE_RANDOM 1 /* configure does not set this ... */ 262#define HAVE_SRANDOM 1 /* configure does not set this ... */ 263 264#define NODETACH 1 265 266/* vxWorks specific additions to take care of its 267 * unix (non)complicance 268 */ 269 270#include "vxWorks.h" 271#include "ioLib.h" 272#include "taskLib.h" 273#include "time.h" 274 275extern int sysClkRateGet (); 276 277/* usrtime.h 278 * Bob Herlien's excellent time code find it at: 279 * ftp://ftp.atd.ucar.edu/pub/vxworks/vx/usrTime.shar 280 * I would recommend this instead of clock_[g|s]ettime() plus you get 281 * adjtime() too ... casey 282 */ 283/* 284extern int gettimeofday ( struct timeval *tp, struct timezone *tzp ); 285extern int settimeofday (struct timeval *, struct timezone *); 286extern int adjtime ( struct timeval *delta, struct timeval *olddelta ); 287 */ 288 289/* in machines.c */ 290extern void sleep (int seconds); 291extern void alarm (int seconds); 292/* machines.c */ 293 294 295/* this is really this */ 296#define getpid taskIdSelf 297#define getclock clock_gettime 298#define fcntl ioctl 299#define _getch getchar 300 301/* define this away for vxWorks */ 302#define openlog(x,y) 303/* use local defines for these */ 304#undef min 305#undef max 306 307#endif /* SYS_VXWORKS */ 308 309#ifdef NO_NETDB 310/* These structures are needed for gethostbyname() etc... */ 311/* structures used by netdb.h */ 312struct hostent { 313 char *h_name; /* official name of host */ 314 char **h_aliases; /* alias list */ 315 int h_addrtype; /* host address type */ 316 int h_length; /* length of address */ 317 char **h_addr_list; /* list of addresses from name server */ 318#define h_addr h_addr_list[0] /* address, for backward compatibility */ 319}; 320 321struct servent { 322 char *s_name; /* official service name */ 323 char **s_aliases; /* alias list */ 324 int s_port; /* port # */ 325 char *s_proto; /* protocol to use */ 326}; 327extern int h_errno; 328 329#define TRY_AGAIN 2 330 331struct hostent *gethostbyname (char * netnum); 332struct hostent *gethostbyaddr (char * netnum, int size, int addr_type); 333/* type is the protocol */ 334struct servent *getservbyname (char *name, char *type); 335#endif /* NO_NETDB */ 336 337#ifdef NO_MAIN_ALLOWED 338/* we have no main routines so lets make a plan */ 339#define CALL(callname, progname, callmain) \ 340 extern int callmain (int,char**); \ 341 void callname (a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \ 342 char *a0; \ 343 char *a1; \ 344 char *a2; \ 345 char *a3; \ 346 char *a4; \ 347 char *a5; \ 348 char *a6; \ 349 char *a7; \ 350 char *a8; \ 351 char *a9; \ 352 char *a10; \ 353 { \ 354 char *x[11]; \ 355 int argc; \ 356 char *argv[] = {progname,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; \ 357 int i; \ 358 for (i=0;i<11;i++) \ 359 x[i] = NULL; \ 360 x[0] = a0; \ 361 x[1] = a1; \ 362 x[2] = a2; \ 363 x[3] = a3; \ 364 x[4] = a4; \ 365 x[5] = a5; \ 366 x[6] = a6; \ 367 x[7] = a7; \ 368 x[8] = a8; \ 369 x[9] = a9; \ 370 x[10] = a10; \ 371 argc=1; \ 372 for (i=0; i<11;i++) \ 373 if (x[i]) \ 374 { \ 375 argv[argc++] = x[i]; \ 376 } \ 377 callmain(argc,argv); \ 378 } 379#endif /* NO_MAIN_ALLOWED */ 380/*casey Tue May 27 15:45:25 SAT 1997*/ 381 382/* 383 * Here's where autoconfig starts to take over 384 */ 385#ifdef HAVE_SYS_STROPTS_H 386# ifdef HAVE_SYS_STREAM_H 387# define STREAM 388# endif 389#endif 390 391#ifndef RETSIGTYPE 392# if defined(NTP_POSIX_SOURCE) 393# define RETSIGTYPE void 394# else 395# define RETSIGTYPE int 396# endif 397#endif 398 399#ifdef NTP_SYSCALLS_STD 400# ifndef NTP_SYSCALL_GET 401# define NTP_SYSCALL_GET 235 402# endif 403# ifndef NTP_SYSCALL_ADJ 404# define NTP_SYSCALL_ADJ 236 405# endif 406#endif /* NTP_SYSCALLS_STD */ 407 408#ifdef MPE 409# include <sys/types.h> 410# include <netinet/in.h> 411# include <stdio.h> 412# include <time.h> 413 414/* missing functions that are easily renamed */ 415 416# define _getch getchar 417 418/* special functions that require MPE-specific wrappers */ 419 420# define bind __ntp_mpe_bind 421# define fcntl __ntp_mpe_fcntl 422 423/* standard macros missing from MPE include files */ 424 425# define IN_CLASSD(i) ((((long)(i))&0xf0000000)==0xe0000000) 426# define IN_MULTICAST IN_CLASSD 427# define ITIMER_REAL 0 428# define MAXHOSTNAMELEN 64 429 430/* standard structures missing from MPE include files */ 431 432struct itimerval { 433 struct timeval it_interval; /* timer interval */ 434 struct timeval it_value; /* current value */ 435}; 436 437/* various declarations to make gcc stop complaining */ 438 439extern int __filbuf(FILE *); 440extern int __flsbuf(int, FILE *); 441extern int gethostname(char *, int); 442extern unsigned long inet_addr(char *); 443extern char *strdup(const char *); 444 445/* miscellaneous NTP macros */ 446 447# define HAVE_NO_NICE 448#endif /* MPE */ 449 450#ifdef HAVE_RTPRIO 451# define HAVE_NO_NICE 452#else 453# ifdef HAVE_SETPRIORITY 454# define HAVE_BSD_NICE 455# else 456# ifdef HAVE_NICE 457# define HAVE_ATT_NICE 458# endif 459# endif 460#endif 461 462#if !defined(HAVE_ATT_NICE) \ 463 && !defined(HAVE_BSD_NICE) \ 464 && !defined(HAVE_NO_NICE) 465#include "ERROR: You must define one of the HAVE_xx_NICE defines!" 466#endif 467 468/* 469 * use only one tty model - no use in initialising 470 * a tty in three ways 471 * HAVE_TERMIOS is preferred over HAVE_SYSV_TTYS over HAVE_BSD_TTYS 472 */ 473 474#ifdef HAVE_TERMIOS_H 475# define HAVE_TERMIOS 476#else 477# ifdef HAVE_TERMIO_H 478# define HAVE_SYSV_TTYS 479# else 480# ifdef HAVE_SGTTY_H 481# define HAVE_BSD_TTYS 482# endif 483# endif 484#endif 485 486#ifdef HAVE_TERMIOS 487# undef HAVE_BSD_TTYS 488# undef HAVE_SYSV_TTYS 489#endif 490 491#ifndef HAVE_TIMEGM 492extern time_t timegm (struct tm *); 493#endif 494 495#ifdef HAVE_SYSV_TTYS 496# undef HAVE_BSD_TTYS 497#endif 498 499#if !defined(SYS_WINNT) && !defined(VMS) && !defined(SYS_VXWORKS) 500# if !defined(HAVE_SYSV_TTYS) \ 501 && !defined(HAVE_BSD_TTYS) \ 502 && !defined(HAVE_TERMIOS) 503#include "ERROR: no tty type defined!" 504# endif 505#endif /* SYS_WINNT || VMS || SYS_VXWORKS*/ 506 507#ifdef WORDS_BIGENDIAN 508# define XNTP_BIG_ENDIAN 1 509#else 510# define XNTP_LITTLE_ENDIAN 1 511#endif 512 513/* 514 * Byte order woes. 515 * This used to be resolved by calling ntohl() and htonl() to swap things 516 * around, but this turned out to be quite costly on Vaxes where those 517 * things are actual functions. The code now straightens out byte 518 * order troubles on its own, with no performance penalty for little 519 * end first machines, but at great expense to cleanliness. 520 */ 521#if !defined(XNTP_BIG_ENDIAN) && !defined(XNTP_LITTLE_ENDIAN) 522 /* 523 * Pick one or the other. 524 */ 525 BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION 526#endif 527 528#if defined(XNTP_BIG_ENDIAN) && defined(XNTP_LITTLE_ENDIAN) 529 /* 530 * Pick one or the other. 531 */ 532 BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION 533#endif 534 535#endif /* NTP_MACHINE_H */ 536