/contrib/ntp/include/ntp_machine.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 590 lines · 330 code · 75 blank · 185 comment · 19 complexity · 505f92b9df38643232a1405930b4320b MD5 · raw file

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