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