xref: /freebsd/contrib/ntp/include/ntp_machine.h (revision d37ea99837e6ad50837fd9fe1771ddf1c3ba6002)
1 /*
2  * Collect all machine dependent idiosyncrasies in one place.
3  */
4 
5 #ifndef __ntp_machine
6 #define __ntp_machine
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 
43 INFO 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 
50 HOW 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 
57   STREAMS_TLI - use ioctl(I_STR) to implement ioctl(SIOCGIFCONF)
58 
59 WHAT DOES IOCTL(SIOCGIFCONF) RETURN IN THE BUFFER
60 
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.
66 
67   SIZE_RETURNED_IN_BUFFER - size integer is in the buffer
68 
69 WILL IOCTL(SIOCGIFCONF) WORK ON A SOCKET
70 
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.
74 
75   USE_STREAMS_DEVICE_FOR_IF_CONFIG - use the /dev/ip device for configuration
76 
77 MISC
78 
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.
84   UDP_WILDCARD_DELIVERY
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 ?
89 */
90 
91 /*
92  * Set up for prototyping (duplicated from ntp_types.h)
93  */
94 #ifndef P
95 #if defined(__STDC__) || defined(HAVE_PROTOTYPES)
96 #define P(x)    x
97 #else /* not __STDC__ and not HAVE_PROTOTYPES */
98 #define P(x)    ()
99 #endif /* not __STDC__ and not HAVE_PROTOTYPES */
100 #endif /* P */
101 
102 #if 0
103 
104 /*
105  * IRIX 4.X and IRIX 5.x
106  */
107 #if defined(SYS_IRIX4)||defined(SYS_IRIX5)
108 # define ADJTIME_IS_ACCURATE
109 # define LOCK_PROCESS
110 #endif
111 
112 /*
113  * Ultrix
114  * Note: posix version has NTP_POSIX_SOURCE and HAVE_SIGNALED_IO
115  */
116 #if defined(SYS_ULTRIX)
117 # define S_CHAR_DEFINED
118 # define NTP_SYSCALLS_STD
119 # define HAVE_MODEM_CONTROL
120 #endif
121 
122 /*
123  * AUX
124  */
125 #if defined(SYS_AUX2) || defined(SYS_AUX3)
126 # define NO_SIGNED_CHAR_DECL
127 # define LOCK_PROCESS
128 # define NTP_POSIX_SOURCE
129 /*
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...
135  */
136 # define LOG_NTP LOG_LOCAL1
137 #endif
138 
139 /*
140  * HPUX
141  */
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
147 #endif
148 
149 /*
150  * BSD/OS 2.0 and above
151  */
152 #if defined(SYS_BSDI)
153 # define USE_FSETOWNCTTY	/* this funny system demands a CTTY for FSETOWN */
154 #endif
155 
156 /*
157  * FreeBSD 2.0 and above
158  */
159 #ifdef SYS_FREEBSD
160 # define KERNEL_PLL
161 #endif
162 
163 /*
164  * Linux
165  */
166 #if defined(SYS_LINUX)
167 # define ntp_adjtime __adjtimex
168 #endif
169 
170 /*
171  * PTX
172  */
173 #if defined(SYS_PTX)
174 # define LOCK_PROCESS
175 struct timezone { int __0; };	/* unused placebo */
176 /*
177  * no comment !@!
178  */
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;
184 # endif
185 #endif
186 
187 /*
188  * UNIX V.4 on and NCR 3000
189  */
190 #if defined(SYS_SVR4)
191 # define STREAM
192 # define LOCK_PROCESS
193 # define SIZE_RETURNED_IN_BUFFER
194 #endif
195 
196 /*
197  * (Univel/Novell) Unixware1 SVR4 on intel x86 processor
198  */
199 #if defined(SYS_UNIXWARE1)
200 /* #define _POSIX_SOURCE */
201 # define STREAM
202 # define STREAMS
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>
209 #endif
210 
211 /*
212  * DomainOS
213  */
214 #if defined(SYS_DOMAINOS)
215 # define NTP_SYSCALLS_STD
216 /* older versions of domain/os don't have class D */
217 # ifndef IN_CLASSD
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)
223 # endif
224 #endif
225 
226 /*
227  * Fujitsu UXP/V
228  */
229 #if defined(SYS_UXPV)
230 # define LOCK_PROCESS
231 # define SIZE_RETURNED_IN_BUFFER
232 #endif
233 
234 
235 #endif /* 0 */
236 
237 /*
238  * Windows NT
239  */
240 #if defined(SYS_WINNT)
241 # if !defined(HAVE_CONFIG_H)  || !defined(__config)
242     error "NT requires config.h to be included"
243 # endif /* HAVE_CONFIG_H) */
244 
245 # define ifreq _INTERFACE_INFO
246 # define ifr_flags iiFlags
247 # define ifr_addr iiAddress.AddressIn
248 # define ifr_broadaddr iiBroadcastAddress.AddressIn
249 # define ifr_mask iiNetmask.AddressIn
250 
251 # define isascii __isascii
252 # define isatty _isatty
253 # define mktemp _mktemp
254 # if 0
255 #  define getpid GetCurrentProcessId
256 # endif
257 # include <windows.h>
258 # include <ws2tcpip.h>
259 # undef interface
260  typedef char *caddr_t;
261 #endif /* SYS_WINNT */
262 
263 int ntp_set_tod P((struct timeval *tvp, void *tzp));
264 
265 #if defined (SYS_CYGWIN32)
266 #include <windows.h>
267 #define __int64 long long
268 #endif
269 
270 /*casey Tue May 27 15:45:25 SAT 1997*/
271 #ifdef SYS_VXWORKS
272 
273 /* casey's new defines */
274 #define NO_MAIN_ALLOWED 	1
275 #define NO_NETDB			1
276 #define NO_RENAME			1
277 
278 /* in vxWorks we use FIONBIO, but the others are defined for old systems, so
279  * all hell breaks loose if we leave them defined we define USE_FIONBIO to
280  * undefine O_NONBLOCK FNDELAY O_NDELAY where necessary.
281  */
282 #define USE_FIONBIO 		1
283 /* end my new defines */
284 
285 #define TIMEOFDAY		0x0 	/* system wide realtime clock */
286 #define HAVE_GETCLOCK		1	/* configure does not set this ... */
287 #define HAVE_NO_NICE		1	/* configure does not set this ... */
288 #define HAVE_RANDOM		1	/* configure does not set this ...  */
289 #define HAVE_SRANDOM		1	/* configure does not set this ... */
290 
291 #define NODETACH		1
292 
293 /* vxWorks specific additions to take care of its
294  * unix (non)complicance
295  */
296 
297 #include "vxWorks.h"
298 #include "ioLib.h"
299 #include "taskLib.h"
300 #include "time.h"
301 
302 extern int sysClkRateGet P(());
303 
304 /* usrtime.h
305  * Bob Herlien's excellent time code find it at:
306  * ftp://ftp.atd.ucar.edu/pub/vxworks/vx/usrTime.shar
307  * I would recommend this instead of clock_[g|s]ettime() plus you get
308  * adjtime() too ... casey
309  */
310 /*
311 extern int	  gettimeofday P(( struct timeval *tp, struct timezone *tzp ));
312 extern int	  settimeofday P((struct timeval *, struct timezone *));
313 extern int	  adjtime P(( struct timeval *delta, struct timeval *olddelta ));
314  */
315 
316 /* in  machines.c */
317 extern void sleep P((int seconds));
318 extern void alarm P((int seconds));
319 /* machines.c */
320 
321 
322 /*		this is really this 	*/
323 #define getpid		taskIdSelf
324 #define getclock	clock_gettime
325 #define fcntl		ioctl
326 #define _getch		getchar
327 #define random 		rand
328 #define srandom		srand
329 
330 /* define this away for vxWorks */
331 #define openlog(x,y)
332 /* use local defines for these */
333 #undef min
334 #undef max
335 
336 #endif /* SYS_VXWORKS */
337 
338 #ifdef NO_NETDB
339 /* These structures are needed for gethostbyname() etc... */
340 /* structures used by netdb.h */
341 struct	hostent {
342 	char	*h_name;				/* official name of host */
343 	char	**h_aliases;			/* alias list */
344 	int h_addrtype; 				/* host address type */
345 	int h_length;					/* length of address */
346 	char	**h_addr_list;			/* list of addresses from name server */
347 #define 	h_addr h_addr_list[0]	/* address, for backward compatibility */
348 };
349 
350 struct	servent {
351 	char	*s_name;				/* official service name */
352 	char	**s_aliases;			/* alias list */
353 	int s_port; 					/* port # */
354 	char	*s_proto;				/* protocol to use */
355 };
356 extern int h_errno;
357 
358 #define TRY_AGAIN	2
359 
360 struct hostent *gethostbyname P((char * netnum));
361 struct hostent *gethostbyaddr P((char * netnum, int size, int addr_type));
362 /* type is the protocol */
363 struct servent *getservbyname P((char *name, char *type));
364 #endif	/* NO_NETDB */
365 
366 #ifdef NO_MAIN_ALLOWED
367 /* we have no main routines so lets make a plan */
368 #define CALL(callname, progname, callmain) \
369 	extern int callmain (int,char**); \
370 	void callname (a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \
371 		char *a0;  \
372 		char *a1;  \
373 		char *a2;  \
374 		char *a3;  \
375 		char *a4;  \
376 		char *a5;  \
377 		char *a6;  \
378 		char *a7;  \
379 		char *a8;  \
380 		char *a9;  \
381 		char *a10; \
382 	{ \
383 	  char *x[11]; \
384 	  int argc; \
385 	  char *argv[] = {progname,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; \
386 	  int i; \
387 	  for (i=0;i<11;i++) \
388 	   x[i] = NULL; \
389 	  x[0] = a0; \
390 	  x[1] = a1; \
391 	  x[2] = a2; \
392 	  x[3] = a3; \
393 	  x[4] = a4; \
394 	  x[5] = a5; \
395 	  x[6] = a6; \
396 	  x[7] = a7; \
397 	  x[8] = a8; \
398 	  x[9] = a9; \
399 	  x[10] = a10; \
400 	  argc=1; \
401 	  for (i=0; i<11;i++) \
402 		if (x[i]) \
403 		{ \
404 		  argv[argc++] = x[i];	\
405 		} \
406 	 callmain(argc,argv);  \
407 	}
408 #endif /* NO_MAIN_ALLOWED */
409 /*casey Tue May 27 15:45:25 SAT 1997*/
410 
411 /*
412  * Here's where autoconfig starts to take over
413  */
414 #ifdef HAVE_SYS_STROPTS_H
415 # ifdef HAVE_SYS_STREAM_H
416 #  define STREAM
417 # endif
418 #endif
419 
420 #ifndef RETSIGTYPE
421 # if defined(NTP_POSIX_SOURCE)
422 #  define	RETSIGTYPE	void
423 # else
424 #  define	RETSIGTYPE	int
425 # endif
426 #endif
427 
428 #ifdef	NTP_SYSCALLS_STD
429 # ifndef	NTP_SYSCALL_GET
430 #  define	NTP_SYSCALL_GET 235
431 # endif
432 # ifndef	NTP_SYSCALL_ADJ
433 #  define	NTP_SYSCALL_ADJ 236
434 # endif
435 #endif	/* NTP_SYSCALLS_STD */
436 
437 #ifdef MPE
438 # include <sys/types.h>
439 # include <netinet/in.h>
440 # include <stdio.h>
441 # include <time.h>
442 
443 /* missing functions that are easily renamed */
444 
445 # define _getch getchar
446 
447 /* special functions that require MPE-specific wrappers */
448 
449 # define bind	__ntp_mpe_bind
450 # define fcntl	__ntp_mpe_fcntl
451 
452 /* standard macros missing from MPE include files */
453 
454 # define IN_CLASSD(i)	((((long)(i))&0xf0000000)==0xe0000000)
455 # define IN_MULTICAST IN_CLASSD
456 # define ITIMER_REAL 0
457 # define MAXHOSTNAMELEN 64
458 
459 /* standard structures missing from MPE include files */
460 
461 struct itimerval {
462         struct timeval it_interval;    /* timer interval */
463         struct timeval it_value;       /* current value */
464 };
465 
466 /* various declarations to make gcc stop complaining */
467 
468 extern int __filbuf(FILE *);
469 extern int __flsbuf(int, FILE *);
470 extern int gethostname(char *, int);
471 extern unsigned long inet_addr(char *);
472 extern char *strdup(const char *);
473 
474 /* miscellaneous NTP macros */
475 
476 # define HAVE_NO_NICE
477 #endif /* MPE */
478 
479 #ifdef HAVE_RTPRIO
480 # define HAVE_NO_NICE
481 #else
482 # ifdef HAVE_SETPRIORITY
483 #  define HAVE_BSD_NICE
484 # else
485 #  ifdef HAVE_NICE
486 #	define HAVE_ATT_NICE
487 #  endif
488 # endif
489 #endif
490 
491 #if !defined(HAVE_ATT_NICE) \
492 	&& !defined(HAVE_BSD_NICE) \
493 	&& !defined(HAVE_NO_NICE) \
494 	&& !defined(SYS_WINNT)
495 #include "ERROR: You must define one of the HAVE_xx_NICE defines!"
496 #endif
497 
498 /*
499  * use only one tty model - no use in initialising
500  * a tty in three ways
501  * HAVE_TERMIOS is preferred over HAVE_SYSV_TTYS over HAVE_BSD_TTYS
502  */
503 
504 #ifdef HAVE_TERMIOS_H
505 # define HAVE_TERMIOS
506 #else
507 # ifdef HAVE_TERMIO_H
508 #  define HAVE_SYSV_TTYS
509 # else
510 #  ifdef HAVE_SGTTY_H
511 #	define HAVE_BSD_TTYS
512 #  endif
513 # endif
514 #endif
515 
516 #ifdef HAVE_TERMIOS
517 # undef HAVE_BSD_TTYS
518 # undef HAVE_SYSV_TTYS
519 #endif
520 
521 #ifdef HAVE_SYSV_TTYS
522 # undef HAVE_BSD_TTYS
523 #endif
524 
525 #if !defined(SYS_WINNT) && !defined(VMS) && !defined(SYS_VXWORKS)
526 # if	!defined(HAVE_SYSV_TTYS) \
527 	&& !defined(HAVE_BSD_TTYS) \
528 	&& !defined(HAVE_TERMIOS)
529 #include "ERROR: no tty type defined!"
530 # endif
531 #endif /* SYS_WINNT || VMS	|| SYS_VXWORKS*/
532 
533 #ifdef	WORDS_BIGENDIAN
534 # define	XNTP_BIG_ENDIAN 1
535 #else
536 # define	XNTP_LITTLE_ENDIAN	1
537 #endif
538 
539 /*
540  * Byte order woes.  The DES code is sensitive to byte order.  This
541  * used to be resolved by calling ntohl() and htonl() to swap things
542  * around, but this turned out to be quite costly on Vaxes where those
543  * things are actual functions.  The code now straightens out byte
544  * order troubles on its own, with no performance penalty for little
545  * end first machines, but at great expense to cleanliness.
546  */
547 #if !defined(XNTP_BIG_ENDIAN) && !defined(XNTP_LITTLE_ENDIAN)
548 	/*
549 	 * Pick one or the other.
550 	 */
551 	BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
552 #endif
553 
554 #if defined(XNTP_BIG_ENDIAN) && defined(XNTP_LITTLE_ENDIAN)
555 	/*
556 	 * Pick one or the other.
557 	 */
558 	BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
559 #endif
560 
561 #endif /* __ntp_machine */
562