2 * Collect all machine dependent idiosyncrasies in one place.
12 #ifdef TIME_WITH_SYS_TIME
13 # include <sys/time.h>
16 # ifdef HAVE_SYS_TIME_H
17 # include <sys/time.h>
23 #include "ntp_proto.h"
29 The first half of this file is obsolete, and is only there to help
30 reconcile "what went before" with "current behavior".
32 The per-system SYS_* #defins ARE NO LONGER USED, with the temporary
33 exception of SYS_WINNT.
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.
43 INFO ON NEW KERNEL PLL SYS CALLS
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.
50 HOW TO GET IP INTERFACE INFORMATION
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.
57 STREAMS_TLI - use ioctl(I_STR) to implement ioctl(SIOCGIFCONF)
59 WHAT DOES IOCTL(SIOCGIFCONF) RETURN IN THE BUFFER
61 UNIX V.4 machines implement a sockets library on top of streams.
62 When requesting the IP interface configuration with an ioctl(2) calll,
63 an array of ifreq structures are placed in the provided buffer. Some
64 implementations also place the length of the buffer information in
65 the first integer position of the buffer.
67 SIZE_RETURNED_IN_BUFFER - size integer is in the buffer
69 WILL IOCTL(SIOCGIFCONF) WORK ON A SOCKET
71 Some UNIX V.4 machines do not appear to support ioctl() requests for the
72 IP interface configuration on a socket. They appear to require the use
73 of the streams device instead.
75 USE_STREAMS_DEVICE_FOR_IF_CONFIG - use the /dev/ip device for configuration
79 HAVE_PROTOTYPES - Prototype functions
80 DOSYNCTODR - Resync TODR clock every hour.
81 RETSIGTYPE - Define signal function type.
82 NO_SIGNED_CHAR_DECL - No "signed char" see include/ntp.h
83 LOCK_PROCESS - Have plock.
85 - these systems deliver broadcast packets to the wildcard
86 port instead to a port bound to the interface bound
87 to the correct broadcast address - are these
88 implementations broken or did the spec change ?
92 * Set up for prototyping (duplicated from ntp_types.h)
95 #if defined(__STDC__) || defined(HAVE_PROTOTYPES)
97 #else /* not __STDC__ and not HAVE_PROTOTYPES */
99 #endif /* not __STDC__ and not HAVE_PROTOTYPES */
105 * IRIX 4.X and IRIX 5.x
107 #if defined(SYS_IRIX4)||defined(SYS_IRIX5)
108 # define ADJTIME_IS_ACCURATE
109 # define LOCK_PROCESS
114 * Note: posix version has NTP_POSIX_SOURCE and HAVE_SIGNALED_IO
116 #if defined(SYS_ULTRIX)
117 # define S_CHAR_DEFINED
118 # define NTP_SYSCALLS_STD
119 # define HAVE_MODEM_CONTROL
125 #if defined(SYS_AUX2) || defined(SYS_AUX3)
126 # define NO_SIGNED_CHAR_DECL
127 # define LOCK_PROCESS
128 # define NTP_POSIX_SOURCE
130 * This requires that _POSIX_SOURCE be forced on the
131 * compiler command flag. We can't do it here since this
132 * file is included _after_ the system header files and we
133 * need to let _them_ know we're POSIX. We do this in
134 * compilers/aux3.gcc...
136 # define LOG_NTP LOG_LOCAL1
142 #if defined(SYS_HPUX)
143 # define getdtablesize() sysconf(_SC_OPEN_MAX)
144 # define setlinebuf(f) setvbuf(f, NULL, _IOLBF, 0)
145 # define NO_SIGNED_CHAR_DECL
146 # define LOCK_PROCESS
150 * BSD/OS 2.0 and above
152 #if defined(SYS_BSDI)
153 # define USE_FSETOWNCTTY /* this funny system demands a CTTY for FSETOWN */
157 * FreeBSD 2.0 and above
166 #if defined(SYS_LINUX)
167 # define ntp_adjtime __adjtimex
174 # define LOCK_PROCESS
175 struct timezone { int __0; }; /* unused placebo */
179 typedef unsigned int u_int;
180 # ifndef _NETINET_IN_SYSTM_INCLUDED /* i am about to comment... */
181 typedef unsigned char u_char;
182 typedef unsigned short u_short;
183 typedef unsigned long u_long;
188 * UNIX V.4 on and NCR 3000
190 #if defined(SYS_SVR4)
192 # define LOCK_PROCESS
193 # define SIZE_RETURNED_IN_BUFFER
197 * (Univel/Novell) Unixware1 SVR4 on intel x86 processor
199 #if defined(SYS_UNIXWARE1)
200 /* #define _POSIX_SOURCE */
203 # undef STEP_SLEW /* TWO step */
204 # define LOCK_PROCESS
205 # define SIZE_RETURNED_IN_BUFFER
206 # include <sys/sockio.h>
207 # include <sys/types.h>
208 # include <netinet/in_systm.h>
214 #if defined(SYS_DOMAINOS)
215 # define NTP_SYSCALLS_STD
216 /* older versions of domain/os don't have class D */
218 # define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
219 # define IN_CLASSD_NET 0xf0000000
220 # define IN_CLASSD_NSHIFT 28
221 # define IN_CLASSD_HOST 0xfffffff
222 # define IN_MULTICAST(i) IN_CLASSD(i)
229 #if defined(SYS_UXPV)
230 # define LOCK_PROCESS
231 # define SIZE_RETURNED_IN_BUFFER
238 * Define these here for non-Windows NT systems
239 * SOCKET and INVALID_SOCKET are native macros
240 * on Windows NT and since they have different
241 * requirements we use them in the code and
242 * make them macros for everyone else
246 # define INVALID_SOCKET -1
247 # define closesocket close
252 #if defined(SYS_WINNT)
253 # if !defined(HAVE_CONFIG_H) || !defined(__config)
255 # endif /* HAVE_CONFIG_H) */
256 # include <windows.h>
257 # include <ws2tcpip.h>
258 # include <winsock2.h>
260 # define ifreq _INTERFACE_INFO
261 # define ifr_flags iiFlags
262 # define ifr_addr iiAddress.AddressIn
263 # define ifr_broadaddr iiBroadcastAddress.AddressIn
264 # define ifr_mask iiNetmask.AddressIn
265 # define zz_family sin_family
267 # define S_IFREG _S_IFREG
269 # define isascii __isascii
270 # define isatty _isatty
271 # define mktemp _mktemp
272 # define unlink _unlink
273 # define fileno _fileno
274 # define write _write
275 # define vsnprintf _vsnprintf
276 # define snprintf _snprintf
278 # define close _close
281 # include <process.h>
282 #define getpid _getpid
284 * Defining registers are not a good idea on Windows
285 * This gets rid of the usage
290 typedef char *caddr_t;
291 # define vsnprintf _vsnprintf
292 #endif /* SYS_WINNT */
294 int ntp_set_tod P((struct timeval *tvp, void *tzp));
296 #if defined (SYS_CYGWIN32)
298 #define __int64 long long
301 /*casey Tue May 27 15:45:25 SAT 1997*/
304 /* casey's new defines */
305 #define NO_MAIN_ALLOWED 1
309 /* in vxWorks we use FIONBIO, but the others are defined for old systems, so
310 * all hell breaks loose if we leave them defined we define USE_FIONBIO to
311 * undefine O_NONBLOCK FNDELAY O_NDELAY where necessary.
313 #define USE_FIONBIO 1
314 /* end my new defines */
316 #define TIMEOFDAY 0x0 /* system wide realtime clock */
317 #define HAVE_GETCLOCK 1 /* configure does not set this ... */
318 #define HAVE_NO_NICE 1 /* configure does not set this ... */
319 #define HAVE_RANDOM 1 /* configure does not set this ... */
320 #define HAVE_SRANDOM 1 /* configure does not set this ... */
324 /* vxWorks specific additions to take care of its
325 * unix (non)complicance
333 extern int sysClkRateGet P(());
336 * Bob Herlien's excellent time code find it at:
337 * ftp://ftp.atd.ucar.edu/pub/vxworks/vx/usrTime.shar
338 * I would recommend this instead of clock_[g|s]ettime() plus you get
339 * adjtime() too ... casey
342 extern int gettimeofday P(( struct timeval *tp, struct timezone *tzp ));
343 extern int settimeofday P((struct timeval *, struct timezone *));
344 extern int adjtime P(( struct timeval *delta, struct timeval *olddelta ));
348 extern void sleep P((int seconds));
349 extern void alarm P((int seconds));
353 /* this is really this */
354 #define getpid taskIdSelf
355 #define getclock clock_gettime
357 #define _getch getchar
359 #define srandom srand
361 /* define this away for vxWorks */
363 /* use local defines for these */
367 #endif /* SYS_VXWORKS */
370 /* These structures are needed for gethostbyname() etc... */
371 /* structures used by netdb.h */
373 char *h_name; /* official name of host */
374 char **h_aliases; /* alias list */
375 int h_addrtype; /* host address type */
376 int h_length; /* length of address */
377 char **h_addr_list; /* list of addresses from name server */
378 #define h_addr h_addr_list[0] /* address, for backward compatibility */
382 char *s_name; /* official service name */
383 char **s_aliases; /* alias list */
384 int s_port; /* port # */
385 char *s_proto; /* protocol to use */
391 struct hostent *gethostbyname P((char * netnum));
392 struct hostent *gethostbyaddr P((char * netnum, int size, int addr_type));
393 /* type is the protocol */
394 struct servent *getservbyname P((char *name, char *type));
395 #endif /* NO_NETDB */
397 #ifdef NO_MAIN_ALLOWED
398 /* we have no main routines so lets make a plan */
399 #define CALL(callname, progname, callmain) \
400 extern int callmain (int,char**); \
401 void callname (a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \
416 char *argv[] = {progname,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; \
432 for (i=0; i<11;i++) \
435 argv[argc++] = x[i]; \
437 callmain(argc,argv); \
439 #endif /* NO_MAIN_ALLOWED */
440 /*casey Tue May 27 15:45:25 SAT 1997*/
443 * Here's where autoconfig starts to take over
445 #ifdef HAVE_SYS_STROPTS_H
446 # ifdef HAVE_SYS_STREAM_H
452 # if defined(NTP_POSIX_SOURCE)
453 # define RETSIGTYPE void
455 # define RETSIGTYPE int
459 #ifdef NTP_SYSCALLS_STD
460 # ifndef NTP_SYSCALL_GET
461 # define NTP_SYSCALL_GET 235
463 # ifndef NTP_SYSCALL_ADJ
464 # define NTP_SYSCALL_ADJ 236
466 #endif /* NTP_SYSCALLS_STD */
469 # include <sys/types.h>
470 # include <netinet/in.h>
474 /* missing functions that are easily renamed */
476 # define _getch getchar
478 /* special functions that require MPE-specific wrappers */
480 # define bind __ntp_mpe_bind
481 # define fcntl __ntp_mpe_fcntl
483 /* standard macros missing from MPE include files */
485 # define IN_CLASSD(i) ((((long)(i))&0xf0000000)==0xe0000000)
486 # define IN_MULTICAST IN_CLASSD
487 # define ITIMER_REAL 0
488 # define MAXHOSTNAMELEN 64
490 /* standard structures missing from MPE include files */
493 struct timeval it_interval; /* timer interval */
494 struct timeval it_value; /* current value */
497 /* various declarations to make gcc stop complaining */
499 extern int __filbuf(FILE *);
500 extern int __flsbuf(int, FILE *);
501 extern int gethostname(char *, int);
502 extern unsigned long inet_addr(char *);
503 extern char *strdup(const char *);
505 /* miscellaneous NTP macros */
507 # define HAVE_NO_NICE
511 # define HAVE_NO_NICE
513 # ifdef HAVE_SETPRIORITY
514 # define HAVE_BSD_NICE
517 # define HAVE_ATT_NICE
522 #if !defined(HAVE_ATT_NICE) \
523 && !defined(HAVE_BSD_NICE) \
524 && !defined(HAVE_NO_NICE) \
525 && !defined(SYS_WINNT)
526 #include "ERROR: You must define one of the HAVE_xx_NICE defines!"
530 * use only one tty model - no use in initialising
531 * a tty in three ways
532 * HAVE_TERMIOS is preferred over HAVE_SYSV_TTYS over HAVE_BSD_TTYS
535 #ifdef HAVE_TERMIOS_H
536 # define HAVE_TERMIOS
538 # ifdef HAVE_TERMIO_H
539 # define HAVE_SYSV_TTYS
542 # define HAVE_BSD_TTYS
548 # undef HAVE_BSD_TTYS
549 # undef HAVE_SYSV_TTYS
553 extern time_t timegm P((struct tm *));
556 #ifdef HAVE_SYSV_TTYS
557 # undef HAVE_BSD_TTYS
560 #if !defined(SYS_WINNT) && !defined(VMS) && !defined(SYS_VXWORKS)
561 # if !defined(HAVE_SYSV_TTYS) \
562 && !defined(HAVE_BSD_TTYS) \
563 && !defined(HAVE_TERMIOS)
564 #include "ERROR: no tty type defined!"
566 #endif /* SYS_WINNT || VMS || SYS_VXWORKS*/
568 #ifdef WORDS_BIGENDIAN
569 # define XNTP_BIG_ENDIAN 1
571 # define XNTP_LITTLE_ENDIAN 1
576 * This used to be resolved by calling ntohl() and htonl() to swap things
577 * around, but this turned out to be quite costly on Vaxes where those
578 * things are actual functions. The code now straightens out byte
579 * order troubles on its own, with no performance penalty for little
580 * end first machines, but at great expense to cleanliness.
582 #if !defined(XNTP_BIG_ENDIAN) && !defined(XNTP_LITTLE_ENDIAN)
584 * Pick one or the other.
586 BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
589 #if defined(XNTP_BIG_ENDIAN) && defined(XNTP_LITTLE_ENDIAN)
591 * Pick one or the other.
593 BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
596 #endif /* __ntp_machine */