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