#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ntp_machine.h"
#include "ntp_syslog.h"
#include "ntp_stdlib.h"
#include "ntp_unixtime.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifndef SYS_WINNT
#ifdef SYS_VXWORKS
#include "taskLib.h"
#include "sysLib.h"
#include "time.h"
#include "ntp_syslog.h"
#include "ioLib.h"
#include <socket.h>
int h_errno;
struct hostent *gethostbyname(char *name)
{
struct hostent *host1;
h_errno = 0;
host1 = (struct hostent *) malloc (sizeof(struct hostent));
host1->h_name = name;
host1->h_addrtype = AF_INET;
host1->h_aliases = name;
host1->h_length = 4;
host1->h_addr_list[0] = (char *)hostGetByName (name);
host1->h_addr_list[1] = NULL;
return host1;
}
struct hostent *gethostbyaddr(char *name, int size, int addr_type)
{
struct hostent *host1;
h_errno = 0;
host1 = (struct hostent *) malloc (sizeof(struct hostent));
host1->h_name = name;
host1->h_addrtype = AF_INET;
host1->h_aliases = name;
host1->h_length = 4;
host1->h_addr_list = NULL;
return host1;
}
struct servent *getservbyname (char *name, char *type)
{
struct servent *serv1;
serv1 = (struct servent *) malloc (sizeof(struct servent));
serv1->s_name = "ntp";
serv1->s_aliases = NULL;
serv1->s_port = 123;
serv1->s_proto = "udp";
return serv1;
}
#define CLKRATE sysClkRateGet()
#define CLK_GRANULARITY 1
#define USECS_PER_SEC MILLION
#define TICK (((USECS_PER_SEC / CLKRATE) / CLK_GRANULARITY) * CLK_GRANULARITY)
void sleep(int seconds)
{
taskDelay(seconds*TICK);
}
void alarm (int seconds)
{
sleep(seconds);
}
#endif
#ifdef SYS_PTX
#include <sys/procstats.h>
int
gettimeofday(
struct timeval *tvp
)
{
return (get_process_stats(tvp, PS_SELF, (struct procstats *) 0,
(struct procstats *) 0));
}
#endif
const char *set_tod_using = "UNKNOWN";
int
ntp_set_tod(
struct timeval *tvp,
void *tzp
)
{
int rc;
#ifdef HAVE_CLOCK_SETTIME
{
struct timespec ts;
ts.tv_sec = tvp->tv_sec;
ts.tv_nsec = 1000 * tvp->tv_usec;
rc = clock_settime(CLOCK_REALTIME, &ts);
if (!rc)
{
set_tod_using = "clock_settime";
return rc;
}
}
#endif
#ifdef HAVE_SETTIMEOFDAY
{
rc = SETTIMEOFDAY(tvp, tzp);
if (!rc)
{
set_tod_using = "settimeofday";
return rc;
}
}
#endif
#ifdef HAVE_STIME
{
rc = stime(&tvp->tv_sec);
if (!rc)
{
set_tod_using = "stime";
return rc;
}
}
#endif
set_tod_using = "Failed!";
return -1;
}
#ifdef SYS_CYGWIN32
#include <stdio.h>
#include <time.h>
int
settimeofday_NT(
struct timeval *tv
)
{
SYSTEMTIME st;
struct tm *gmtm;
long x = tv->tv_sec;
long y = tv->tv_usec;
printf("NT Set: %d %d\n",x,y);
gmtm = gmtime((const time_t *) &x);
st.wSecond = (WORD) gmtm->tm_sec;
st.wMinute = (WORD) gmtm->tm_min;
st.wHour = (WORD) gmtm->tm_hour;
st.wDay = (WORD) gmtm->tm_mday;
st.wMonth = (WORD) (gmtm->tm_mon + 1);
st.wYear = (WORD) (gmtm->tm_year + 1900);
st.wDayOfWeek = (WORD) gmtm->tm_wday;
st.wMilliseconds = (WORD) (y / 1000);
if (!SetSystemTime(&st)) {
msyslog(LOG_ERR, "SetSystemTime failed: %m\n");
return -1;
}
return 0;
}
#endif
#endif
#if defined (SYS_WINNT) || defined (SYS_VXWORKS)
char *
getpass(const char * prompt)
{
int c, i;
static char password[32];
#ifdef DEBUG
fprintf(stderr, "%s", prompt);
fflush(stderr);
#endif
for (i=0; i<sizeof(password)-1 && ((c=_getch())!='\n'); i++) {
password[i] = c;
}
password[i] = '\0';
return password;
}
#endif
#if !defined(HAVE_MEMSET)
void
ntp_memset(
char *a,
int x,
int c
)
{
while (c-- > 0)
*a++ = x;
}
#endif