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