struct servent *getservbyname (char *name, char *type)
{
struct servent *serv1;
serv1 = (struct servent *) emalloc (sizeof(struct servent));
serv1->s_name = "ntp"; /* official service name */
serv1->s_aliases = NULL; /* alias list */
serv1->s_port = 123; /* port # */
serv1->s_proto = "udp"; /* protocol to use */
return serv1;
}
/* second
* vxworks thinks it has insomnia
* we have to sleep for number of seconds
*/
#define CLKRATE sysClkRateGet()
/* I am not sure how valid the granularity is - it is from G. Eger's port */
#define CLK_GRANULARITY 1 /* Granularity of system clock in usec */
/* Used to round down # usecs/tick */
/* On a VCOM-100, PIT gets 8 MHz clk, */
/* & it prescales by 32, thus 4 usec */
/* on mv167, granularity is 1usec anyway*/
/* To defeat rounding, set to 1 */
#define USECS_PER_SEC MILLION /* Microseconds per second */
#define TICK (((USECS_PER_SEC / CLKRATE) / CLK_GRANULARITY) * CLK_GRANULARITY)
/* emulate unix sleep
* casey
*/
void sleep(int seconds)
{
taskDelay(seconds*TICK);
}
/* emulate unix alarm
* that pauses and calls SIGALRM after the seconds are up...
* so ... taskDelay() fudged for seconds should amount to the same thing.
* casey
*/
void alarm (int seconds)
{
sleep(seconds);
}
#endif /* SYS_VXWORKS */
#ifdef SYS_PTX /* Does PTX still need this? */
/*#include <sys/types.h> */
#include <sys/procstats.h>
int
gettimeofday(
struct timeval *tvp
)
{
/*
* hi, this is Sequents sneak path to get to a clock
* this is also the most logical syscall for such a function
*/
return (get_process_stats(tvp, PS_SELF, (struct procstats *) 0,
(struct procstats *) 0));
}
#endif /* SYS_PTX */
#ifdef MPE
/* This is a substitute for bind() that if called for an AF_INET socket
port less than 1024, GETPRIVMODE() and GETUSERMODE() calls will be done. */
int __ntp_mpe_bind(int s, void *addr, int addrlen);
int __ntp_mpe_bind(int s, void *addr, int addrlen) {
int priv = 0;
int result;
if (addrlen == sizeof(struct sockaddr_in)) { /* AF_INET */
if (((struct sockaddr_in *)addr)->sin_port > 0 &&
((struct sockaddr_in *)addr)->sin_port < 1024) {
priv = 1;
GETPRIVMODE();
}
/* ((struct sockaddr_in *)addr)->sin_addr.s_addr = 0; */
result = bind(s,addr,addrlen);
if (priv == 1) GETUSERMODE();
} else /* AF_UNIX */
result = bind(s,addr,addrlen);
return result;
}
/*
* MPE stupidly requires sfcntl() to be used on sockets instead of fcntl(),
* so we define a wrapper to analyze the file descriptor and call the correct
* function.
*/
/*
* Setitimer emulation support. Note that we implement this using alarm(),
* and since alarm() only delivers one signal, we must re-enable the alarm
* by enabling our own SIGALRM setitimer_mpe_handler routine to be called
* before the real handler routine and re-enable the alarm at that time.
*
* Note that this solution assumes that sigaction(SIGALRM) is called before
* calling setitimer(). If it should ever to become necessary to support
* sigaction(SIGALRM) after calling setitimer(), it will be necessary to trap
* those sigaction() calls.
*/
#include <limits.h>
#include <signal.h>
/*
* Some global data that needs to be shared between setitimer() and
* setitimer_mpe_handler().
*/
struct {
unsigned long current_msec; /* current alarm() value in effect */
unsigned long interval_msec; /* next alarm() value from setitimer */
unsigned long value_msec; /* first alarm() value from setitimer */
struct itimerval current_itimerval; /* current itimerval in effect */
struct sigaction oldact; /* SIGALRM state saved by setitimer */
} setitimer_mpe_ctx = { 0, 0, 0 };
/*
* Undocumented, unsupported function to do alarm() in milliseconds.
*/
extern unsigned int px_alarm(unsigned long, int *);
/*
* The SIGALRM handler routine enabled by setitimer(). Re-enable the alarm or
* restore the original SIGALRM setting if no more alarms are needed. Then
* call the original SIGALRM handler (if any).
*/
static RETSIGTYPE setitimer_mpe_handler(int sig)
{
int alarm_hpe_status;
if (value_msec > 0 && interval_msec > 0) {
/*
* We'll be starting an interval timer that will be repeating, so we need to
* insert our own SIGALRM signal handler to schedule the repeats.
*/
/* Read the current SIGALRM action */
if (sigaction(SIGALRM, NULL, &setitimer_mpe_ctx.oldact) < 0) {
fprintf(stderr,"MPE setitimer old handler failed, errno=%d\n",errno);
return -1;
}
/* Initialize the new action to call our SIGALRM handler instead */
/* Undocumented, unsupported MPE functions. */
extern long long get_time(void);
extern void get_time_change_info(long long *, char *, char *);
extern long long ticks_to_micro(long long);
char pwf_since_boot, recover_pwf_time;
long long mpetime, offset_ticks, offset_usec;
GETPRIVMODE();
mpetime = get_time(); /* MPE local time usecs since Jan 1 1970 */
get_time_change_info(&offset_ticks, &pwf_since_boot, &recover_pwf_time);
offset_usec = ticks_to_micro(offset_ticks); /* UTC offset usecs */
GETUSERMODE();
mpetime = mpetime - offset_usec; /* Convert from local time to UTC */
tvp->tv_sec = mpetime / 1000000LL;
tvp->tv_usec = mpetime % 1000000LL;
return 0;
}
/*
* MPE lacks settimeofday(), so we define our own.
*/
GETPRIVMODE();
set_time_correction(0LL,0,0); /* Cancel previous time correction, if any */
get_time_change_info(&offset_ticks, &pwf_since_boot, &recover_pwf_time);
offset_usec = ticks_to_micro(offset_ticks); /* UTC offset microseconds */
mpetime = mpetime + offset_usec; /* Convert from UTC to local time */
initialize_system_time(mpetime,1);
GETUSERMODE();
}
#endif /* HAVE_CLOCK_SETTIME */
#ifdef HAVE_SETTIMEOFDAY
if (rc && (SET_TOD_SETTIMEOFDAY == tod || !tod)) {
struct timeval adjtv;
/*
* Some broken systems don't reset adjtime() when the
* clock is stepped.
*/
adjtv.tv_sec = adjtv.tv_usec = 0;
adjtime(&adjtv, NULL);
errno = 0;
rc = SETTIMEOFDAY(tvp, tzp);
saved_errno = errno;
TRACE(1, ("ntp_set_tod: settimeofday: %d %m\n", rc));
if (!tod && !rc)
tod = SET_TOD_SETTIMEOFDAY;
}
#endif /* HAVE_SETTIMEOFDAY */
#ifdef HAVE_STIME
if (rc && (SET_TOD_STIME == tod || !tod)) {
long tp = tvp->tv_sec;
errno = 0;
rc = stime(&tp); /* lie as bad as SysVR4 */
saved_errno = errno;
TRACE(1, ("ntp_set_tod: stime: %d %m\n", rc));
if (!tod && !rc)
tod = SET_TOD_STIME;
}
#endif /* HAVE_STIME */
errno = saved_errno; /* for %m below */
TRACE(1, ("ntp_set_tod: Final result: %s: %d %m\n",
set_tod_used[tod], rc));
/*
* Say how we're setting the time of day
*/
if (!rc && NULL != set_tod_using) {
(*set_tod_using)(set_tod_used[tod]);
set_tod_using = NULL;
}
if (rc)
errno = saved_errno;
return rc;
}
#endif /* not SYS_WINNT */
#if defined (SYS_WINNT) || defined (SYS_VXWORKS) || defined(MPE)
/* getpass is used in ntpq.c and ntpdc.c */