1 /* $NetBSD: ntp_machine.h,v 1.3 2006/06/11 19:34:09 kardel Exp $ */
4 * Collect all machine dependent idiosyncrasies in one place.
14 #ifdef TIME_WITH_SYS_TIME
15 # include <sys/time.h>
18 # ifdef HAVE_SYS_TIME_H
19 # include <sys/time.h>
25 #include "ntp_proto.h"
31 The first half of this file is obsolete, and is only there to help
32 reconcile "what went before" with "current behavior".
34 The per-system SYS_* #defins ARE NO LONGER USED, with the temporary
35 exception of SYS_WINNT.
37 If you find a hunk of code that is bracketed by a SYS_* macro and you
38 *know* that it is still needed, please let us know. In many cases the
39 code fragment is now handled somewhere else by autoconf choices.
45 INFO ON NEW KERNEL PLL SYS CALLS
47 NTP_SYSCALLS_STD - use the "normal" ones
48 NTP_SYSCALL_GET - SYS_ntp_gettime id
49 NTP_SYSCALL_ADJ - SYS_ntp_adjtime id
50 NTP_SYSCALLS_LIBC - ntp_adjtime() and ntp_gettime() are in libc.
52 HOW TO GET IP INTERFACE INFORMATION
54 Some UNIX V.4 machines implement a sockets library on top of
55 streams. For these systems, you must use send the SIOCGIFCONF down
56 the stream in an I_STR ioctl. This ususally also implies
57 USE_STREAMS_DEVICE FOR IF_CONFIG. Dell UNIX is a notable exception.
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.
87 * Set up for prototyping (duplicated from ntp_types.h)
90 #if defined(__STDC__) || defined(HAVE_PROTOTYPES)
92 #else /* not __STDC__ and not HAVE_PROTOTYPES */
94 #endif /* not __STDC__ and not HAVE_PROTOTYPES */
97 #if !defined(HAVE_NTP_ADJTIME) && defined(HAVE___ADJTIMEX)
98 # define ntp_adjtime __adjtimex
104 * IRIX 4.X and IRIX 5.x
106 #if defined(SYS_IRIX4)||defined(SYS_IRIX5)
107 # define ADJTIME_IS_ACCURATE
108 # define LOCK_PROCESS
113 * Note: posix version has NTP_POSIX_SOURCE and HAVE_SIGNALED_IO
115 #if defined(SYS_ULTRIX)
116 # define S_CHAR_DEFINED
117 # define NTP_SYSCALLS_STD
118 # define HAVE_MODEM_CONTROL
124 #if defined(SYS_AUX2) || defined(SYS_AUX3)
125 # define NO_SIGNED_CHAR_DECL
126 # define LOCK_PROCESS
127 # define NTP_POSIX_SOURCE
129 * This requires that _POSIX_SOURCE be forced on the
130 * compiler command flag. We can't do it here since this
131 * file is included _after_ the system header files and we
132 * need to let _them_ know we're POSIX. We do this in
133 * compilers/aux3.gcc...
135 # define LOG_NTP LOG_LOCAL1
141 #if defined(SYS_HPUX)
142 # define getdtablesize() sysconf(_SC_OPEN_MAX)
143 # define setlinebuf(f) setvbuf(f, NULL, _IOLBF, 0)
144 # define NO_SIGNED_CHAR_DECL
145 # define LOCK_PROCESS
149 * BSD/OS 2.0 and above
151 #if defined(SYS_BSDI)
152 # define USE_FSETOWNCTTY /* this funny system demands a CTTY for FSETOWN */
156 * FreeBSD 2.0 and above
165 #if defined(SYS_LINUX)
166 # define ntp_adjtime __adjtimex
173 # define LOCK_PROCESS
174 struct timezone
{ int __0
; }; /* unused placebo */
178 typedef unsigned int u_int
;
179 # ifndef _NETINET_IN_SYSTM_INCLUDED /* i am about to comment... */
180 typedef unsigned char u_char
;
181 typedef unsigned short u_short
;
182 typedef unsigned long u_long
;
187 * UNIX V.4 on and NCR 3000
189 #if defined(SYS_SVR4)
191 # define LOCK_PROCESS
192 # define SIZE_RETURNED_IN_BUFFER
196 * (Univel/Novell) Unixware1 SVR4 on intel x86 processor
198 #if defined(SYS_UNIXWARE1)
199 /* #define _POSIX_SOURCE */
202 # undef STEP_SLEW /* TWO step */
203 # define LOCK_PROCESS
204 # define SIZE_RETURNED_IN_BUFFER
205 # include <sys/sockio.h>
206 # include <sys/types.h>
207 # include <netinet/in_systm.h>
213 #if defined(SYS_DOMAINOS)
214 # define NTP_SYSCALLS_STD
215 /* older versions of domain/os don't have class D */
217 # define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
218 # define IN_CLASSD_NET 0xf0000000
219 # define IN_CLASSD_NSHIFT 28
220 # define IN_CLASSD_HOST 0xfffffff
221 # define IN_MULTICAST(i) IN_CLASSD(i)
228 #if defined(SYS_UXPV)
229 # define LOCK_PROCESS
230 # define SIZE_RETURNED_IN_BUFFER
237 * Define these here for non-Windows NT systems
238 * SOCKET and INVALID_SOCKET are native macros
239 * on Windows NT and since they have different
240 * requirements we use them in the code and
241 * make them macros for everyone else
245 # define INVALID_SOCKET -1
246 # define SOCKET_ERROR -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
276 # define close _close
279 # include <process.h>
280 #define getpid _getpid
282 * Defining registers are not a good idea on Windows
283 * This gets rid of the usage
288 typedef char *caddr_t
;
289 # define vsnprintf _vsnprintf
290 #endif /* SYS_WINNT */
292 int ntp_set_tod
P((struct timeval
*tvp
, void *tzp
));
294 #if defined (SYS_CYGWIN32)
296 #define __int64 long long
299 /*casey Tue May 27 15:45:25 SAT 1997*/
302 /* casey's new defines */
303 #define NO_MAIN_ALLOWED 1
307 /* in vxWorks we use FIONBIO, but the others are defined for old systems, so
308 * all hell breaks loose if we leave them defined we define USE_FIONBIO to
309 * undefine O_NONBLOCK FNDELAY O_NDELAY where necessary.
311 #define USE_FIONBIO 1
312 /* end my new defines */
314 #define TIMEOFDAY 0x0 /* system wide realtime clock */
315 #define HAVE_GETCLOCK 1 /* configure does not set this ... */
316 #define HAVE_NO_NICE 1 /* configure does not set this ... */
317 #define HAVE_RANDOM 1 /* configure does not set this ... */
318 #define HAVE_SRANDOM 1 /* configure does not set this ... */
322 /* vxWorks specific additions to take care of its
323 * unix (non)complicance
331 extern int sysClkRateGet
P(());
334 * Bob Herlien's excellent time code find it at:
335 * ftp://ftp.atd.ucar.edu/pub/vxworks/vx/usrTime.shar
336 * I would recommend this instead of clock_[g|s]ettime() plus you get
337 * adjtime() too ... casey
340 extern int gettimeofday P(( struct timeval *tp, struct timezone *tzp ));
341 extern int settimeofday P((struct timeval *, struct timezone *));
342 extern int adjtime P(( struct timeval *delta, struct timeval *olddelta ));
346 extern void sleep
P((int seconds
));
347 extern void alarm
P((int seconds
));
351 /* this is really this */
352 #define getpid taskIdSelf
353 #define getclock clock_gettime
355 #define _getch getchar
357 /* define this away for vxWorks */
359 /* use local defines for these */
363 #endif /* SYS_VXWORKS */
366 /* These structures are needed for gethostbyname() etc... */
367 /* structures used by netdb.h */
369 char *h_name
; /* official name of host */
370 char **h_aliases
; /* alias list */
371 int h_addrtype
; /* host address type */
372 int h_length
; /* length of address */
373 char **h_addr_list
; /* list of addresses from name server */
374 #define h_addr h_addr_list[0] /* address, for backward compatibility */
378 char *s_name
; /* official service name */
379 char **s_aliases
; /* alias list */
380 int s_port
; /* port # */
381 char *s_proto
; /* protocol to use */
387 struct hostent
*gethostbyname
P((char * netnum
));
388 struct hostent
*gethostbyaddr
P((char * netnum
, int size
, int addr_type
));
389 /* type is the protocol */
390 struct servent
*getservbyname
P((char *name
, char *type
));
391 #endif /* NO_NETDB */
393 #ifdef NO_MAIN_ALLOWED
394 /* we have no main routines so lets make a plan */
395 #define CALL(callname, progname, callmain) \
396 extern int callmain (int,char**); \
397 void callname (a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \
412 char *argv[] = {progname,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; \
428 for (i=0; i<11;i++) \
431 argv[argc++] = x[i]; \
433 callmain(argc,argv); \
435 #endif /* NO_MAIN_ALLOWED */
436 /*casey Tue May 27 15:45:25 SAT 1997*/
439 * Here's where autoconfig starts to take over
441 #ifdef HAVE_SYS_STROPTS_H
442 # ifdef HAVE_SYS_STREAM_H
448 # if defined(NTP_POSIX_SOURCE)
449 # define RETSIGTYPE void
451 # define RETSIGTYPE int
455 #ifdef NTP_SYSCALLS_STD
456 # ifndef NTP_SYSCALL_GET
457 # define NTP_SYSCALL_GET 235
459 # ifndef NTP_SYSCALL_ADJ
460 # define NTP_SYSCALL_ADJ 236
462 #endif /* NTP_SYSCALLS_STD */
465 # include <sys/types.h>
466 # include <netinet/in.h>
470 /* missing functions that are easily renamed */
472 # define _getch getchar
474 /* special functions that require MPE-specific wrappers */
476 # define bind __ntp_mpe_bind
477 # define fcntl __ntp_mpe_fcntl
479 /* standard macros missing from MPE include files */
481 # define IN_CLASSD(i) ((((long)(i))&0xf0000000)==0xe0000000)
482 # define IN_MULTICAST IN_CLASSD
483 # define ITIMER_REAL 0
484 # define MAXHOSTNAMELEN 64
486 /* standard structures missing from MPE include files */
489 struct timeval it_interval
; /* timer interval */
490 struct timeval it_value
; /* current value */
493 /* various declarations to make gcc stop complaining */
495 extern int __filbuf(FILE *);
496 extern int __flsbuf(int, FILE *);
497 extern int gethostname(char *, int);
498 extern unsigned long inet_addr(char *);
499 extern char *strdup(const char *);
501 /* miscellaneous NTP macros */
503 # define HAVE_NO_NICE
507 # define HAVE_NO_NICE
509 # ifdef HAVE_SETPRIORITY
510 # define HAVE_BSD_NICE
513 # define HAVE_ATT_NICE
518 #if !defined(HAVE_ATT_NICE) \
519 && !defined(HAVE_BSD_NICE) \
520 && !defined(HAVE_NO_NICE) \
521 && !defined(SYS_WINNT)
522 #include "ERROR: You must define one of the HAVE_xx_NICE defines!"
526 * use only one tty model - no use in initialising
527 * a tty in three ways
528 * HAVE_TERMIOS is preferred over HAVE_SYSV_TTYS over HAVE_BSD_TTYS
531 #ifdef HAVE_TERMIOS_H
532 # define HAVE_TERMIOS
534 # ifdef HAVE_TERMIO_H
535 # define HAVE_SYSV_TTYS
538 # define HAVE_BSD_TTYS
544 # undef HAVE_BSD_TTYS
545 # undef HAVE_SYSV_TTYS
549 extern time_t timegm
P((struct tm
*));
552 #ifdef HAVE_SYSV_TTYS
553 # undef HAVE_BSD_TTYS
556 #if !defined(SYS_WINNT) && !defined(VMS) && !defined(SYS_VXWORKS)
557 # if !defined(HAVE_SYSV_TTYS) \
558 && !defined(HAVE_BSD_TTYS) \
559 && !defined(HAVE_TERMIOS)
560 #include "ERROR: no tty type defined!"
562 #endif /* SYS_WINNT || VMS || SYS_VXWORKS*/
564 #ifdef WORDS_BIGENDIAN
565 # define XNTP_BIG_ENDIAN 1
567 # define XNTP_LITTLE_ENDIAN 1
572 * This used to be resolved by calling ntohl() and htonl() to swap things
573 * around, but this turned out to be quite costly on Vaxes where those
574 * things are actual functions. The code now straightens out byte
575 * order troubles on its own, with no performance penalty for little
576 * end first machines, but at great expense to cleanliness.
578 #if !defined(XNTP_BIG_ENDIAN) && !defined(XNTP_LITTLE_ENDIAN)
580 * Pick one or the other.
582 BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
585 #if defined(XNTP_BIG_ENDIAN) && defined(XNTP_LITTLE_ENDIAN)
587 * Pick one or the other.
589 BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
592 #endif /* __ntp_machine */