Macros. Fix if statements to not also assign. Miscellaneous fixes.
bk: 3de1a516HBQVFxIX3agEEx4f6tkwOg
--- /dev/null
+/*
+ * Copyright (C) 1999-2001 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $Id: interfaceiter.h,v 1.10 2001/01/09 21:57:01 bwelling Exp $ */
+
+#ifndef ISC_INTERFACEITER_H
+#define ISC_INTERFACEITER_H 1
+
+/*****
+ ***** Module Info
+ *****/
+
+/*
+ * Interface iterator
+ *
+ * Iterate over the list of network interfaces.
+ *
+ * Interfaces whose address family is not supported are ignored and never
+ * returned by the iterator. Interfaces whose netmask, interface flags,
+ * or similar cannot be obtained are also ignored, and the failure is logged.
+ *
+ * Standards:
+ * The API for scanning varies greatly among operating systems.
+ * This module attempts to hide the differences.
+ */
+
+/***
+ *** Imports
+ ***/
+
+#include <isc/lang.h>
+#include <isc/netaddr.h>
+#include <isc/types.h>
+
+/*
+ * Public structure describing a network interface.
+ */
+
+struct isc_interface {
+ char name[32]; /* Interface name, null-terminated. */
+ unsigned int af; /* Address family. */
+ isc_netaddr_t address; /* Local address. */
+ isc_netaddr_t netmask; /* Network mask. */
+ isc_netaddr_t dstaddress; /* Destination address
+ (point-to-point only). */
+ isc_uint32_t flags; /* Flags; see below. */
+};
+
+/* Interface flags. */
+
+#define INTERFACE_F_UP 0x00000001U
+#define INTERFACE_F_POINTTOPOINT 0x00000002U
+#define INTERFACE_F_LOOPBACK 0x00000004U
+
+/***
+ *** Functions
+ ***/
+
+ISC_LANG_BEGINDECLS
+
+isc_result_t
+isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp);
+/*
+ * Create an iterator for traversing the operating system's list
+ * of network interfaces.
+ *
+ * Returns:
+ * ISC_R_SUCCESS
+ * ISC_R_NOMEMORY
+ * Various network-related errors
+ */
+
+isc_result_t
+isc_interfaceiter_first(isc_interfaceiter_t *iter);
+/*
+ * Position the iterator on the first interface.
+ *
+ * Returns:
+ * ISC_R_SUCCESS Success.
+ * ISC_R_NOMORE There are no interfaces.
+ */
+
+isc_result_t
+isc_interfaceiter_current(isc_interfaceiter_t *iter,
+ isc_interface_t *ifdata);
+/*
+ * Get information about the interface the iterator is currently
+ * positioned at and store it at *ifdata.
+ *
+ * Requires:
+ * The iterator has been successfully positioned using
+ * isc_interface_iter_first() / isc_interface_iter_next().
+ *
+ * Returns:
+ * ISC_R_SUCCESS Success.
+ */
+
+isc_result_t
+isc_interfaceiter_next(isc_interfaceiter_t *iter);
+/*
+ * Position the iterator on the next interface.
+ *
+ * Requires:
+ * The iterator has been successfully positioned using
+ * isc_interface_iter_first() / isc_interface_iter_next().
+ *
+ * Returns:
+ * ISC_R_SUCCESS Success.
+ * ISC_R_NOMORE There are no more interfaces.
+ */
+
+void
+isc_interfaceiter_destroy(isc_interfaceiter_t **iterp);
+/*
+ * Destroy the iterator.
+ */
+
+ISC_LANG_ENDDECLS
+
+#endif /* ISC_INTERFACEITER_H */
* numbers of each of the interfaces we are using.
*/
struct interface {
-#ifndef SYS_WINNT
- int fd; /* socket this is opened on */
- int bfd; /* socket for receiving broadcasts */
-#else
SOCKET fd; /* socket this is opened on */
SOCKET bfd; /* socket for receiving broadcasts */
-#endif
+ struct sockaddr_storage sin; /* interface address */
+ struct sockaddr_storage bcast; /* broadcast address */
+ struct sockaddr_storage mask; /* interface mask */
char name[8]; /* name of interface */
int flags; /* interface flags */
int last_ttl; /* last TTL specified */
- u_int32 addr_refid; /* IPv4 addr or IPv6 hash */
+ u_int addr_refid; /* IPv4 addr or IPv6 hash */
volatile long received; /* number of incoming packets */
long sent; /* number of outgoing packets */
long notsent; /* number of send failures */
# else /* SYS_WINNT */
# define CONFIG_FILE "%windir%\\system32\\drivers\\etc\\ntp.conf"
# define ALT_CONFIG_FILE "%windir%\\ntp.conf"
+# define NTP_KEYSDIR "%windir%\\system32\\drivers\\etc"
# endif /* SYS_WINNT */
#endif /* not CONFIG_FILE */
#endif /* 0 */
+/*
+ * Define these here for non-Windows NT systems
+ * SOCKET and INVALID_SOCKET are native macros
+ * on Windows NT and since they have different
+ * requirements we use them in the code and
+ * make them macros for everyone else
+ */
+#ifndef SYS_WINNT
+# define SOCKET int
+# define INVALID_SOCKET -1
+# define closesocket close
+#endif
/*
* Windows NT
*/
# define ifr_addr iiAddress.AddressIn
# define ifr_broadaddr iiBroadcastAddress.AddressIn
# define ifr_mask iiNetmask.AddressIn
+# define zz_family sin_family
# define S_IFREG _S_IFREG
# define stat _stat
# define unlink _unlink
# define fileno _fileno
# define write _write
+# define vsnprintf _vsnprintf
#ifndef close
# define close _close
#endif
#endif
#ifndef HAVE_TIMEGM
-extern time_t timegm P((struct tm *));
+extern time_t timegm P((struct tm *));
#endif
#ifdef HAVE_SYSV_TTYS
of refclock input data */
caddr_t srcclock; /* pointer to clock structure */
int datalen; /* lenth of data */
-#ifndef SYS_WINNT
- int fd; /* file descriptor */
-#else
SOCKET fd; /* file descriptor */
-#endif
u_long recvcount; /* count of receive completions */
};
|((u_short)(nitems)&0xfff))))
#define INFO_MBZ(mbz_itemsize) ((ntohs(mbz_itemsize)>>12)&0xf)
-#define INFO_ITEMSIZE(mbz_itemsize) (ntohs(mbz_itemsize)&0xfff)
+#define INFO_ITEMSIZE(mbz_itemsize) ((u_short)(ntohs(mbz_itemsize)&0xfff))
#define MBZ_ITEMSIZE(itemsize) (htons((u_short)(itemsize)))
/*
* IPv6 address
*/
+#ifdef SYS_WINNT
+#define in6_addr in_addr6
+#else
struct in6_addr {
union {
u_int8_t __u6_addr8[16];
};
#define s6_addr __u6_addr.__u6_addr8
+#endif
/*
* Definition of some useful macros to handle IP6 addresses
*/
+#ifdef SYS_WINNT
+#define IN6ADDR_ANY_INIT {{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}
+#else
#define IN6ADDR_ANY_INIT \
{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
+#endif
+
extern const struct in6_addr in6addr_any;
#define SIN6_LEN
+#ifndef HAVE_SOCKADDR_IN6
struct sockaddr_in6 {
#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
u_int8_t sin6_len; /* length of this struct(sa_family_t)*/
struct in6_addr sin6_addr; /* IP6 address */
u_int32_t sin6_scope_id; /* scope zone index */
};
+#endif
/*
* Unspecified
void service_ctrl (DWORD);
void worker_thread (void *);
#define sleep(x) Sleep((DWORD) x * 1000 /* milliseconds */ );
-#else
-#define SOCKET int
-#define INVALID_SOCKET -1
-#define closesocket close
#endif /* SYS_WINNT */
/* ntp_config.c */
extern struct peer *findexistingpeer P((struct sockaddr_storage *, struct peer *, int));
extern struct peer *findpeer P((struct sockaddr_storage *, struct interface *, int, int, int *));
extern struct peer *findpeerbyassoc P((u_int));
-extern struct peer *newpeer P((struct sockaddr_in *, struct interface *, int, int, int, int, u_int, u_char, int, keyid_t));
+extern struct peer *newpeer P((struct sockaddr_storage *, struct interface *, int, int, int, int, u_int, u_char, int, keyid_t));
extern void peer_all_reset P((void));
extern void peer_clr_stats P((void));
extern struct peer *peer_config P((struct sockaddr_storage *, struct interface *, int, int, int, int, u_int, int, keyid_t, u_char *));
* File descriptor masks etc. for call to select
*/
extern fd_set activefds;
-extern SOCKET maxactivefd;
+extern int maxactivefd;
/* ntp_loopfilter.c */
extern double drift_comp; /* clock frequency (s/s) */
extern int allow_panic; /* allow panic correction */
extern int mode_ntpdate; /* exit on first clock set */
extern int peer_ntpdate; /* count of ntpdate peers */
+extern int forground_process; /* run the process in the forground */
/*
* Clock state machine variables
struct sockaddr_storage srcadr; /* where packet came from */
#endif
struct interface *dstadr; /* interface datagram arrived thru */
-#ifndef SYS_WINNT
- int fd; /* fd on which it was received */
-#else
SOCKET fd; /* fd on which it was received */
-#endif
l_fp recv_time; /* time of arrival */
void (*receiver) P((struct recvbuf *)); /* routine to receive buffer */
int recv_length; /* number of octets received */
#include "ntp_stdlib.h"
#ifdef SYS_WINNT
+# include <stdarg.h>
# include "..\ports\winnt\libntp\log.h"
# include "..\ports\winnt\libntp\messages.h"
#endif
u_long ntp_syslogmask = ~ (u_long) 0;
#ifdef SYS_WINNT
-HANDLE hEventSource;
-LPTSTR lpszStrings[1];
-static WORD event_type[] = {
- EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
- EVENTLOG_WARNING_TYPE,
- EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
-};
+static char separator = '\\';
+#else
+static char separator = '/';
#endif /* SYS_WINNT */
extern char *progname;
#endif
va_list ap;
char buf[1025], nfmt[256];
-#if defined(SYS_WINNT)
- char xerr[50];
-#endif
register char c;
register char *n, *prog;
register const char *f;
- int olderrno;
+
+ /*
+ * Save the error value as soon as possible
+ */
+#ifdef SYS_WINNT
+ int olderrno = GetLastError();
+#else
+ int olderrno = errno;
+#endif
char *err;
#if defined(__STDC__) || defined(HAVE_STDARG_H)
fmt = va_arg(ap, char *);
#endif
- olderrno = errno;
n = nfmt;
f = fmt;
while ((c = *f++) != '\0' && c != '\n' && n < &nfmt[252]) {
continue;
}
err = 0;
-#if !defined(SYS_WINNT)
err = strerror(olderrno);
-#else /* SYS_WINNT */
- err = xerr;
- FormatMessage(
- FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
- (LPTSTR) err,
- sizeof(xerr),
- NULL);
-
-#endif /* SYS_WINNT */
if ((n + strlen(err)) < &nfmt[254]) {
strcpy(n, err);
n += strlen(err);
vsnprintf(buf, sizeof(buf), nfmt, ap);
#if !defined(VMS) && !defined (SYS_VXWORKS)
if (syslogit)
-#ifndef SYS_WINNT
syslog(level, "%s", buf);
-#else
- {
- lpszStrings[0] = buf;
-
- switch (event_type[level])
- {
- case EVENTLOG_ERROR_TYPE:
- reportAnEEvent(NTP_ERROR,1,lpszStrings);
- break;
- case EVENTLOG_INFORMATION_TYPE:
- reportAnIEvent(NTP_INFO,1,lpszStrings);
- break;
- case EVENTLOG_WARNING_TYPE:
- reportAnWEvent(NTP_WARNING,1,lpszStrings);
- break;
- } /* switch end */
-
- }
-#endif /* SYS_WINNT */
else
#endif /* VMS && SYS_VXWORKS*/
{
: level <= LOG_ERR ? stderr : stdout;
/* syslog() provides the timestamp, so if we're not using
syslog, we must provide it. */
- prog = strrchr(progname, '/');
+ prog = strrchr(progname, separator);
if (prog == NULL)
prog = progname;
else
#ifndef HAVE_IPV6
-#if 0
+#if defined(SYS_WINNT)
/* XXX This is the preferred way, but for some reason the SunOS compiler
* does not like it.
*/
}
char *
-gai_strerror(ecode)
- int ecode;
+gai_strerror(int ecode)
{
if (ecode < 0 || ecode > EAI_MAX)
ecode = EAI_MAX;
LIB_GETBUF(buffer);
if (getnameinfo((struct sockaddr *)sock, SOCKLEN(sock), buffer,
- LIB_BUFLENGTH /* NI_MAXHOST*/, NULL, NULL, 0))
+ LIB_BUFLENGTH /* NI_MAXHOST*/, NULL, 0, 0))
return stoa(sock);
return buffer;
timetv.tv_usec -= 1000000;
}
}
- if (ntp_set_tod(&timetv, (struct timezone *)0) != 0) {
+ if (ntp_set_tod(&timetv, NULL) != 0) {
msyslog(LOG_ERR, "Can't set time of day: %m");
return (0);
}
{
FILE *new_file;
- new_file = fopen(ntp_optarg, "a");
+ if(strcmp(ntp_optarg, "stderr") == 0)
+ new_file = stderr;
+ else if(strcmp(ntp_optarg, "stdout") == 0)
+ new_file = stdout;
+ else
+ new_file = fopen(ntp_optarg, "a");
if (new_file != NULL) {
NLOG(NLOG_SYSINFO)
msyslog(LOG_NOTICE, "logging to file %s", ntp_optarg);
case 'v':
case 'V':
set_sys_var(ntp_optarg, strlen(ntp_optarg)+1,
- RW | ((c == 'V') ? DEF : 0));
+ (u_short) (RW | ((c == 'V') ? DEF : 0)));
break;
case 'x':
keyid_t, u_char *));
static void do_resolve_internal P((void));
static void abort_resolve P((void));
-#if !defined(VMS)
+#if !defined(VMS) && !defined(SYS_WINNT)
static RETSIGTYPE catchchild P((int));
#endif /* VMS */
case CONFIG_TTL:
for (i = 1; i < ntokens && i < MAX_TTL; i++) {
- sys_ttl[i - 1] = atoi(tokens[i]);
+ sys_ttl[i - 1] = (u_char) atoi(tokens[i]);
sys_ttlmax = i - 1;
}
break;
"no value for setvar command - line ignored");
} else {
set_sys_var(tokens[1], strlen(tokens[1])+1,
- RW |
+ (u_short) (RW |
((((ntokens > 2)
&& !strcmp(tokens[2],
"default")))
? DEF
- : 0));
+ : 0)));
}
break;
}
-#if !defined(VMS)
+#if !defined(VMS) && !defined(SYS_WINNT)
/*
* catchchild - receive the resolver's exit status
*/
#else
/* no /tmp directory under NT */
{
- DWORD len;
if(!(GetTempPath((DWORD)MAX_PATH, (LPTSTR)res_file))) {
msyslog(LOG_ERR, "cannot get pathname for temporary directory: %m");
return;
*/
DWORD dwThreadId;
fflush(stdout);
- if (!(ResolverThreadHandle = CreateThread(
- NULL, /* no security attributes */
- 0, /* use default stack size */
+ ResolverThreadHandle = CreateThread(
+ NULL, /* no security attributes */
+ 0, /* use default stack size */
(LPTHREAD_START_ROUTINE) ntp_intres, /* thread function */
- NULL, /* argument to thread function */
- 0, /* use default creation flags */
- &dwThreadId))) { /* returns the thread identifier */
+ NULL, /* argument to thread function */
+ 0, /* use default creation flags */
+ &dwThreadId); /* returns the thread identifier */
+ if (ResolverThreadHandle == NULL) {
msyslog(LOG_ERR, "CreateThread() failed, can't start ntp_intres");
abort_resolve();
}
tptouse->tr_sequence = 1;
tptouse->tr_addr = *raddr;
tptouse->tr_localaddr = linter;
- tptouse->tr_version = version;
+ tptouse->tr_version = (u_char) version;
tptouse->tr_flags = TRAP_INUSE;
if (traptype == TRAP_TYPE_CONFIG)
tptouse->tr_flags |= TRAP_CONFIGURED;
if (!data || !size)
return;
- if ((k = *kv)) {
+ k = *kv;
+ if (k != NULL) {
while (!(k->flags & EOV)) {
s = data;
t = k->text;
case FILEGEN_MONTH:
caljulian(now, &cal);
- cal.yearday -= cal.monthday - 1;
+ cal.yearday = (u_short) (cal.yearday - cal.monthday + 1);
cal.monthday = 1;
cal.hour = cal.minute = cal.second = 0;
new_gen = caltontp(&cal);
gen->basename = (char*)emalloc(strlen(basename) + 1);
strcpy(gen->basename, basename);
}
- gen->type = type;
- gen->flag = flag;
+ gen->type = (u_char) type;
+ gen->flag = (u_char) flag;
/*
* make filegen use the new settings
/*
* File descriptor for ntp request code.
*/
-#ifndef SYS_WINNT
-static int sockfd = -1;
-#else
static SOCKET sockfd = INVALID_SOCKET; /* NT uses SOCKET */
-#endif
/* stuff to be filled in by caller */
#endif /* VMS */
+#if defined(SYS_WINNT)
+#include <transmitbuff.h>
+#endif
#if defined(VMS) || defined(SYS_WINNT)
/* structure used in SIOCGIFCONF request (after [KSR] OSF/1) */
#define lifr_dstaddr ifr_dstaddr
#define lifr_broadaddr ifr_broadaddr
#define lifr_flags ifr_flags
+#ifndef zz_family
#define zz_family sa_family
+#endif
#define lifreq ifreq
#else
#define zz_family ss_family
* File descriptor masks etc. for call to select
*/
fd_set activefds;
-SOCKET maxactivefd;
+int maxactivefd;
static int create_sockets P((u_int));
-static SOCKET open_socket P((struct sockaddr_in *, int, int));
+static SOCKET open_socket P((struct sockaddr_storage *, int, int));
static void close_socket P((SOCKET));
static void close_file P((int));
static char * fdbits P((int, fd_set *));
# ifdef STREAMS_TLI
struct strioctl ioc;
# endif /* STREAMS_TLI */
+ char buf[MAXINTERFACES*sizeof(struct lifreq)];
+ struct lifconf lifc;
+ struct lifreq lifreq, *lifr;
SOCKET vs;
- int n, i, j, size = 0;
+ int af, n, i, j, len, size = 0;
+ struct sockaddr_storage resmask;
#endif /* _BSDI_VERSION >= 199510 */
#ifdef DEBUG
/*
* create pseudo-interface with wildcard IPv4 address
*/
- inter_list[0].sin.sin_port = (u_short) port;
+ ((struct sockaddr_in*)&inter_list[0].sin)->sin_addr.s_addr = htonl(INADDR_ANY);
+ ((struct sockaddr_in*)&inter_list[0].sin)->sin_port = (u_short) port;
+ inter_list[0].sin.ss_family = AF_INET;
+ (void) strncpy(inter_list[0].name, "wildcard", sizeof(inter_list[0].name));
+ inter_list[0].mask.ss_family = AF_INET;
+ ((struct sockaddr_in*)&inter_list[0].mask)->sin_addr.s_addr = htonl(~(u_int32)0);
inter_list[0].received = 0;
inter_list[0].sent = 0;
inter_list[0].notsent = 0;
inter_list[0].flags = INT_BROADCAST;
any_interface = &inter_list[0];
+#ifdef HAVE_IPV6
/*
* create pseudo-interface with wildcard IPv6 address
*/
inter_list[1].sin.ss_family = AF_INET6;
((struct sockaddr_in6*)&inter_list[1].sin)->sin6_addr = in6addr_any;
- ((struct sockaddr_in6*)&inter_list[1].sin)->sin6_port = port;
+ ((struct sockaddr_in6*)&inter_list[1].sin)->sin6_port = (u_short) port;
(void) strncpy(inter_list[1].name, "wildcard", sizeof(inter_list[1].name));
memset(&((struct sockaddr_in6*)&inter_list[1].mask)->sin6_addr.s6_addr, 0xff, sizeof(struct in6_addr));
inter_list[1].mask.ss_family = AF_INET6;
inter_list[1].notsent = 0;
inter_list[1].flags = 0;
any6_interface = &inter_list[1];
-
+#endif
#if _BSDI_VERSION >= 199510
#if _BSDI_VERSION >= 199701
msyslog(LOG_ERR, "getifaddrs: %m");
exit(1);
}
+#ifdef HAVE_IPV6
i = 2;
+#else
+ i = 1;
+#endif
for (ifap = ifaddrs; ifap != NULL; ifap = ifap->ifa_next)
#else
if (getifaddrs(&ifaddrs, &num_if) < 0)
exit(1);
}
+#ifdef HAVE_IPV6
i = 2;
+#else
+ i = 1;
+#endif
for (ifap = ifaddrs, lp = ifap + num_if; ifap < lp; ifap++)
#endif
exit(1);
}
+#ifdef HAVE_IPV6
i = 2;
+#else
+ i = 1;
+#endif
# if !defined(SYS_WINNT)
lifc.lifc_len = sizeof(buf);
# endif
len = SOCKLEN(&lifr->lifr_addr);
# endif
size = sizeof(*lifr);
+#ifndef SYS_WINNT
if (size < sizeof(lifr->lifr_name) + len)
size = sizeof(lifr->lifr_name) + len;
+#else
+ if(size < len)
+ size = len;
+#endif
n -= size;
# if !defined(SYS_WINNT)
inter_list[i].flags = 0;
af = lifr->lifr_addr.zz_family;
- close(vs);
+ close_socket(vs);
- if (
- (vs = socket(af, SOCK_DGRAM, 0))
+ vs = socket(af, SOCK_DGRAM, 0);
# ifndef SYS_WINNT
- < 0
+ if (vs < 0)
# else /* SYS_WINNT */
- == INVALID_SOCKET
+ if (vs == INVALID_SOCKET)
# endif /* SYS_WINNT */
- ) {
+ {
msyslog(LOG_ERR,
"create_sockets: socket(%s, SOCK_DGRAM) failed: %m",
af == AF_INET ? "AF_INET" : "AF_INET6");
(void)strncpy(inter_list[i].name, lifreq.lifr_name,
sizeof(inter_list[i].name));
# endif
- inter_list[i].sin.sin_port = (u_short) port;
+ memcpy(&(inter_list[i].sin), &lifr->lifr_addr, SOCKLEN(&lifr->lifr_addr));
+ ((struct sockaddr_in*)&inter_list[i].sin)->sin_port = (u_short) port;
# if !defined SYS_WINNT && !defined SYS_CYGWIN32 /* no interface flags on NT */
if (inter_list[i].flags & INT_BROADCAST) {
# ifdef STREAMS_TLI
inter_list[i].bcast =
*(struct sockaddr_storage *)&lifreq.lifr_broadaddr;
# endif /* lifr_broadaddr */
- ((struct sockaddr_in*)&inter_list[i].bcast)->sin_port = port;
+ ((struct sockaddr_in*)&inter_list[i].bcast)->sin_port = (u_short) port;
}
if (inter_list[i].sin.ss_family == AF_INET) {
inter_list[i].mask.ss_family = inter_list[i].sin.ss_family;
# else
/* winnt here */
- inter_list[i].bcast.sin_port = (u_short) port;
+ inter_list[i].bcast = *(struct sockaddr_storage*)&lifreq.lifr_broadaddr;
+ inter_list[i].bcast.ss_family = inter_list[i].sin.ss_family;
+ ((struct sockaddr_in*)&inter_list[i].bcast)->sin_port = (u_short) port;
+ inter_list[i].mask = *(struct sockaddr_storage*)&ifreq.ifr_mask;
+ inter_list[i].mask.ss_family = inter_list[i].sin.ss_family;
# endif /* not SYS_WINNT */
/* correct the mask for ipv6 addresses */
if (i > MAXINTERFACES)
break;
}
- closesocket(vs);
+ close_socket(vs);
#endif /* _BSDI_VERSION >= 199510 */
ninterfaces = i;
/*
* enable possible multicast reception on the broadcast socket
*/
- inter_list[0].bcast.sin_port = (u_short) port;
+ inter_list[0].bcast.ss_family = AF_INET;
+ ((struct sockaddr_in*)&inter_list[0].bcast)->sin_port = (u_short) port;
+ ((struct sockaddr_in*)&inter_list[0].bcast)->sin_addr.s_addr = htonl(INADDR_ANY);
#endif /* MCAST */
/*
inet_ntoa(iaddr));
} else {
inter_list[i].fd = s;
- inter_list[i].bfd = -1;
+ inter_list[i].bfd = INVALID_SOCKET;
(void) strncpy(inter_list[i].name, "multicast",
sizeof(inter_list[i].name));
((struct sockaddr_in*)&inter_list[i].mask)->sin_addr.s_addr = htonl(~(u_int32)0);
sin6p = (struct sockaddr_in6*)&inter_list[i].sin;
memset((char *)&mreq6, 0, sizeof(mreq6));
memset((char *)&inter_list[i], 0, sizeof inter_list[0]);
- inter_list[i].bfd = INVALID_SOCKET;
+ sin6p->sin6_family = AF_INET6;
+ sin6p->sin6_addr = iaddr6;
+ sin6p->sin6_port = htons(123)
+
+ /*
+ * Try opening a socket for the specified class D address. This
+ * works under SunOS 4.x, but not OSF1 .. :-(
+ */
+ s = open_socket((struct sockaddr_storage*)sin6p, 0, 1);
+ if(s < 0){
+ memset((char *)&inter_list[i], 0, sizeof inter_list[0]);
+ i = 0;
+ /* HACK ! -- stuff in an address */
+ inter_list[i].bcast = addr;
+ msyslog(LOG_ERR,
+ "...multicast address %s using wildcard socket",
+ stoa(&addr));
+ } else {
+ interlist[i].fd = s;
+ interlist[i].bfd = -1
+ (void)strncpy(inter_list[i].name, "multicast",
+ sizeof(inter_list[i].name));
+ memset(&(((struct sockaddr_in6*)&inter_list[i].mask)->sin6_addr), 1, sizeof(struct in6_addr));
+ }
+
+ /*
+ * enable reception of multicast packets
+ */
+ mreq6.ipv6mr_multiaddr = iaddr6;
+ mreq6.ipv6mr_interface = 0;
+ if(setsockopt(inter_list[i].fd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
+ (char *)&mreq6, sizeof(mreq6)) == -1)
+ msyslog(LOG_ERR,
+ "setsockopt IPV6_JOIN_GROUP fails: %m on interface %d(%s),
+ mreq6.ipv6mr_interface, stoa(&addr));
+ inter_list[i].flags |= INT_MULTICAST;
+ if(i >= ninterfaces)
+ ninterfaces = i+1;
+
+ break
+#endif /* HAVE_IPV6 */
}
#ifdef DEBUG
if (!IN_CLASSD(haddr))
{
- inter_list[i].fd = INVALID_SOCKET;
- inter_list[i].bfd = INVALID_SOCKET;
+ sinaddr.sin_addr.s_addr = ((struct sockaddr_in*)&addr)->sin_addr.s_addr;
+ msyslog(LOG_ERR,
+ "invalid multicast address %s", stoa(&addr));
+ return;
}
/*
/* we have an explicit fd, so we can close it */
close_socket(inter_list[i].fd);
memset((char *)&inter_list[i], 0, sizeof inter_list[0]);
- inter_list[i].fd = -1;
- inter_list[i].bfd = -1;
+ inter_list[i].fd = INVALID_SOCKET;
+ inter_list[i].bfd = INVALID_SOCKET;
}
else
{
/* we have an explicit fd, so we can close it */
close_socket(inter_list[i].fd);
memset((char *)&inter_list[i], 0, sizeof inter_list[0]);
- inter_list[i].fd = -1;
- inter_list[i].bfd = -1;
+ inter_list[i].fd = INVALID_SOCKET;
+ inter_list[i].bfd = INVALID_SOCKET;
}
else
{
int turn_off_reuse
)
{
+#ifdef SYS_WINNT
+ int errval;
+#endif
SOCKET fd;
int on = 1, off = 0;
#if defined(IPTOS_LOWDELAY) && defined(IPPROTO_IP) && defined(IP_TOS)
#ifndef HAVE_IPV6
if (addr->ss_family == AF_INET6)
- return (-1);
+ return (INVALID_SOCKET);
#endif /* HAVE_IPV6 */
/* create a datagram (UDP) socket */
- if ( (fd = socket(addr->ss_family, SOCK_DGRAM, 0))
#ifndef SYS_WINNT
- < 0
-#else
- == INVALID_SOCKET
-#endif /* SYS_WINNT */
- )
- {
+ if ( (fd = socket(addr->ss_family, SOCK_DGRAM, 0)) < 0) {
if(addr->ss_family == AF_INET)
msyslog(LOG_ERR, "socket(AF_INET, SOCK_DGRAM, 0) failed: %m");
else if(addr->ss_family == AF_INET6)
msyslog(LOG_ERR, "socket(AF_INET6, SOCK_DGRAM, 0) failed: %m");
if (errno == EPROTONOSUPPORT || errno == EAFNOSUPPORT ||
errno == EPFNOSUPPORT)
- return (-1);
+ return (INVALID_SOCKET);
exit(1);
/*NOTREACHED*/
}
+#else
+ if ( (fd = socket(addr->ss_family, SOCK_DGRAM, 0)) == INVALID_SOCKET) {
+ errval = WSAGetLastError();
+ if(addr->ss_family == AF_INET)
+ msyslog(LOG_ERR, "socket(AF_INET, SOCK_DGRAM, 0) failed: %m");
+ else if(addr->ss_family == AF_INET6)
+ msyslog(LOG_ERR, "socket(AF_INET6, SOCK_DGRAM, 0) failed: %m");
+ if (errno == WSAEPROTONOSUPPORT || errno == WSAEAFNOSUPPORT ||
+ errno == WSAEPFNOSUPPORT)
+ return (INVALID_SOCKET);
+ exit(1);
+ /*NOTREACHED*/
+ }
+#endif /* SYS_WINNT */
/* set SO_REUSEADDR since we will be binding the same port
number on each interface */
fd, addr->ss_family, (int)ntohs(((struct sockaddr_in6*)addr)->sin6_port),
stoa(addr),
IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)addr)->sin6_addr), flags);
- else return -1;
+ else return INVALID_SOCKET;
msyslog(LOG_ERR, buff);
- closesocket(fd);
+ close_socket(fd);
/*
* soft fail if opening a multicast address
*/
- return INVALID_SOCKET;
+ if(addr->ss_family == AF_INET){
+ if(IN_CLASSD(ntohl(((struct sockaddr_in*)addr)->sin_addr.s_addr)))
+ return (INVALID_SOCKET);
+ }
+ else {
+ if(IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)addr)->sin6_addr))
+ return (INVALID_SOCKET);
+ }
#if 0
exit(1);
#else
* for the moment we use the bcast option to set multicast ttl
*/
if (ttl > 0 && ttl != inter->last_ttl) {
- char mttl = ttl;
+ char mttl = (char) ttl;
/*
* set the multicast ttl for outgoing packets
*/
if (setsockopt(inter->fd, IPPROTO_IP, IP_MULTICAST_TTL,
- &mttl, sizeof(mttl)) == -1)
- msyslog(LOG_ERR, "setsockopt IP_MULTICAST_TTL fails: %m");
+ (char *) &ttl, sizeof(ttl)) != 0) {
+ int errval = WSAGetLastError();
+ msyslog(LOG_ERR, "setsockopt IP_MULTICAST_TTL fails: err = %d %m", errval);
+ }
else
inter->last_ttl = ttl;
}
memcpy(&((struct sockaddr_in6*)&saddr)->sin6_addr, &((struct sockaddr_in6*)addr)->sin6_addr, sizeof(struct in6_addr));
((struct sockaddr_in*)&saddr)->sin_port = htons(2000);
s = socket(addr->ss_family, SOCK_DGRAM, 0);
+#ifndef SYS_WINNT
if (s < 0)
+#else
+ if (s == INVALID_SOCKET)
+#endif
return ANY_INTERFACE_CHOOSE(addr);
rtn = connect(s, (struct sockaddr *)&saddr, SOCKLEN(&saddr));
+#ifndef SYS_WINNT
if (rtn < 0)
+#else
+ if (rtn != 0)
+#endif
return ANY_INTERFACE_CHOOSE(addr);
rtn = getsockname(s, (struct sockaddr *)&saddr, &saddrlen);
+#ifndef SYS_WINNT
if (rtn < 0)
+#else
+ if (rtn != 0)
+#endif
return ANY_INTERFACE_CHOOSE(addr);
close_socket(s);
*/
if (peer != 0) {
peer->hmode = (u_char)hmode;
- peer->version = (u_char)version;
- peer->minpoll = (u_char)minpoll;
- peer->maxpoll = (u_char)maxpoll;
+ peer->version = (u_char) version;
+ peer->minpoll = (u_char) minpoll;
+ peer->maxpoll = (u_char) maxpoll;
peer->flags = flags | FLAG_CONFIG |
(peer->flags & FLAG_REFCLOCK);
peer->cast_flags = cast_flags;
- peer->ttl = ttl;
+ peer->ttl = (u_char) ttl;
peer->keyid = key;
peer->precision = sys_precision;
peer_clear(peer, "RMOT");
if (key > NTP_MAXKEY)
peer->flags |= FLAG_SKEY;
peer->cast_flags = cast_flags;
- peer->ttl = ttl;
+ peer->ttl = (u_char)ttl;
peer->keyid = key;
peer->precision = sys_precision;
if (cast_flags & MDF_ACAST)
double dtemp;
l_fp p_rec, p_xmt, p_org, p_reftime;
l_fp ci;
- int pmode, pleap, pstratum;
+ u_char pmode, pleap, pstratum;
/*
* Swap header fields and keep the books. The books amount to
* changes, we gotta reroll the keys.
*/
default:
- sys_stratum = sys_peer->stratum + 1;
+ sys_stratum = (u_char) (sys_peer->stratum + 1);
if (sys_stratum == 1 || sys_stratum == STRATUM_UNSPEC)
sys_refid = sys_peer->refid;
else
else if (hpoll < peer->minpoll)
peer->hpoll = peer->minpoll;
else
- peer->hpoll = hpoll;
+ peer->hpoll = (u_char) hpoll;
}
/*
} else if (peer->cast_flags & MDF_ACAST) {
if (sys_survivors >= sys_minclock || peer->ttl >=
sys_ttlmax)
- peer->kpoll = peer->hpoll + 3;
+ peer->kpoll = (u_char) (peer->hpoll + 3);
else
peer->kpoll = peer->hpoll;
peer->nextdate = peer->outdate + RANDPOLL(peer->kpoll);
} else {
- peer->kpoll = max(min(peer->ppoll, peer->hpoll),
+ peer->kpoll = (u_char) max(min(peer->ppoll, peer->hpoll),
peer->minpoll);
peer->nextdate = peer->outdate + RANDPOLL(peer->kpoll);
}
char *ident /* tally lights */
)
{
- int i;
+ u_char i;
/*
* If cryptographic credentials have been acquired, toss them to
peer->filter_disp[j] = dsp;
peer->filter_epoch[j] = current_time;
j++; j %= NTP_SHIFT;
- peer->filter_nextpt = j;
+ peer->filter_nextpt = (u_short) j;
/*
* Update dispersions since the last update and at the same
*/
m = 0;
for (i = 0; i < NTP_SHIFT; i++) {
- peer->filter_order[i] = ord[i];
+ peer->filter_order[i] = (u_char) ord[i];
if (dst[i] >= MAXDISPERSE || (m >= 2 && dst[i] >=
MAXDISTANCE))
continue;
*/
leap_consensus = 0;
for (i = nlist - 1; i >= 0; i--) {
- leap_consensus |= peer->leap;
peer = peer_list[i];
+ leap_consensus |= peer->leap;
peer->status = CTL_PST_SEL_SYNCCAND;
peer->flags |= FLAG_SYSPEER;
if (peer->stratum >= sys_floor && osurv >= sys_minclock)
sys_stattime = 0;
proto_clr_stats();
for (i = 0; i < MAX_TTL; i++) {
- sys_ttl[i] = (i + 1) * 256 / MAX_TTL - 1;
+ sys_ttl[i] = (u_char) ((i + 1) * 256 / MAX_TTL - 1);
sys_ttlmax = i;
}
#ifdef OPENSSL
{
struct refclockproc *pp;
- if (!(pp = peer->procptr))
+ pp = peer->procptr;
+ if (pp == NULL)
return;
if (code == CEVNT_BADREPLY)
pp->badformat++;
if (code == CEVNT_TIMEOUT)
pp->noreply++;
if (pp->currentstatus != code) {
- pp->currentstatus = code;
- pp->lastevent = code;
+ pp->currentstatus = (u_char)code;
+ pp->lastevent = (u_char)code;
if (code == CEVNT_FAULT)
msyslog(LOG_ERR,
"clock %s event '%s' (0x%02x)",
/*
* Allocate and initialize interface structure
*/
- if (!(pp = (struct refclockproc *)emalloc(sizeof(struct refclockproc))))
+ pp = (struct refclockproc *)emalloc(sizeof(struct refclockproc));
+ if (pp == NULL)
return (0);
memset((char *)pp, 0, sizeof(struct refclockproc));
typeunit[clktype][unit] = peer;
* Initialize structures
*/
peer->refclktype = clktype;
- peer->refclkunit = unit;
+ peer->refclkunit = (u_char)unit;
peer->flags |= FLAG_REFCLOCK;
peer->maxpoll = peer->minpoll;
peer->stratum = STRATUM_REFCLOCK;
* timestamp by noting its value is earlier than the buffer
* timestamp, but not more than one second earlier.
*/
- dpt = rbufp->recv_buffer;
+ dpt = (char *)rbufp->recv_buffer;
dpend = dpt + rbufp->recv_length;
trtmp = rbufp->recv_time;
unit = REFCLOCKUNIT(srcadr);
if (clktype >= num_refclock_conf || unit >= MAXUNIT)
return;
- if (!(peer = typeunit[clktype][unit]))
+ peer = typeunit[clktype][unit];
+ if (peer == NULL)
return;
if (peer->procptr == NULL)
return;
unit = REFCLOCKUNIT(srcadr);
if (clktype >= num_refclock_conf || unit >= MAXUNIT)
return;
- if (!(peer = typeunit[clktype][unit]))
+ peer = typeunit[clktype][unit];
+ if (peer == NULL)
return;
pp = peer->procptr;
ip->precision = pp->precision;
ip->version = pp->version;
ip->reach = pp->reach;
- ip->unreach = pp->unreach;
+ ip->unreach = (u_char) pp->unreach;
ip->flash = (u_char)pp->flash;
- ip->flash2 = pp->flash;
+ ip->flash2 = (u_short) pp->flash;
ip->estbdelay = HTONS_FP(DTOFP(pp->estbdelay));
ip->ttl = pp->ttl;
ip->associd = htons(pp->associd);
*/
volatile int debug;
+/*
+ * Set the processing not to be in the forground
+ */
+int forground_process = FALSE;
+
/*
* No-fork flag. If set, we do not become a background daemon.
*/
#endif /* SIGDIE2 */
#ifdef DEBUG
+#ifndef SYS_WINNT
static RETSIGTYPE moredebug P((int));
static RETSIGTYPE lessdebug P((int));
+#endif
#else /* not DEBUG */
static RETSIGTYPE no_debug P((int));
#endif /* not DEBUG */
if(!debug)
{
/* register our service control handler */
- if (!(sshStatusHandle = RegisterServiceCtrlHandler( TEXT("NetworkTimeProtocol"),
- (LPHANDLER_FUNCTION)service_ctrl)))
+ sshStatusHandle = RegisterServiceCtrlHandler( TEXT("NetworkTimeProtocol"),
+ (LPHANDLER_FUNCTION)service_ctrl);
+ if(sshStatusHandle == 0)
{
msyslog(LOG_ERR, "RegisterServiceCtrlHandler failed: %m");
return;
debug = 0; /* will be immediately re-initialized 8-( */
getstartup(argc, argv); /* startup configuration, catch logfile this time */
-#if !defined(SYS_WINNT) && !defined(VMS)
+#if !defined(VMS)
# ifndef LOG_DAEMON
openlog(cp, LOG_PID);
{
# if !defined(HAVE_SIGNALED_IO)
extern fd_set activefds;
- extern SOCKET maxactivefd;
+ extern int maxactivefd;
fd_set rdfdes;
int nfound;
*/
}
exit(1); /* unreachable */
+#ifndef SYS_WINNT
return 1; /* DEC OSF cc braindamage */
+#endif
}
#ifdef DEBUG
+#ifndef SYS_WINNT
/*
* moredebug - increase debugging verbosity
*/
}
errno = saved_errno;
}
+#endif
#else /* not DEBUG */
/*
* no_debug - We don't do the debug here.
if (debug)
printf ("starting Dumbclock with device %s\n",device);
#endif
- if (!(fd = refclock_open(device, SPEED232, 0)))
+ fd = refclock_open(device, SPEED232, 0);
+ if (fd < 0)
return (0);
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct dumbclock_unit *)
- emalloc(sizeof(struct dumbclock_unit)))) {
+ up = (struct dumbclock_unit *)emalloc(sizeof(struct dumbclock_unit));
+ if (up == NULL) {
(void) close(fd);
return (0);
}
up->tcswitch = 0;
return;
}
- pp->lencode = temp;
+ pp->lencode = (u_short)temp;
pp->lastrec = up->laststamp;
up->laststamp = trtmp;
up->tcswitch = 1;
pp->lastref = pp->lastrec;
refclock_receive(peer);
record_clock_stats(&peer->srcadr, pp->a_lastcode);
- up->lasthour = pp->hour;
+ up->lasthour = (u_char)pp->hour;
}
#if 0
pp->io.clock_recv = noentry;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
- pp->io.fd = -1;
+ pp->io.fd = INVALID_SOCKET;
pp->unitptr = (caddr_t)up;
get_systime(&pp->lastrec);
sprintf(pp->a_lastcode,"ST: %02X T: %02d:%02d:%02d.%03ld D: %02d.%02d.%04d",
m_time.wStatus, pp->hour, pp->minute, pp->second,
pp->nsec / 1000000, m_time.wDay, m_time.wMonth, m_time.wYear);
- pp->lencode = strlen(pp->a_lastcode);
+ pp->lencode = (u_short)strlen(pp->a_lastcode);
get_systime(&pp->lastrec);
up->rpt_next = 0; /* wait until next poll interval occur */
- pp->lencode = refclock_gtlin(rbufp, pp->a_lastcode, BMAX, &pp->lastrec);
+ pp->lencode = (u_short)refclock_gtlin(rbufp, pp->a_lastcode, BMAX, &pp->lastrec);
if (pp->lencode == 0)
return;
*/
(void)sprintf(device, DEVICE, unit);
- if (!(fd = refclock_open(device, SPEED232, LDISC_CLK)))
+ fd = refclock_open(device, SPEED232, LDISC_CLK);
+ if (fd < 0)
return (0);
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct nmeaunit *)
- emalloc(sizeof(struct nmeaunit)))) {
+ up = (struct nmeaunit *)emalloc(sizeof(struct nmeaunit));
+ if (up == NULL) {
(void) close(fd);
return (0);
}
peer = (struct peer *)rbufp->recv_srcclock;
pp = peer->procptr;
up = (struct nmeaunit *)pp->unitptr;
- rd_lencode = refclock_gtlin(rbufp, rd_lastcode, BMAX, &rd_tmp);
+ rd_lencode = (u_short)refclock_gtlin(rbufp, rd_lastcode, BMAX, &rd_tmp);
/*
* There is a case that a <CR><LF> gives back a "blank" line
* File descriptor masks etc. for call to select
*/
-#ifndef SYS_WINNT
+int ai_fam_templ;
+int nbsock;
+SOCKET fd[MAX_AF]; /* support up to 2 sockets */
+SOCKET fd_family[MAX_AF]; /* to remember the socket family */
#ifdef HAVE_POLL_H
struct pollfd fdmask[MAX_AF];
#else
u_fp e
)
{
- register int i;
+ u_short i;
i = server->filter_nextpt;
if (i < NTP_SHIFT) {
server->filter_offset[i] = *c;
server->filter_soffset[i] = LFPTOFP(c);
server->filter_error[i] = e;
- server->filter_nextpt = i + 1;
+ server->filter_nextpt = (u_short)(i + 1);
}
}
{
int i;
int cc;
- int sock = 0;
+ SOCKET sock = 0;
#ifdef SYS_WINNT
DWORD err;
static struct timeval tvsout = { DEFSTIMEOUT, 0 }; /* secondary time out */
static l_fp delay_time; /* delay time */
static char currenthost[LENHOSTNAME]; /* current host name */
-static int showhostnames = 1; /* show host names by default */
+int showhostnames = 1; /* show host names by default */
-#ifndef SYS_WINNT
+static int ai_fam_templ; /* address family */
+static SOCKET sockfd; /* fd socket is opened on */
static int havehost = 0; /* set to 1 when host open */
int s_port = 0;
n = 0;
for (xcp = builtins; xcp->keyword != 0; xcp++) {
if (*(xcp->keyword) != '?')
- cmdsort[n++] = xcp->keyword;
+ cmdsort[n++] = (char *)xcp->keyword;
}
for (xcp = opcmds; xcp->keyword != 0; xcp++)
- cmdsort[n++] = xcp->keyword;
+ cmdsort[n++] = (char *)xcp->keyword;
#ifdef QSORT_USES_VOID_P
qsort(cmdsort, (size_t)n, sizeof(char *), helpsort);
fprintf(stderr, "%s", keyprompt); fflush(stderr);
for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
if (p < &pbuf[18])
- *p++ = c;
+ *p++ = (char) c;
}
*p = '\0';
if (fi != stdin)
pl->addr6 = GET_INADDR6(pcmd->argval[qitems].netnum);
pl->v6_flag = 1;
}
- pl->port = s_port;
+ pl->port = (u_short)s_port;
pl->hmode = pl->flags = 0;
pl = (struct info_peer_list *)((char *)pl + sendsize);
}
pl->addr6 = GET_INADDR6(pcmd->argval[qitems].netnum);
pl->v6_flag = 1;
}
- pl->port = s_port;
+ pl->port = (u_short)s_port;
pl->hmode = plist[qitems].flags = 0;
pl = (struct info_peer_list *)((char *)pl + sendsize);
}
int err;
int sendsize;
+ /* Initialize cres */
+ cres.addr = 0;
+ cres.mask = 0;
+ cres.flags = 0;
+ cres.mflags = 0;
+ cres.v6_flag = 0;
+
again:
if (impl_ver == IMPL_XNTPD)
sendsize = sizeof(struct conf_restrict);
struct sockaddr_in hostaddr = { 0 }; /* host address */
int showhostnames = 1; /* show host names by default */
-#ifndef SYS_WINNT
-int sockfd; /* fd socket is opened on */
-#else
+int ai_fam_templ; /* address family */
SOCKET sockfd; /* fd socket is opened on */
-#endif
int havehost = 0; /* set to 1 when host open */
int s_port = 0;
struct servent *server_entry = NULL; /* server entry for ntp */
int errflg = 0;
extern int ntp_optind;
extern char *ntp_optarg;
+ int ai_fam_templ;
#ifdef NO_MAIN_ALLOWED
clear_globals();
exit(1);
}
}
-
+#endif /* SYS_WINNT */
sockfd = socket(ai->ai_family, SOCK_DGRAM, 0);
if (sockfd == INVALID_SOCKET) {
error("socket", "", "");
- exit(-1);
}
-#else
- sockfd = socket(ai->ai_family, SOCK_DGRAM, 0);
- if (sockfd == -1)
- error("socket", "", "");
-#endif /* SYS_WINNT */
#ifdef NEED_RCVBUF_SLOP
* Fill in the packet
*/
qpkt.li_vn_mode = PKT_LI_VN_MODE(0, pktversion, MODE_CONTROL);
- qpkt.r_m_e_op = (u_char)opcode & CTL_OP_MASK;
+ qpkt.r_m_e_op = (u_char)(opcode & CTL_OP_MASK);
qpkt.sequence = htons(sequence);
qpkt.status = 0;
qpkt.associd = htons((u_short)associd);
return 0;
}
- cal.monthday = *cp++ - '0'; /* ascii dependent */
+ cal.monthday = (u_char) (*cp++ - '0'); /* ascii dependent */
if (isdigit((int)*cp)) {
- cal.monthday = (cal.monthday << 3) + (cal.monthday << 1);
- cal.monthday += *cp++ - '0';
+ cal.monthday = (u_char)((cal.monthday << 3) + (cal.monthday << 1));
+ cal.monthday = (u_char)(cal.monthday + *cp++ - '0');
}
if (*cp++ != '-')
break;
if (i == 12)
return 0;
- cal.month = i + 1;
+ cal.month = (u_char)(i + 1);
if (*cp++ != '-')
return 0;
if (!isdigit((int)*cp))
return 0;
- cal.year = *cp++ - '0';
+ cal.year = (u_short)(*cp++ - '0');
if (isdigit((int)*cp)) {
- cal.year = (cal.year << 3) + (cal.year << 1);
- cal.year += *cp++ - '0';
+ cal.year = (u_short)((cal.year << 3) + (cal.year << 1));
+ cal.year = (u_short)(*cp++ - '0');
}
if (isdigit((int)*cp)) {
- cal.year = (cal.year << 3) + (cal.year << 1);
- cal.year += *cp++ - '0';
+ cal.year = (u_short)((cal.year << 3) + (cal.year << 1));
+ cal.year = (u_short)(cal.year + *cp++ - '0');
}
if (isdigit((int)*cp)) {
- cal.year = (cal.year << 3) + (cal.year << 1);
- cal.year += *cp++ - '0';
+ cal.year = (u_short)((cal.year << 3) + (cal.year << 1));
+ cal.year = (u_short)(cal.year + *cp++ - '0');
}
/*
if (*cp++ != ' ' || !isdigit((int)*cp))
return 0;
- cal.hour = *cp++ - '0';
+ cal.hour = (u_char)(*cp++ - '0');
if (isdigit((int)*cp)) {
- cal.hour = (cal.hour << 3) + (cal.hour << 1);
- cal.hour += *cp++ - '0';
+ cal.hour = (u_char)((cal.hour << 3) + (cal.hour << 1));
+ cal.hour = (u_char)(cal.hour + *cp++ - '0');
}
if (*cp++ != ':' || !isdigit((int)*cp))
return 0;
- cal.minute = *cp++ - '0';
+ cal.minute = (u_char)(*cp++ - '0');
if (isdigit((int)*cp)) {
- cal.minute = (cal.minute << 3) + (cal.minute << 1);
- cal.minute += *cp++ - '0';
+ cal.minute = (u_char)((cal.minute << 3) + (cal.minute << 1));
+ cal.minute = (u_char)(cal.minute + *cp++ - '0');
}
if (*cp++ != ':' || !isdigit((int)*cp))
return 0;
- cal.second = *cp++ - '0';
+ cal.second = (u_char)(*cp++ - '0');
if (isdigit((int)*cp)) {
- cal.second = (cal.second << 3) + (cal.second << 1);
- cal.second += *cp++ - '0';
+ cal.second = (u_char)((cal.second << 3) + (cal.second << 1));
+ cal.second = (u_char)(cal.second + *cp++ - '0');
}
/*
n = 0;
for (xcp = builtins; xcp->keyword != 0; xcp++) {
if (*(xcp->keyword) != '?')
- cmdsort[n++] = xcp->keyword;
+ cmdsort[n++] = (char *)xcp->keyword;
}
for (xcp = opcmds; xcp->keyword != 0; xcp++)
- cmdsort[n++] = xcp->keyword;
+ cmdsort[n++] = (char *)xcp->keyword;
#ifdef QSORT_USES_VOID_P
qsort(cmdsort, (size_t)n, sizeof(char *), helpsort);
fprintf(stderr, "%s", keyprompt); fflush(stderr);
for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
if (p < &pbuf[18])
- *p++ = c;
+ *p++ = (char)c;
}
*p = '\0';
if (fi != stdin)
if (c < ' ') {
*ocp++ = '^';
- *ocp++ = c + '@';
+ *ocp++ = (u_char)(c + '@');
} else if (c == 0177) {
*ocp++ = '^';
*ocp++ = '?';
register int varid;
char *name;
char *value;
- int output_raw;
+ char output_raw;
int fmt;
struct ctl_var *varlist;
l_fp lfp;
case AF_INET:
dummy = ((struct sockaddr_in *)sock)->sin_addr.s_addr;
dummy = ntohl(dummy);
- ch = ((dummy&0xf0000000)==0xe0000000) ? 'm' :
+ ch = (char)(((dummy&0xf0000000)==0xe0000000) ? 'm' :
((dummy&0x000000ff)==0x000000ff) ? 'b' :
((dummy&0xffffffff)==0x7f000001) ? 'l' :
((dummy&0xffffffe0)==0x00000000) ? '-' :
- 'u';
+ 'u');
break;
case AF_INET6:
sin6 = (struct sockaddr_in6 *)sock;
# define HAVE_NO_NICE
# define TIME_WITH_SYS_TIME
# define HAVE_IO_COMPLETION_PORT
+# define HAVE_SOCKADDR_IN6
//# define volatile
# define STDC_HEADERS
extern void io_completion_port_add_socket (struct interface *);
-extern DWORD io_completion_port_sendto (struct interface *, struct pkt *, int, struct sockaddr_in*);
+extern DWORD io_completion_port_sendto (struct interface *, struct pkt *, int, struct sockaddr_storage*);
extern HANDLE get_io_event (void);
-/**************************************************************
- * Dummy Header for Unix to Windows NT portability
- * Created for NTP package
- **************************************************************/
-
-#ifndef SYSLOG_H
-#define SYSLOG_H
-
-#define LOG_EMERG 0 /* system is unusable */
-#define LOG_ALERT 1 /* action must be taken immediately */
-#define LOG_CRIT 2 /* critical conditions */
-#define LOG_ERR 3 /* error conditions */
-#define LOG_WARNING 4 /* warning conditions */
-#define LOG_NOTICE 5 /* normal but signification condition */
-#define LOG_INFO 6 /* informational */
-#define LOG_DEBUG 7 /* debug-level messages */
-
-#endif /* SYSLOG_H */
+/*
+ * Copyright (C) 2001 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* From BIND 9 lib/isc/include/isc/: syslog.h,v 1.4 2002/08/01 03:43:31 mayer */
+
+#ifndef _SYSLOG_H
+#define _SYSLOG_H
+
+#include <stdio.h>
+
+/* Constant definitions for openlog() */
+#define LOG_PID 1
+#define LOG_CONS 2
+/* NT event log does not support facility level */
+#define LOG_KERN 0
+#define LOG_USER 0
+#define LOG_MAIL 0
+#define LOG_DAEMON 0
+#define LOG_AUTH 0
+#define LOG_SYSLOG 0
+#define LOG_LPR 0
+#define LOG_LOCAL0 0
+#define LOG_LOCAL1 0
+#define LOG_LOCAL2 0
+#define LOG_LOCAL3 0
+#define LOG_LOCAL4 0
+#define LOG_LOCAL5 0
+#define LOG_LOCAL6 0
+#define LOG_LOCAL7 0
+
+#define LOG_EMERG 0 /* system is unusable */
+#define LOG_ALERT 1 /* action must be taken immediately */
+#define LOG_CRIT 2 /* critical conditions */
+#define LOG_ERR 3 /* error conditions */
+#define LOG_WARNING 4 /* warning conditions */
+#define LOG_NOTICE 5 /* normal but signification condition */
+#define LOG_INFO 6 /* informational */
+#define LOG_DEBUG 7 /* debug-level messages */
+
+/*
+ * These are ignored on NT
+ */
+#define LOG_NDELAY 0 /* Open the connection to syslogd immediately */
+
+#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
+
+void
+syslog(int level, const char *fmt, ...);
+
+void
+openlog(const char *, int, ...);
+
+void
+closelog(void);
+
+void
+ModifyLogLevel(int level);
+
+int
+setlogmask(int maskpri);
+
+void
+InitNTLogging(FILE *, int);
+
+void
+NTReportError(const char *, const char *);
+
+#endif
--- /dev/null
+/*
+ * Copyright (C) 1999-2001 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $Id: interfaceiter.c,v 1.7 2001/11/27 01:56:21 gson Exp $ */
+
+/*
+ * Note that this code will need to be revisited to support IPv6 Interfaces.
+ * For now we just iterate through IPv4 interfaces.
+ */
+
+#include <config.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <isc/interfaceiter.h>
+#include <isc/mem.h>
+#include <isc/result.h>
+#include <isc/string.h>
+#include <isc/strerror.h>
+#include <isc/types.h>
+#include <isc/util.h>
+
+/* Common utility functions */
+
+/*
+ * Extract the network address part from a "struct sockaddr".
+ *
+ * The address family is given explicity
+ * instead of using src->sa_family, because the latter does not work
+ * for copying a network mask obtained by SIOCGIFNETMASK (it does
+ * not have a valid address family).
+ */
+
+
+#define IFITER_MAGIC 0x49464954U /* IFIT. */
+#define VALID_IFITER(t) ((t) != NULL && (t)->magic == IFITER_MAGIC)
+
+struct isc_interfaceiter {
+ unsigned int magic; /* Magic number. */
+ isc_mem_t *mctx;
+ int socket;
+ INTERFACE_INFO IFData; /* Current Interface Info */
+ int numIF; /* Current Interface count */
+ int totalIF; /* Total Number
+ of Interfaces */
+ INTERFACE_INFO *buf; /* Buffer for WSAIoctl data. */
+ unsigned int bufsize; /* Bytes allocated. */
+ INTERFACE_INFO *pos; /* Current offset in IF List */
+ isc_interface_t current; /* Current interface data. */
+ isc_result_t result; /* Last result code. */
+};
+
+
+/*
+ * Size of buffer for SIO_GET_INTERFACE_LIST, in number of interfaces.
+ * We assume no sane system will have more than than 1K of IP addresses on
+ * all of its adapters.
+ */
+#define IFCONF_SIZE_INITIAL 16
+#define IFCONF_SIZE_INCREMENT 64
+#define IFCONF_SIZE_MAX 1040
+
+static void
+get_addr(unsigned int family, isc_netaddr_t *dst, struct sockaddr *src) {
+ dst->family = family;
+ switch (family) {
+ case AF_INET:
+ memcpy(&dst->type.in,
+ &((struct sockaddr_in *) src)->sin_addr,
+ sizeof(struct in_addr));
+ break;
+ case AF_INET6:
+ memcpy(&dst->type.in6,
+ &((struct sockaddr_in6 *) src)->sin6_addr,
+ sizeof(struct in6_addr));
+ break;
+ default:
+ INSIST(0);
+ break;
+ }
+}
+
+isc_result_t
+isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
+ char strbuf[ISC_STRERRORSIZE];
+ isc_interfaceiter_t *iter;
+ isc_result_t result;
+ int error;
+ unsigned long bytesReturned = 0;
+
+ REQUIRE(mctx != NULL);
+ REQUIRE(iterp != NULL);
+ REQUIRE(*iterp == NULL);
+
+ iter = isc_mem_get(mctx, sizeof(*iter));
+ if (iter == NULL)
+ return (ISC_R_NOMEMORY);
+
+ iter->mctx = mctx;
+ iter->buf = NULL;
+
+ /*
+ * Create an unbound datagram socket to do the
+ * SIO_GET_INTERFACE_LIST WSAIoctl on.
+ */
+ if ((iter->socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ error = WSAGetLastError();
+ isc__strerror(error, strbuf, sizeof(strbuf));
+ UNEXPECTED_ERROR(__FILE__, __LINE__,
+ "making interface scan socket: %s",
+ strbuf);
+ result = ISC_R_UNEXPECTED;
+ goto socket_failure;
+ }
+
+ /*
+ * Get the interface configuration, allocating more memory if
+ * necessary.
+ */
+ iter->bufsize = IFCONF_SIZE_INITIAL*sizeof(INTERFACE_INFO);
+
+ for (;;) {
+ iter->buf = isc_mem_get(mctx, iter->bufsize);
+ if (iter->buf == NULL) {
+ result = ISC_R_NOMEMORY;
+ goto alloc_failure;
+ }
+
+ if (WSAIoctl(iter->socket, SIO_GET_INTERFACE_LIST,
+ 0, 0, iter->buf, iter->bufsize,
+ &bytesReturned, 0, 0) == SOCKET_ERROR)
+ {
+ error = WSAGetLastError();
+ if (error != WSAEFAULT && error != WSAENOBUFS) {
+ errno = error;
+ isc__strerror(error, strbuf, sizeof(strbuf));
+ UNEXPECTED_ERROR(__FILE__, __LINE__,
+ "get interface configuration: %s",
+ strbuf);
+ result = ISC_R_UNEXPECTED;
+ goto ioctl_failure;
+ }
+ /*
+ * EINVAL. Retry with a bigger buffer.
+ */
+ } else {
+ /*
+ * The WSAIoctl succeeded.
+ * If the number of the returned bytes is the same
+ * as the buffer size, we will grow it just in
+ * case and retry.
+ */
+ if (bytesReturned > 0 &&
+ (bytesReturned < iter->bufsize))
+ break;
+ }
+ if (iter->bufsize >= IFCONF_SIZE_MAX*sizeof(INTERFACE_INFO)) {
+ UNEXPECTED_ERROR(__FILE__, __LINE__,
+ "get interface configuration: "
+ "maximum buffer size exceeded");
+ result = ISC_R_UNEXPECTED;
+ goto ioctl_failure;
+ }
+ isc_mem_put(mctx, iter->buf, iter->bufsize);
+
+ iter->bufsize += IFCONF_SIZE_INCREMENT *
+ sizeof(INTERFACE_INFO);
+ }
+
+ /*
+ * A newly created iterator has an undefined position
+ * until isc_interfaceiter_first() is called.
+ */
+ iter->pos = NULL;
+ iter->result = ISC_R_FAILURE;
+ iter->numIF = 0;
+ iter->totalIF = bytesReturned/sizeof(INTERFACE_INFO);
+
+
+ iter->magic = IFITER_MAGIC;
+ *iterp = iter;
+ /* We don't need the socket any more, so close it */
+ closesocket(iter->socket);
+ return (ISC_R_SUCCESS);
+
+ ioctl_failure:
+ isc_mem_put(mctx, iter->buf, iter->bufsize);
+
+ alloc_failure:
+ (void) closesocket(iter->socket);
+
+ socket_failure:
+ isc_mem_put(mctx, iter, sizeof(*iter));
+ return (result);
+}
+
+/*
+ * Get information about the current interface to iter->current.
+ * If successful, return ISC_R_SUCCESS.
+ * If the interface has an unsupported address family, or if
+ * some operation on it fails, return ISC_R_IGNORE to make
+ * the higher-level iterator code ignore it.
+ */
+
+static isc_result_t
+internal_current(isc_interfaceiter_t *iter, int family) {
+ BOOL ifNamed = FALSE;
+ unsigned long flags;
+
+ REQUIRE(VALID_IFITER(iter));
+ REQUIRE(iter->numIF >= 0);
+
+ memset(&iter->current, 0, sizeof(iter->current));
+ iter->current.af = family;
+
+ get_addr(family, &iter->current.address,
+ (struct sockaddr *)&(iter->IFData.iiAddress));
+
+ /*
+ * Get interface flags.
+ */
+
+ iter->current.flags = 0;
+ flags = iter->IFData.iiFlags;
+
+ if ((flags & IFF_UP) != 0)
+ iter->current.flags |= INTERFACE_F_UP;
+
+ if ((flags & IFF_POINTTOPOINT) != 0) {
+ iter->current.flags |= INTERFACE_F_POINTTOPOINT;
+ sprintf(iter->current.name, "PPP Interface %d", iter->numIF);
+ ifNamed = TRUE;
+ }
+
+ if ((flags & IFF_LOOPBACK) != 0) {
+ iter->current.flags |= INTERFACE_F_LOOPBACK;
+ sprintf(iter->current.name, "Loopback Interface %d",
+ iter->numIF);
+ ifNamed = TRUE;
+ }
+
+ /*
+ * If the interface is point-to-point, get the destination address.
+ */
+ if ((iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) {
+ get_addr(family, &iter->current.dstaddress,
+ (struct sockaddr *)&(iter->IFData.iiBroadcastAddress));
+ }
+
+ if (ifNamed == FALSE)
+ sprintf(iter->current.name,
+ "TCP/IP Interface %d", iter->numIF);
+
+ /*
+ * Get the network mask.
+ */
+ switch (family) {
+ case AF_INET:
+ get_addr(family, &iter->current.netmask,
+ (struct sockaddr *)&(iter->IFData.iiNetmask));
+ break;
+ case AF_INET6:
+ break;
+ }
+
+ return (ISC_R_SUCCESS);
+}
+
+/*
+ * Step the iterator to the next interface. Unlike
+ * isc_interfaceiter_next(), this may leave the iterator
+ * positioned on an interface that will ultimately
+ * be ignored. Return ISC_R_NOMORE if there are no more
+ * interfaces, otherwise ISC_R_SUCCESS.
+ */
+static isc_result_t
+internal_next(isc_interfaceiter_t *iter) {
+ if (iter->numIF >= iter->totalIF)
+ return (ISC_R_NOMORE);
+
+ /*
+ * The first one needs to be set up to point to the last
+ * Element of the array. Go to the end and back up
+ * Microsoft's implementation is peculiar for returning
+ * the list in reverse order
+ */
+
+ if (iter->numIF == 0)
+ iter->pos = (INTERFACE_INFO *)(iter->buf + (iter->totalIF));
+
+ iter->pos--;
+ if (&(iter->pos) < &(iter->buf))
+ return (ISC_R_NOMORE);
+
+ memset(&(iter->IFData), 0, sizeof(INTERFACE_INFO));
+ memcpy(&(iter->IFData), iter->pos, sizeof(INTERFACE_INFO));
+ iter->numIF++;
+
+ return (ISC_R_SUCCESS);
+}
+
+isc_result_t
+isc_interfaceiter_current(isc_interfaceiter_t *iter,
+ isc_interface_t *ifdata) {
+ REQUIRE(iter->result == ISC_R_SUCCESS);
+ memcpy(ifdata, &iter->current, sizeof(*ifdata));
+ return (ISC_R_SUCCESS);
+}
+
+isc_result_t
+isc_interfaceiter_first(isc_interfaceiter_t *iter) {
+ isc_result_t result;
+
+ REQUIRE(VALID_IFITER(iter));
+
+ iter->numIF = 0;
+ for (;;) {
+ result = internal_next(iter);
+ if (result != ISC_R_SUCCESS)
+ break;
+ result = internal_current(iter, AF_INET);
+ if (result != ISC_R_IGNORE)
+ break;
+ }
+ iter->result = result;
+ return (result);
+}
+
+isc_result_t
+isc_interfaceiter_next(isc_interfaceiter_t *iter) {
+ isc_result_t result;
+
+ REQUIRE(VALID_IFITER(iter));
+ REQUIRE(iter->result == ISC_R_SUCCESS);
+
+ for (;;) {
+ result = internal_next(iter);
+ if (result != ISC_R_SUCCESS)
+ break;
+ result = internal_current(iter,AF_INET);
+ if (result != ISC_R_IGNORE)
+ break;
+ }
+ iter->result = result;
+ return (result);
+}
+
+void
+isc_interfaceiter_destroy(isc_interfaceiter_t **iterp) {
+ isc_interfaceiter_t *iter;
+ REQUIRE(iterp != NULL);
+ iter = *iterp;
+ REQUIRE(VALID_IFITER(iter));
+
+ isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
+
+ iter->magic = 0;
+ isc_mem_put(iter->mctx, iter, sizeof(*iter));
+ *iterp = NULL;
+}
+
# End Source File
# Begin Source File
+SOURCE=..\..\..\libntp\ntp_rfc2553.c
+# End Source File
+# Begin Source File
+
SOURCE=..\..\..\libntp\numtoa.c
# End Source File
# Begin Source File
# End Source File
# Begin Source File
+SOURCE=..\..\..\libntp\socktoa.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\libntp\socktohost.c
+# End Source File
+# Begin Source File
+
SOURCE=..\..\..\libntp\statestr.c
# End Source File
# Begin Source File
-SOURCE=..\..\..\libntp\strerror.c
+SOURCE=.\strerror.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\syslog.c
# End Source File
# Begin Source File
--- /dev/null
+/*
+ * Copyright (C) 2002 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* From BIND 9 lib/isc/win32/: strerror.c,v 1.5 2002/08/01 03:52:14 mayer */
+
+#include <stdio.h>
+#include <string.h>
+#include <winsock2.h>
+
+/*
+ * Forward declarations
+ */
+
+char *
+FormatError(int error);
+
+char *
+GetWSAErrorMessage(int errval);
+
+char *
+NTstrerror(int err, BOOL *bfreebuf);
+
+char *
+strerror(int errnum) {
+ BOOL bfreebuf;
+ return (NTstrerror(errnum, &bfreebuf));
+}
+/*
+ * This routine needs to free up any buffer allocated by FormatMessage
+ * if that routine gets used.
+ */
+
+void
+isc__strerror(int num, char *buf, size_t size) {
+ char *msg;
+ BOOL freebuf;
+ unsigned int unum = num;
+
+ freebuf = FALSE;
+ msg = NTstrerror(num, &freebuf);
+ if (msg != NULL)
+ _snprintf(buf, size, "%s", msg);
+ else
+ _snprintf(buf, size, "Unknown error: %u", unum);
+ if(freebuf && msg != NULL) {
+ LocalFree(msg);
+ }
+}
+
+/*
+ * Note this will cause a memory leak unless the memory allocated here
+ * is freed by calling LocalFree. isc__strerror does this before unlocking.
+ * This only gets called if there is a system type of error and will likely
+ * be an unusual event.
+ */
+char *
+FormatError(int error) {
+ LPVOID lpMsgBuf = NULL;
+ FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ error,
+ /* Default language */
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf,
+ 0,
+ NULL);
+
+ return (lpMsgBuf);
+}
+
+/*
+ * This routine checks the error value and calls the WSA Windows Sockets
+ * Error message function GetWSAErrorMessage below if it's within that range
+ * since those messages are not available in the system error messages.
+ */
+char *
+NTstrerror(int err, BOOL *bfreebuf) {
+ char *retmsg = NULL;
+
+ /* Copy the error value first in case of other errors */
+ DWORD errval = err;
+
+ *bfreebuf = FALSE;
+
+ /* Get the Winsock2 error messages */
+ if (errval >= WSABASEERR && errval <= (WSABASEERR + 1015)) {
+ retmsg = GetWSAErrorMessage(errval);
+ if (retmsg != NULL)
+ return (retmsg);
+ }
+ /*
+ * If it's not one of the standard Unix error codes,
+ * try a system error message
+ */
+ if (errval > (DWORD) _sys_nerr) {
+ *bfreebuf = TRUE;
+ return (FormatError(errval));
+ } else {
+ return (_sys_errlist[errval]);
+ }
+}
+
+/*
+ * This is a replacement for perror
+ */
+void __cdecl
+NTperror(char *errmsg) {
+ /* Copy the error value first in case of other errors */
+ int errval = errno;
+ BOOL bfreebuf = FALSE;
+ char *msg;
+
+ msg = NTstrerror(errval, &bfreebuf);
+ fprintf(stderr, "%s: %s\n", errmsg, msg);
+ if(bfreebuf == TRUE) {
+ LocalFree(msg);
+ }
+
+}
+
+/*
+ * Return the error string related to Winsock2 errors.
+ * This function is necessary since FormatMessage knows nothing about them
+ * and there is no function to get them.
+ */
+char *
+GetWSAErrorMessage(int errval) {
+ char *msg;
+
+ switch (errval) {
+
+ case WSAEINTR:
+ msg = "Interrupted system call";
+ break;
+
+ case WSAEBADF:
+ msg = "Bad file number";
+ break;
+
+ case WSAEACCES:
+ msg = "Permission denied";
+ break;
+
+ case WSAEFAULT:
+ msg = "Bad address";
+ break;
+
+ case WSAEINVAL:
+ msg = "Invalid argument";
+ break;
+
+ case WSAEMFILE:
+ msg = "Too many open sockets";
+ break;
+
+ case WSAEWOULDBLOCK:
+ msg = "Operation would block";
+ break;
+
+ case WSAEINPROGRESS:
+ msg = "Operation now in progress";
+ break;
+
+ case WSAEALREADY:
+ msg = "Operation already in progress";
+ break;
+
+ case WSAENOTSOCK:
+ msg = "Socket operation on non-socket";
+ break;
+
+ case WSAEDESTADDRREQ:
+ msg = "Destination address required";
+ break;
+
+ case WSAEMSGSIZE:
+ msg = "Message too long";
+ break;
+
+ case WSAEPROTOTYPE:
+ msg = "Protocol wrong type for socket";
+ break;
+
+ case WSAENOPROTOOPT:
+ msg = "Bad protocol option";
+ break;
+
+ case WSAEPROTONOSUPPORT:
+ msg = "Protocol not supported";
+ break;
+
+ case WSAESOCKTNOSUPPORT:
+ msg = "Socket type not supported";
+ break;
+
+ case WSAEOPNOTSUPP:
+ msg = "Operation not supported on socket";
+ break;
+
+ case WSAEPFNOSUPPORT:
+ msg = "Protocol family not supported";
+ break;
+
+ case WSAEAFNOSUPPORT:
+ msg = "Address family not supported";
+ break;
+
+ case WSAEADDRINUSE:
+ msg = "Address already in use";
+ break;
+
+ case WSAEADDRNOTAVAIL:
+ msg = "Can't assign requested address";
+ break;
+
+ case WSAENETDOWN:
+ msg = "Network is down";
+ break;
+
+ case WSAENETUNREACH:
+ msg = "Network is unreachable";
+ break;
+
+ case WSAENETRESET:
+ msg = "Net connection reset";
+ break;
+
+ case WSAECONNABORTED:
+ msg = "Software caused connection abort";
+ break;
+
+ case WSAECONNRESET:
+ msg = "Connection reset by peer";
+ break;
+
+ case WSAENOBUFS:
+ msg = "No buffer space available";
+ break;
+
+ case WSAEISCONN:
+ msg = "Socket is already connected";
+ break;
+
+ case WSAENOTCONN:
+ msg = "Socket is not connected";
+ break;
+
+ case WSAESHUTDOWN:
+ msg = "Can't send after socket shutdown";
+ break;
+
+ case WSAETOOMANYREFS:
+ msg = "Too many references: can't splice";
+ break;
+
+ case WSAETIMEDOUT:
+ msg = "Connection timed out";
+ break;
+
+ case WSAECONNREFUSED:
+ msg = "Connection refused";
+ break;
+
+ case WSAELOOP:
+ msg = "Too many levels of symbolic links";
+ break;
+
+ case WSAENAMETOOLONG:
+ msg = "File name too long";
+ break;
+
+ case WSAEHOSTDOWN:
+ msg = "Host is down";
+ break;
+
+ case WSAEHOSTUNREACH:
+ msg = "No route to host";
+ break;
+
+ case WSAENOTEMPTY:
+ msg = "Directory not empty";
+ break;
+
+ case WSAEPROCLIM:
+ msg = "Too many processes";
+ break;
+
+ case WSAEUSERS:
+ msg = "Too many users";
+ break;
+
+ case WSAEDQUOT:
+ msg = "Disc quota exceeded";
+ break;
+
+ case WSAESTALE:
+ msg = "Stale NFS file handle";
+ break;
+
+ case WSAEREMOTE:
+ msg = "Too many levels of remote in path";
+ break;
+
+ case WSASYSNOTREADY:
+ msg = "Network system is unavailable";
+ break;
+
+ case WSAVERNOTSUPPORTED:
+ msg = "Winsock version out of range";
+ break;
+
+ case WSANOTINITIALISED:
+ msg = "WSAStartup not yet called";
+ break;
+
+ case WSAEDISCON:
+ msg = "Graceful shutdown in progress";
+ break;
+/*
+ case WSAHOST_NOT_FOUND:
+ msg = "Host not found";
+ break;
+
+ case WSANO_DATA:
+ msg = "No host data of that type was found";
+ break;
+*/
+ default:
+ msg = NULL;
+ break;
+ }
+ return (msg);
+}
+
+/*
+ * These error messages are more informative about CryptAPI Errors than the
+ * standard error messages
+ */
+
+char *
+GetCryptErrorMessage(int errval) {
+ char *msg;
+
+ switch (errval) {
+
+ case NTE_BAD_FLAGS:
+ msg = "The dwFlags parameter has an illegal value.";
+ break;
+ case NTE_BAD_KEYSET:
+ msg = "The Registry entry for the key container "
+ "could not be opened and may not exist.";
+ break;
+ case NTE_BAD_KEYSET_PARAM:
+ msg = "The pszContainer or pszProvider parameter "
+ "is set to an illegal value.";
+ break;
+ case NTE_BAD_PROV_TYPE:
+ msg = "The value of the dwProvType parameter is out "
+ "of range. All provider types must be from "
+ "1 to 999, inclusive.";
+ break;
+ case NTE_BAD_SIGNATURE:
+ msg = "The provider DLL signature did not verify "
+ "correctly. Either the DLL or the digital "
+ "signature has been tampered with.";
+ break;
+ case NTE_EXISTS:
+ msg = "The dwFlags parameter is CRYPT_NEWKEYSET, but the key"
+ " container already exists.";
+ break;
+ case NTE_KEYSET_ENTRY_BAD:
+ msg = "The Registry entry for the pszContainer key container "
+ "was found (in the HKEY_CURRENT_USER window), but is "
+ "corrupt. See the section System Administration for "
+ " etails about CryptoAPI's Registry usage.";
+ break;
+ case NTE_KEYSET_NOT_DEF:
+ msg = "No Registry entry exists in the HKEY_CURRENT_USER "
+ "window for the key container specified by "
+ "pszContainer.";
+ break;
+ case NTE_NO_MEMORY:
+ msg = "The CSP ran out of memory during the operation.";
+ break;
+ case NTE_PROV_DLL_NOT_FOUND:
+ msg = "The provider DLL file does not exist or is not on the "
+ "current path.";
+ break;
+ case NTE_PROV_TYPE_ENTRY_BAD:
+ msg = "The Registry entry for the provider type specified by "
+ "dwProvType is corrupt. This error may relate to "
+ "either the user default CSP list or the machine "
+ "default CSP list. See the section System "
+ "Administration for details about CryptoAPI's "
+ "Registry usage.";
+ break;
+ case NTE_PROV_TYPE_NO_MATCH:
+ msg = "The provider type specified by dwProvType does not "
+ "match the provider type found in the Registry. Note "
+ "that this error can only occur when pszProvider "
+ "specifies an actual CSP name.";
+ break;
+ case NTE_PROV_TYPE_NOT_DEF:
+ msg = "No Registry entry exists for the provider type "
+ "specified by dwProvType.";
+ break;
+ case NTE_PROVIDER_DLL_FAIL:
+ msg = "The provider DLL file could not be loaded, and "
+ "may not exist. If it exists, then the file is "
+ "not a valid DLL.";
+ break;
+ case NTE_SIGNATURE_FILE_BAD:
+ msg = "An error occurred while loading the DLL file image, "
+ "prior to verifying its signature.";
+ break;
+
+ default:
+ msg = NULL;
+ break;
+ }
+ return msg;
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2001 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* From BIND 9 lib/isc/win32/: syslog.c,v 1.6 2002/08/03 01:34:14 mayer */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <windows.h>
+#include <string.h>
+#include <stdlib.h>
+#include <syslog.h>
+
+#include <messages.h>
+
+static HANDLE hAppLog = NULL;
+static FILE *log_stream;
+static int debug_level = 0;
+static char *progname = "NTP";
+static int logmask = 0;
+
+static struct dsn_c_pvt_sfnt {
+ int val;
+ const char *strval;
+} facilities[] = {
+ { LOG_KERN, "kern" },
+ { LOG_USER, "user" },
+ { LOG_MAIL, "mail" },
+ { LOG_DAEMON, "daemon" },
+ { LOG_AUTH, "auth" },
+ { LOG_SYSLOG, "syslog" },
+ { LOG_LPR, "lpr" },
+#ifdef LOG_NEWS
+ { LOG_NEWS, "news" },
+#endif
+#ifdef LOG_UUCP
+ { LOG_UUCP, "uucp" },
+#endif
+#ifdef LOG_CRON
+ { LOG_CRON, "cron" },
+#endif
+#ifdef LOG_AUTHPRIV
+ { LOG_AUTHPRIV, "authpriv" },
+#endif
+#ifdef LOG_FTP
+ { LOG_FTP, "ftp" },
+#endif
+ { LOG_LOCAL0, "local0"},
+ { LOG_LOCAL1, "local1"},
+ { LOG_LOCAL2, "local2"},
+ { LOG_LOCAL3, "local3"},
+ { LOG_LOCAL4, "local4"},
+ { LOG_LOCAL5, "local5"},
+ { LOG_LOCAL6, "local6"},
+ { LOG_LOCAL7, "local7"},
+ { 0, NULL }
+};
+
+#if 0
+BOOL
+isc_syslog_facilityfromstring(const char *str, int *facilityp) {
+ int i;
+
+ REQUIRE(str != NULL);
+ REQUIRE(facilityp != NULL);
+
+ for (i = 0 ; facilities[i].strval != NULL ; i++) {
+ if (strcasecmp(facilities[i].strval, str) == 0) {
+ *facilityp = facilities[i].val;
+ return (TRUE);
+ }
+ }
+ return (FALSE);
+}
+#endif
+/*
+ * Log to the NT Event Log
+ */
+void
+syslog(int level, const char *fmt, ...) {
+ va_list ap;
+ char buf[1024];
+ char *str[1];
+
+ str[0] = buf;
+
+ va_start(ap, fmt);
+ vsprintf(buf, fmt, ap);
+ va_end(ap);
+
+ /* Make sure that the channel is open to write the event */
+ if (hAppLog == NULL) {
+ openlog(progname, LOG_PID);
+ }
+ switch (level) {
+ case LOG_INFO:
+ case LOG_NOTICE:
+ case LOG_DEBUG:
+ ReportEvent(hAppLog, EVENTLOG_INFORMATION_TYPE, 0,
+ NTP_INFO, NULL, 1, 0, str, NULL);
+ break;
+ case LOG_WARNING:
+ ReportEvent(hAppLog, EVENTLOG_WARNING_TYPE, 0,
+ NTP_WARNING, NULL, 1, 0, str, NULL);
+ break;
+ default:
+ ReportEvent(hAppLog, EVENTLOG_ERROR_TYPE, 0,
+ NTP_ERROR, NULL, 1, 0, str, NULL);
+ break;
+ }
+}
+
+/*
+ * Initialize event logging
+ */
+void
+openlog(const char *name, int flags, ...) {
+ /* Get a handle to the Application event log */
+ hAppLog = RegisterEventSource(NULL, progname);
+}
+
+/*
+ * Close the Handle to the application Event Log
+ * We don't care whether or not we succeeded so ignore return values
+ * In fact if we failed then we would have nowhere to put the message
+ */
+void
+closelog() {
+ DeregisterEventSource(hAppLog);
+}
+
+/*
+ * Keep event logging synced with the current debug level
+ */
+void
+ModifyLogLevel(int level) {
+ debug_level = level;
+}
+/*
+ * Set the log priority mask to the given value.
+ * Return the previous priority mask
+ * Note that this setting is ignored in Win32
+ */
+int
+setlogmask(int maskpri) {
+ int temp = logmask;
+ logmask = maskpri;
+ return (temp);
+}
+
+/*
+ * Initialize logging for the port section of libbind.
+ * Piggyback onto stream given.
+ */
+void
+InitNTLogging(FILE *stream, int debug) {
+ log_stream = stream;
+ ModifyLogLevel(debug);
+}
+/*
+ * This function is for reporting errors to the application
+ * event log in case the regular syslog is not available
+ * mainly during startup. It should not be used under normal
+ * circumstances.
+ */
+void
+NTReportError(const char *name, const char *str) {
+ HANDLE hNTAppLog = NULL;
+ const char *buf[1];
+
+ buf[0] = str;
+
+ hNTAppLog = RegisterEventSource(NULL, name);
+
+ ReportEvent(hNTAppLog, EVENTLOG_ERROR_TYPE, 0,
+ NTP_ERROR, NULL, 1, 0, buf, NULL);
+
+ DeregisterEventSource(hNTAppLog);
+}
\ No newline at end of file
struct interface *inter,
struct pkt *pkt,
int len,
- struct sockaddr_in* dest)
+ struct sockaddr_storage* dest)
{
transmitbuf *buff = NULL;
DWORD Result = ERROR_SUCCESS;
# Begin Source File
SOURCE=..\..\..\ntpd\ntp_io.c
+
+!IF "$(CFG)" == "ntpd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "ntpd - Win32 Debug"
+
+# SUBTRACT CPP /FA<none>
+
+!ENDIF
+
# End Source File
# Begin Source File
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 kernel32.lib user32.lib ws2_32.lib /nologo /subsystem:console /machine:I386 /out:"../bin/Release/ntpdc.exe"
+# ADD LINK32 kernel32.lib user32.lib ws2_32.lib advapi32.lib /nologo /subsystem:console /machine:I386 /out:"../bin/Release/ntpdc.exe"
!ELSEIF "$(CFG)" == "ntpdc - Win32 Debug"
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../bin/Debug/ntpdc.exe" /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib ws2_32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../bin/Debug/ntpdc.exe" /pdbtype:sept
!ENDIF
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 kernel32.lib user32.lib ws2_32.lib /nologo /subsystem:console /machine:I386 /out:"../bin/Release/ntpq.exe"
+# ADD LINK32 kernel32.lib user32.lib ws2_32.lib advapi32.lib /nologo /subsystem:console /machine:I386 /out:"../bin/Release/ntpq.exe"
!ELSEIF "$(CFG)" == "ntpq - Win32 Debug"
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../bin/Debug/ntpq.exe" /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib ws2_32.lib advapi32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../bin/Debug/ntpq.exe" /pdbtype:sept
!ENDIF