154359Sroberto/*
2290001Sglebius * ntp_machine.h
3290001Sglebius *
454359Sroberto * Collect all machine dependent idiosyncrasies in one place.
5290001Sglebius *
6290001Sglebius * The functionality formerly in this file is mostly handled by
7290001Sglebius * Autoconf these days.
854359Sroberto */
954359Sroberto
10290001Sglebius#ifndef NTP_MACHINE_H
11290001Sglebius#define NTP_MACHINE_H
1254359Sroberto
13290001Sglebius#ifdef HAVE_SYS_TIME_H
1482498Sroberto# include <sys/time.h>
1554359Sroberto#endif
16290001Sglebius#include <time.h>
1754359Sroberto
1854359Sroberto#include "ntp_proto.h"
1954359Sroberto
2054359Sroberto/*
2154359Sroberto
2254359Sroberto			 HEY!  CHECK THIS OUT!
2354359Sroberto
2454359Sroberto  The per-system SYS_* #defins ARE NO LONGER USED, with the temporary
2554359Sroberto  exception of SYS_WINNT.
2654359Sroberto
2754359Sroberto  If you find a hunk of code that is bracketed by a SYS_* macro and you
2854359Sroberto  *know* that it is still needed, please let us know.  In many cases the
2954359Sroberto  code fragment is now handled somewhere else by autoconf choices.
3054359Sroberto
3154359Sroberto*/
3254359Sroberto
3354359Sroberto/*
3454359Sroberto
3554359SrobertoHOW TO GET IP INTERFACE INFORMATION
3654359Sroberto
3754359Sroberto  Some UNIX V.4 machines implement a sockets library on top of
3854359Sroberto  streams. For these systems, you must use send the SIOCGIFCONF down
3954359Sroberto  the stream in an I_STR ioctl. This ususally also implies
4054359Sroberto  USE_STREAMS_DEVICE FOR IF_CONFIG. Dell UNIX is a notable exception.
4154359Sroberto
4254359SrobertoWHAT DOES IOCTL(SIOCGIFCONF) RETURN IN THE BUFFER
4354359Sroberto
4454359Sroberto  UNIX V.4 machines implement a sockets library on top of streams.
4554359Sroberto  When requesting the IP interface configuration with an ioctl(2) calll,
4654359Sroberto  an array of ifreq structures are placed in the provided buffer.  Some
4754359Sroberto  implementations also place the length of the buffer information in
4854359Sroberto  the first integer position of the buffer.
4954359Sroberto
5054359Sroberto  SIZE_RETURNED_IN_BUFFER - size integer is in the buffer
5154359Sroberto
5254359SrobertoWILL IOCTL(SIOCGIFCONF) WORK ON A SOCKET
5354359Sroberto
5454359Sroberto  Some UNIX V.4 machines do not appear to support ioctl() requests for the
5554359Sroberto  IP interface configuration on a socket.  They appear to require the use
5654359Sroberto  of the streams device instead.
5754359Sroberto
5854359Sroberto  USE_STREAMS_DEVICE_FOR_IF_CONFIG - use the /dev/ip device for configuration
5954359Sroberto
6054359SrobertoMISC
6154359Sroberto
6254359Sroberto  DOSYNCTODR		- Resync TODR clock  every hour.
6354359Sroberto  RETSIGTYPE		- Define signal function type.
6454359Sroberto  NO_SIGNED_CHAR_DECL - No "signed char" see include/ntp.h
6554359Sroberto  LOCK_PROCESS		- Have plock.
6654359Sroberto*/
6754359Sroberto
68290001Sglebiusint ntp_set_tod (struct timeval *tvp, void *tzp);
6954359Sroberto
7054359Sroberto/*casey Tue May 27 15:45:25 SAT 1997*/
7154359Sroberto#ifdef SYS_VXWORKS
7254359Sroberto
7354359Sroberto/* casey's new defines */
7454359Sroberto#define NO_MAIN_ALLOWED 	1
7554359Sroberto#define NO_NETDB			1
7654359Sroberto#define NO_RENAME			1
7754359Sroberto
7854359Sroberto/* in vxWorks we use FIONBIO, but the others are defined for old systems, so
7954359Sroberto * all hell breaks loose if we leave them defined we define USE_FIONBIO to
8054359Sroberto * undefine O_NONBLOCK FNDELAY O_NDELAY where necessary.
8154359Sroberto */
8254359Sroberto#define USE_FIONBIO 		1
8354359Sroberto/* end my new defines */
8454359Sroberto
8554359Sroberto#define TIMEOFDAY		0x0 	/* system wide realtime clock */
8654359Sroberto#define HAVE_GETCLOCK		1	/* configure does not set this ... */
8754359Sroberto#define HAVE_NO_NICE		1	/* configure does not set this ... */
8854359Sroberto#define HAVE_RANDOM		1	/* configure does not set this ...  */
8954359Sroberto#define HAVE_SRANDOM		1	/* configure does not set this ... */
9054359Sroberto
9154359Sroberto/* vxWorks specific additions to take care of its
9254359Sroberto * unix (non)complicance
9354359Sroberto */
9454359Sroberto
9554359Sroberto#include "vxWorks.h"
9654359Sroberto#include "ioLib.h"
9754359Sroberto#include "taskLib.h"
9854359Sroberto#include "time.h"
9954359Sroberto
100290001Sglebiusextern int sysClkRateGet ();
10154359Sroberto
10254359Sroberto/* usrtime.h
10354359Sroberto * Bob Herlien's excellent time code find it at:
10454359Sroberto * ftp://ftp.atd.ucar.edu/pub/vxworks/vx/usrTime.shar
10554359Sroberto * I would recommend this instead of clock_[g|s]ettime() plus you get
10654359Sroberto * adjtime() too ... casey
10754359Sroberto */
10854359Sroberto/*
109290001Sglebiusextern int	  gettimeofday ( struct timeval *tp, struct timezone *tzp );
110290001Sglebiusextern int	  settimeofday (struct timeval *, struct timezone *);
111290001Sglebiusextern int	  adjtime ( struct timeval *delta, struct timeval *olddelta );
11254359Sroberto */
11354359Sroberto
11454359Sroberto/* in  machines.c */
115290001Sglebiusextern void sleep (int seconds);
116290001Sglebiusextern void alarm (int seconds);
11754359Sroberto/* machines.c */
11854359Sroberto
11954359Sroberto
12054359Sroberto/*		this is really this 	*/
12154359Sroberto#define getpid		taskIdSelf
12254359Sroberto#define getclock	clock_gettime
12354359Sroberto#define fcntl		ioctl
12454359Sroberto#define _getch		getchar
12554359Sroberto
12654359Sroberto/* define this away for vxWorks */
12754359Sroberto#define openlog(x,y)
12854359Sroberto/* use local defines for these */
12954359Sroberto#undef min
13054359Sroberto#undef max
13154359Sroberto
13254359Sroberto#endif /* SYS_VXWORKS */
13354359Sroberto
13454359Sroberto#ifdef NO_NETDB
13554359Sroberto/* These structures are needed for gethostbyname() etc... */
13654359Sroberto/* structures used by netdb.h */
13754359Srobertostruct	hostent {
13854359Sroberto	char	*h_name;				/* official name of host */
13954359Sroberto	char	**h_aliases;			/* alias list */
14054359Sroberto	int h_addrtype; 				/* host address type */
14154359Sroberto	int h_length;					/* length of address */
14254359Sroberto	char	**h_addr_list;			/* list of addresses from name server */
14354359Sroberto#define 	h_addr h_addr_list[0]	/* address, for backward compatibility */
14454359Sroberto};
14554359Sroberto
14654359Srobertostruct	servent {
14754359Sroberto	char	*s_name;				/* official service name */
14854359Sroberto	char	**s_aliases;			/* alias list */
14954359Sroberto	int s_port; 					/* port # */
15054359Sroberto	char	*s_proto;				/* protocol to use */
15154359Sroberto};
15254359Srobertoextern int h_errno;
15354359Sroberto
15454359Sroberto#define TRY_AGAIN	2
15554359Sroberto
156290001Sglebiusstruct hostent *gethostbyname (char * netnum);
157290001Sglebiusstruct hostent *gethostbyaddr (char * netnum, int size, int addr_type);
15854359Sroberto/* type is the protocol */
159290001Sglebiusstruct servent *getservbyname (char *name, char *type);
16054359Sroberto#endif	/* NO_NETDB */
16154359Sroberto
16254359Sroberto#ifdef NO_MAIN_ALLOWED
16354359Sroberto/* we have no main routines so lets make a plan */
16454359Sroberto#define CALL(callname, progname, callmain) \
16554359Sroberto	extern int callmain (int,char**); \
16654359Sroberto	void callname (a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \
16754359Sroberto		char *a0;  \
16854359Sroberto		char *a1;  \
16954359Sroberto		char *a2;  \
17054359Sroberto		char *a3;  \
17154359Sroberto		char *a4;  \
17254359Sroberto		char *a5;  \
17354359Sroberto		char *a6;  \
17454359Sroberto		char *a7;  \
17554359Sroberto		char *a8;  \
17654359Sroberto		char *a9;  \
17754359Sroberto		char *a10; \
17854359Sroberto	{ \
17954359Sroberto	  char *x[11]; \
18054359Sroberto	  int argc; \
18154359Sroberto	  char *argv[] = {progname,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; \
18254359Sroberto	  int i; \
18354359Sroberto	  for (i=0;i<11;i++) \
18454359Sroberto	   x[i] = NULL; \
18554359Sroberto	  x[0] = a0; \
18654359Sroberto	  x[1] = a1; \
18754359Sroberto	  x[2] = a2; \
18854359Sroberto	  x[3] = a3; \
18954359Sroberto	  x[4] = a4; \
19054359Sroberto	  x[5] = a5; \
19154359Sroberto	  x[6] = a6; \
19254359Sroberto	  x[7] = a7; \
19354359Sroberto	  x[8] = a8; \
19454359Sroberto	  x[9] = a9; \
19554359Sroberto	  x[10] = a10; \
19654359Sroberto	  argc=1; \
19754359Sroberto	  for (i=0; i<11;i++) \
19854359Sroberto		if (x[i]) \
19954359Sroberto		{ \
20054359Sroberto		  argv[argc++] = x[i];	\
20154359Sroberto		} \
20254359Sroberto	 callmain(argc,argv);  \
20354359Sroberto	}
20454359Sroberto#endif /* NO_MAIN_ALLOWED */
20554359Sroberto/*casey Tue May 27 15:45:25 SAT 1997*/
20654359Sroberto
20754359Sroberto/*
20854359Sroberto * Here's where autoconfig starts to take over
20954359Sroberto */
21054359Sroberto#ifdef HAVE_SYS_STROPTS_H
21154359Sroberto# ifdef HAVE_SYS_STREAM_H
21254359Sroberto#  define STREAM
21354359Sroberto# endif
21454359Sroberto#endif
21554359Sroberto
21654359Sroberto#ifndef RETSIGTYPE
21754359Sroberto# if defined(NTP_POSIX_SOURCE)
21854359Sroberto#  define	RETSIGTYPE	void
21954359Sroberto# else
22054359Sroberto#  define	RETSIGTYPE	int
22154359Sroberto# endif
22254359Sroberto#endif
22354359Sroberto
22454359Sroberto#ifdef	NTP_SYSCALLS_STD
22554359Sroberto# ifndef	NTP_SYSCALL_GET
22654359Sroberto#  define	NTP_SYSCALL_GET 235
22754359Sroberto# endif
22854359Sroberto# ifndef	NTP_SYSCALL_ADJ
22954359Sroberto#  define	NTP_SYSCALL_ADJ 236
23054359Sroberto# endif
23154359Sroberto#endif	/* NTP_SYSCALLS_STD */
23254359Sroberto
233106163Sroberto#ifdef MPE
234106163Sroberto# include <sys/types.h>
235106163Sroberto# include <netinet/in.h>
236106163Sroberto# include <stdio.h>
237106163Sroberto# include <time.h>
238106163Sroberto
239106163Sroberto/* missing functions that are easily renamed */
240106163Sroberto
241106163Sroberto# define _getch getchar
242106163Sroberto
243106163Sroberto/* special functions that require MPE-specific wrappers */
244106163Sroberto
245106163Sroberto# define bind	__ntp_mpe_bind
246106163Sroberto# define fcntl	__ntp_mpe_fcntl
247106163Sroberto
248106163Sroberto/* standard macros missing from MPE include files */
249106163Sroberto
250106163Sroberto# define IN_CLASSD(i)	((((long)(i))&0xf0000000)==0xe0000000)
251106163Sroberto# define IN_MULTICAST IN_CLASSD
252106163Sroberto# define ITIMER_REAL 0
253106163Sroberto
254106163Sroberto/* standard structures missing from MPE include files */
255106163Sroberto
256106163Srobertostruct itimerval {
257106163Sroberto        struct timeval it_interval;    /* timer interval */
258106163Sroberto        struct timeval it_value;       /* current value */
259106163Sroberto};
260106163Sroberto
261106163Sroberto/* various declarations to make gcc stop complaining */
262106163Sroberto
263106163Srobertoextern int __filbuf(FILE *);
264106163Srobertoextern int __flsbuf(int, FILE *);
265106163Srobertoextern int gethostname(char *, int);
266106163Srobertoextern unsigned long inet_addr(char *);
267106163Srobertoextern char *strdup(const char *);
268106163Sroberto
269106163Sroberto/* miscellaneous NTP macros */
270106163Sroberto
271106163Sroberto# define HAVE_NO_NICE
272106163Sroberto#endif /* MPE */
273106163Sroberto
27454359Sroberto#ifdef HAVE_RTPRIO
27554359Sroberto# define HAVE_NO_NICE
27654359Sroberto#else
27754359Sroberto# ifdef HAVE_SETPRIORITY
27854359Sroberto#  define HAVE_BSD_NICE
27954359Sroberto# else
28054359Sroberto#  ifdef HAVE_NICE
28154359Sroberto#	define HAVE_ATT_NICE
28254359Sroberto#  endif
28354359Sroberto# endif
28454359Sroberto#endif
28554359Sroberto
28654359Sroberto#if !defined(HAVE_ATT_NICE) \
28754359Sroberto	&& !defined(HAVE_BSD_NICE) \
288290001Sglebius	&& !defined(HAVE_NO_NICE)
28954359Sroberto#include "ERROR: You must define one of the HAVE_xx_NICE defines!"
29054359Sroberto#endif
29154359Sroberto
292132451Sroberto#ifndef HAVE_TIMEGM
293290001Sglebiusextern time_t	timegm		(struct tm *);
294132451Sroberto#endif
295132451Sroberto
29654359Sroberto
297290001Sglebius#endif	/* NTP_MACHINE_H */
298