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