xref: /netbsd-src/external/bsd/ntp/dist/include/ntp_machine.h (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: ntp_machine.h,v 1.1.1.1 2009/12/13 16:54:51 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 closesocket(fd)	close(fd)
236 #endif
237 
238 int ntp_set_tod (struct timeval *tvp, void *tzp);
239 
240 #if defined (SYS_CYGWIN32)
241 #include <windows.h>
242 #define __int64 long long
243 #endif
244 
245 /*casey Tue May 27 15:45:25 SAT 1997*/
246 #ifdef SYS_VXWORKS
247 
248 /* casey's new defines */
249 #define NO_MAIN_ALLOWED 	1
250 #define NO_NETDB			1
251 #define NO_RENAME			1
252 
253 /* in vxWorks we use FIONBIO, but the others are defined for old systems, so
254  * all hell breaks loose if we leave them defined we define USE_FIONBIO to
255  * undefine O_NONBLOCK FNDELAY O_NDELAY where necessary.
256  */
257 #define USE_FIONBIO 		1
258 /* end my new defines */
259 
260 #define TIMEOFDAY		0x0 	/* system wide realtime clock */
261 #define HAVE_GETCLOCK		1	/* configure does not set this ... */
262 #define HAVE_NO_NICE		1	/* configure does not set this ... */
263 #define HAVE_RANDOM		1	/* configure does not set this ...  */
264 #define HAVE_SRANDOM		1	/* configure does not set this ... */
265 
266 #define NODETACH		1
267 
268 /* vxWorks specific additions to take care of its
269  * unix (non)complicance
270  */
271 
272 #include "vxWorks.h"
273 #include "ioLib.h"
274 #include "taskLib.h"
275 #include "time.h"
276 
277 extern int sysClkRateGet ();
278 
279 /* usrtime.h
280  * Bob Herlien's excellent time code find it at:
281  * ftp://ftp.atd.ucar.edu/pub/vxworks/vx/usrTime.shar
282  * I would recommend this instead of clock_[g|s]ettime() plus you get
283  * adjtime() too ... casey
284  */
285 /*
286 extern int	  gettimeofday ( struct timeval *tp, struct timezone *tzp );
287 extern int	  settimeofday (struct timeval *, struct timezone *);
288 extern int	  adjtime ( struct timeval *delta, struct timeval *olddelta );
289  */
290 
291 /* in  machines.c */
292 extern void sleep (int seconds);
293 extern void alarm (int seconds);
294 /* machines.c */
295 
296 
297 /*		this is really this 	*/
298 #define getpid		taskIdSelf
299 #define getclock	clock_gettime
300 #define fcntl		ioctl
301 #define _getch		getchar
302 
303 /* define this away for vxWorks */
304 #define openlog(x,y)
305 /* use local defines for these */
306 #undef min
307 #undef max
308 
309 #endif /* SYS_VXWORKS */
310 
311 #ifdef NO_NETDB
312 /* These structures are needed for gethostbyname() etc... */
313 /* structures used by netdb.h */
314 struct	hostent {
315 	char	*h_name;				/* official name of host */
316 	char	**h_aliases;			/* alias list */
317 	int h_addrtype; 				/* host address type */
318 	int h_length;					/* length of address */
319 	char	**h_addr_list;			/* list of addresses from name server */
320 #define 	h_addr h_addr_list[0]	/* address, for backward compatibility */
321 };
322 
323 struct	servent {
324 	char	*s_name;				/* official service name */
325 	char	**s_aliases;			/* alias list */
326 	int s_port; 					/* port # */
327 	char	*s_proto;				/* protocol to use */
328 };
329 extern int h_errno;
330 
331 #define TRY_AGAIN	2
332 
333 struct hostent *gethostbyname (char * netnum);
334 struct hostent *gethostbyaddr (char * netnum, int size, int addr_type);
335 /* type is the protocol */
336 struct servent *getservbyname (char *name, char *type);
337 #endif	/* NO_NETDB */
338 
339 #ifdef NO_MAIN_ALLOWED
340 /* we have no main routines so lets make a plan */
341 #define CALL(callname, progname, callmain) \
342 	extern int callmain (int,char**); \
343 	void callname (a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \
344 		char *a0;  \
345 		char *a1;  \
346 		char *a2;  \
347 		char *a3;  \
348 		char *a4;  \
349 		char *a5;  \
350 		char *a6;  \
351 		char *a7;  \
352 		char *a8;  \
353 		char *a9;  \
354 		char *a10; \
355 	{ \
356 	  char *x[11]; \
357 	  int argc; \
358 	  char *argv[] = {progname,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; \
359 	  int i; \
360 	  for (i=0;i<11;i++) \
361 	   x[i] = NULL; \
362 	  x[0] = a0; \
363 	  x[1] = a1; \
364 	  x[2] = a2; \
365 	  x[3] = a3; \
366 	  x[4] = a4; \
367 	  x[5] = a5; \
368 	  x[6] = a6; \
369 	  x[7] = a7; \
370 	  x[8] = a8; \
371 	  x[9] = a9; \
372 	  x[10] = a10; \
373 	  argc=1; \
374 	  for (i=0; i<11;i++) \
375 		if (x[i]) \
376 		{ \
377 		  argv[argc++] = x[i];	\
378 		} \
379 	 callmain(argc,argv);  \
380 	}
381 #endif /* NO_MAIN_ALLOWED */
382 /*casey Tue May 27 15:45:25 SAT 1997*/
383 
384 /*
385  * Here's where autoconfig starts to take over
386  */
387 #ifdef HAVE_SYS_STROPTS_H
388 # ifdef HAVE_SYS_STREAM_H
389 #  define STREAM
390 # endif
391 #endif
392 
393 #ifndef RETSIGTYPE
394 # if defined(NTP_POSIX_SOURCE)
395 #  define	RETSIGTYPE	void
396 # else
397 #  define	RETSIGTYPE	int
398 # endif
399 #endif
400 
401 #ifdef	NTP_SYSCALLS_STD
402 # ifndef	NTP_SYSCALL_GET
403 #  define	NTP_SYSCALL_GET 235
404 # endif
405 # ifndef	NTP_SYSCALL_ADJ
406 #  define	NTP_SYSCALL_ADJ 236
407 # endif
408 #endif	/* NTP_SYSCALLS_STD */
409 
410 #ifdef MPE
411 # include <sys/types.h>
412 # include <netinet/in.h>
413 # include <stdio.h>
414 # include <time.h>
415 
416 /* missing functions that are easily renamed */
417 
418 # define _getch getchar
419 
420 /* special functions that require MPE-specific wrappers */
421 
422 # define bind	__ntp_mpe_bind
423 # define fcntl	__ntp_mpe_fcntl
424 
425 /* standard macros missing from MPE include files */
426 
427 # define IN_CLASSD(i)	((((long)(i))&0xf0000000)==0xe0000000)
428 # define IN_MULTICAST IN_CLASSD
429 # define ITIMER_REAL 0
430 # define MAXHOSTNAMELEN 64
431 
432 /* standard structures missing from MPE include files */
433 
434 struct itimerval {
435         struct timeval it_interval;    /* timer interval */
436         struct timeval it_value;       /* current value */
437 };
438 
439 /* various declarations to make gcc stop complaining */
440 
441 extern int __filbuf(FILE *);
442 extern int __flsbuf(int, FILE *);
443 extern int gethostname(char *, int);
444 extern unsigned long inet_addr(char *);
445 extern char *strdup(const char *);
446 
447 /* miscellaneous NTP macros */
448 
449 # define HAVE_NO_NICE
450 #endif /* MPE */
451 
452 #ifdef HAVE_RTPRIO
453 # define HAVE_NO_NICE
454 #else
455 # ifdef HAVE_SETPRIORITY
456 #  define HAVE_BSD_NICE
457 # else
458 #  ifdef HAVE_NICE
459 #	define HAVE_ATT_NICE
460 #  endif
461 # endif
462 #endif
463 
464 #if !defined(HAVE_ATT_NICE) \
465 	&& !defined(HAVE_BSD_NICE) \
466 	&& !defined(HAVE_NO_NICE)
467 #include "ERROR: You must define one of the HAVE_xx_NICE defines!"
468 #endif
469 
470 /*
471  * use only one tty model - no use in initialising
472  * a tty in three ways
473  * HAVE_TERMIOS is preferred over HAVE_SYSV_TTYS over HAVE_BSD_TTYS
474  */
475 
476 #ifdef HAVE_TERMIOS_H
477 # define HAVE_TERMIOS
478 #else
479 # ifdef HAVE_TERMIO_H
480 #  define HAVE_SYSV_TTYS
481 # else
482 #  ifdef HAVE_SGTTY_H
483 #	define HAVE_BSD_TTYS
484 #  endif
485 # endif
486 #endif
487 
488 #ifdef HAVE_TERMIOS
489 # undef HAVE_BSD_TTYS
490 # undef HAVE_SYSV_TTYS
491 #endif
492 
493 #ifndef HAVE_TIMEGM
494 extern time_t	timegm		(struct tm *);
495 #endif
496 
497 #ifdef HAVE_SYSV_TTYS
498 # undef HAVE_BSD_TTYS
499 #endif
500 
501 #if !defined(SYS_WINNT) && !defined(VMS) && !defined(SYS_VXWORKS)
502 # if	!defined(HAVE_SYSV_TTYS) \
503 	&& !defined(HAVE_BSD_TTYS) \
504 	&& !defined(HAVE_TERMIOS)
505 #include "ERROR: no tty type defined!"
506 # endif
507 #endif /* SYS_WINNT || VMS	|| SYS_VXWORKS*/
508 
509 #ifdef	WORDS_BIGENDIAN
510 # define	XNTP_BIG_ENDIAN 1
511 #else
512 # define	XNTP_LITTLE_ENDIAN	1
513 #endif
514 
515 /*
516  * Byte order woes.
517  * This used to be resolved by calling ntohl() and htonl() to swap things
518  * around, but this turned out to be quite costly on Vaxes where those
519  * things are actual functions.  The code now straightens out byte
520  * order troubles on its own, with no performance penalty for little
521  * end first machines, but at great expense to cleanliness.
522  */
523 #if !defined(XNTP_BIG_ENDIAN) && !defined(XNTP_LITTLE_ENDIAN)
524 	/*
525 	 * Pick one or the other.
526 	 */
527 	BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
528 #endif
529 
530 #if defined(XNTP_BIG_ENDIAN) && defined(XNTP_LITTLE_ENDIAN)
531 	/*
532 	 * Pick one or the other.
533 	 */
534 	BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
535 #endif
536 
537 #endif	/* NTP_MACHINE_H */
538