]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Add support for SOCKET type to support Win32. Fix casting issues. Update
authorDanny Mayer <mayer@ntp.org>
Mon, 25 Nov 2002 04:20:38 +0000 (23:20 -0500)
committerDanny Mayer <mayer@ntp.org>
Mon, 25 Nov 2002 04:20:38 +0000 (23:20 -0500)
Macros. Fix if statements to not also assign. Miscellaneous fixes.

bk: 3de1a516HBQVFxIX3agEEx4f6tkwOg

44 files changed:
include/interfaceiter.h [new file with mode: 0644]
include/ntp.h
include/ntp_config.h
include/ntp_machine.h
include/ntp_refclock.h
include/ntp_request.h
include/ntp_rfc2553.h
include/ntpd.h
include/recvbuff.h
libntp/msyslog.c
libntp/ntp_rfc2553.c
libntp/socktohost.c
libntp/systime.c
ntpd/cmd_args.c
ntpd/ntp_config.c
ntpd/ntp_control.c
ntpd/ntp_filegen.c
ntpd/ntp_intres.c
ntpd/ntp_io.c
ntpd/ntp_peer.c
ntpd/ntp_proto.c
ntpd/ntp_refclock.c
ntpd/ntp_request.c
ntpd/ntpd.c
ntpd/refclock_dumbclock.c
ntpd/refclock_hopfpci.c
ntpd/refclock_hopfser.c
ntpd/refclock_nmea.c
ntpdate/ntpdate.c
ntpdc/ntpdc.c
ntpdc/ntpdc_ops.c
ntpq/ntpq.c
ntpq/ntpq_ops.c
ports/winnt/include/config.h
ports/winnt/include/ntp_iocompletionport.h
ports/winnt/include/syslog.h
ports/winnt/libntp/interfaceiter.c [new file with mode: 0644]
ports/winnt/libntp/libntp.dsp
ports/winnt/libntp/strerror.c [new file with mode: 0644]
ports/winnt/libntp/syslog.c [new file with mode: 0644]
ports/winnt/ntpd/ntp_iocompletionport.c
ports/winnt/ntpd/ntpd.dsp
ports/winnt/ntpdc/ntpdc.dsp
ports/winnt/ntpq/ntpq.dsp

diff --git a/include/interfaceiter.h b/include/interfaceiter.h
new file mode 100644 (file)
index 0000000..a813225
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * 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 */
index 2206571f0e9be4c3920d252fc28c71a901ccf21c..9e3b7bb32b0c9385b3aa435bd356a29985551c3f 100644 (file)
@@ -169,17 +169,15 @@ typedef char s_char;
  * 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 */
index 0e56dd87ac8510b9a18795ece8ff6265aa32a3bb..3a022ef2c9e1ef532b1ba671eb475c0e4df38032 100644 (file)
@@ -7,6 +7,7 @@
 # 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 */
 
index 2da8133e3c615a2d9aa5520fe3f67e0d476b075b..ef1e16f57b05226c10e992d6e255c64e58cd6916 100644 (file)
@@ -234,6 +234,18 @@ typedef unsigned long u_long;
 
 #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
  */
@@ -250,6 +262,7 @@ typedef unsigned long u_long;
 # 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
@@ -259,6 +272,7 @@ typedef unsigned long u_long;
 # define unlink _unlink
 # define fileno _fileno
 # define write _write
+# define vsnprintf _vsnprintf
 #ifndef close
 # define close _close
 #endif
@@ -534,7 +548,7 @@ extern char *strdup(const char *);
 #endif
 
 #ifndef HAVE_TIMEGM
-extern time_t  timegm          P((struct tm *));
+extern time_t  timegm          P((struct tm *));
 #endif
 
 #ifdef HAVE_SYSV_TTYS
index 8498ed426a8a9f829be51f004f2600e34b868543..5e33a8ce25a137b7aadcb29171299adf03bac7f8 100644 (file)
@@ -129,11 +129,7 @@ struct refclockio {
                                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 */
 };
 
index 3b36918438457982d15dab22f9b7fa24bc07cd7b..6fa831cdeb49fcdca81ba3f3176b93d0adb7e59d 100644 (file)
@@ -207,7 +207,7 @@ struct resp_pkt {
                                |((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)))
 
 
index 6aee848816528cf7872e59fc9c12d4b64db0c8ec..b9160f9d538de9614b3bb43037f631cf95c56924 100644 (file)
@@ -93,6 +93,9 @@ typedef struct u_int64_t { u_int32 val[2]; } u_int64_t;
 /*
  * IPv6 address
  */
+#ifdef SYS_WINNT
+#define in6_addr in_addr6
+#else
 struct in6_addr {
        union {
                u_int8_t   __u6_addr8[16];
@@ -102,16 +105,23 @@ struct in6_addr {
 };
 
 #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)*/
@@ -124,6 +134,7 @@ struct sockaddr_in6 {
        struct in6_addr sin6_addr;      /* IP6 address */
        u_int32_t       sin6_scope_id;  /* scope zone index */
 };
+#endif
 
 /*
  * Unspecified
index 4f4a4ffd1f291e12f11ff6e14169c61b3c193e8c..0a2e3ae1935eab1c030321a5e6a36599f56fdec9 100644 (file)
@@ -18,10 +18,6 @@ void service_main    (DWORD, LPTSTR *);
 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 */
@@ -124,7 +120,7 @@ extern      void    init_peer       P((void));
 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 *));
@@ -279,7 +275,7 @@ extern struct interface *loopback_interface; /* loopback interface */
  * 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) */
@@ -306,6 +302,7 @@ extern int  allow_step;             /* allow step correction */
 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
index a1fd9a6f5c3aeed605f8506cabdd1db931e33469..4fde7f19250a81ed56984ee61b8e79e7da1358ac 100644 (file)
@@ -63,11 +63,7 @@ struct recvbuf {
        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 */
index 437bfa52a33b44cf1c6df321728de2ff8e484e94..5a96749c8272696af90aeb78bbd40c72793a045f 100644 (file)
@@ -24,6 +24,7 @@
 #include "ntp_stdlib.h"
 
 #ifdef SYS_WINNT
+# include <stdarg.h>
 # include "..\ports\winnt\libntp\log.h"
 # include "..\ports\winnt\libntp\messages.h"
 #endif
@@ -35,13 +36,9 @@ FILE *syslog_file = NULL;
 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;
 
@@ -60,13 +57,18 @@ void msyslog(int level, const char *fmt, ...)
 #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)
@@ -78,7 +80,6 @@ void msyslog(int level, const char *fmt, ...)
        fmt = va_arg(ap, char *);
 #endif
 
-       olderrno = errno;
        n = nfmt;
        f = fmt;
        while ((c = *f++) != '\0' && c != '\n' && n < &nfmt[252]) {
@@ -92,20 +93,7 @@ void msyslog(int level, const char *fmt, ...)
                        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);
@@ -120,27 +108,7 @@ void msyslog(int level, const char *fmt, ...)
        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*/
        {
@@ -148,7 +116,7 @@ void msyslog(int level, const char *fmt, ...)
                        : 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
index 132f3d1b5416334fae389394a1fbe6d5229308dc..9248f2c1fb05fd164b96f08e94a550633a9d4806 100644 (file)
@@ -85,7 +85,7 @@
 
 #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.
  */
@@ -222,8 +222,7 @@ getnameinfo (const struct sockaddr *sa, u_int salen, char *host,
 }
 
 char *
-gai_strerror(ecode)
-       int ecode;
+gai_strerror(int ecode)
 {
        if (ecode < 0 || ecode > EAI_MAX)
                ecode = EAI_MAX;
index ccc7c8522eeb3c799139012bc7fc883ad9f511a7..7a3b30f63d6c812c047607a34293949252146b1b 100644 (file)
@@ -25,7 +25,7 @@ socktohost(
 
        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;
index 146fb8ff4ec87a12828b22ef093f3260c2f8f3e4..5a589ab355ce4f4b4b71ebb357f9f2ab09a7b12c 100644 (file)
@@ -231,7 +231,7 @@ step_systime(
                        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);
        }
index 3d7ab48d63ce1dfd8606b1b5965021e1e12899e0..c1a428b33fa46ff8a3df685137a0706119a30dcb 100644 (file)
@@ -88,7 +88,12 @@ getstartup(
                        {
                                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);
@@ -295,7 +300,7 @@ getCmdOpts(
                    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':
index af9fb134ad87f1c457c2d5d53cf3b56f01207715..98ea88acc9c309c146614ed0abe7b120513354e3 100644 (file)
@@ -421,7 +421,7 @@ static      void save_resolve P((char *, int, int, int, int, u_int, int,
     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 */
 
@@ -1101,7 +1101,7 @@ getconfig(
 
                    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;
@@ -1691,12 +1691,12 @@ getconfig(
                                        "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;
 
@@ -2129,7 +2129,7 @@ getnetnum(
 }
 
 
-#if !defined(VMS)
+#if !defined(VMS) && !defined(SYS_WINNT)
 /*
  * catchchild - receive the resolver's exit status
  */
@@ -2173,7 +2173,6 @@ save_resolve(
 #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;
@@ -2367,13 +2366,14 @@ do_resolve_internal(void)
                 */
                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();
                }
index 564ddea9225e4781f3f9784a936b53bd9df3170d..d85cb6de2c4e5a18a00c01985ff74c839d5854a5 100644 (file)
@@ -2540,7 +2540,7 @@ ctlsettrap(
        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;
@@ -2853,7 +2853,8 @@ set_var(
        if (!data || !size)
                return;
 
-       if ((k = *kv)) {
+       k = *kv;
+       if (k != NULL) {
                while (!(k->flags & EOV)) {
                        s = data;
                        t = k->text;
index bcf3f9c19cd186b12c3f22c86974d653cc7fe793..36310b2f655be72dd36202c00223357be50e5961 100644 (file)
@@ -316,7 +316,7 @@ filegen_setup(
       
            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);
@@ -378,8 +378,8 @@ filegen_config(
                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
index 92c92a5805bcc61a789479cd6af0504e411b35e9..d2954dbdfbfa51e177b9d44715a55893a5999f6d 100644 (file)
@@ -125,11 +125,7 @@ static     int resolve_value;      /* next value of resolve timer */
 /*
  * 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 */
 
index 1960309b3560d2a02fb1f9a96aeeaef29db8a2d3..aee98db3e318f9b4aeea714619799338239e7827 100644 (file)
@@ -68,6 +68,9 @@ extern int listen_to_virtual_ips;
 
 #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) */
@@ -110,7 +113,9 @@ struct ifconf {
 #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
@@ -167,10 +172,10 @@ static    struct refclockio *refio;
  * 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 *));
@@ -250,8 +255,12 @@ create_sockets(
 # 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
@@ -262,19 +271,25 @@ create_sockets(
        /*
         * 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;
@@ -283,7 +298,7 @@ create_sockets(
        inter_list[1].notsent = 0;
        inter_list[1].flags = 0;
        any6_interface = &inter_list[1];
-
+#endif
 
 #if _BSDI_VERSION >= 199510
 #if    _BSDI_VERSION >= 199701
@@ -292,7 +307,11 @@ create_sockets(
                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)
@@ -301,7 +320,11 @@ create_sockets(
                    exit(1);
            }
 
+#ifdef HAVE_IPV6
        i = 2;
+#else
+       i = 1;
+#endif
 
        for (ifap = ifaddrs, lp = ifap + num_if; ifap < lp; ifap++)
 #endif
@@ -438,7 +461,11 @@ create_sockets(
                exit(1);
        }
 
+#ifdef HAVE_IPV6
        i = 2;
+#else
+       i = 1;
+#endif
 # if !defined(SYS_WINNT)
        lifc.lifc_len = sizeof(buf);
 # endif
@@ -490,8 +517,13 @@ create_sockets(
                        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)
@@ -526,16 +558,15 @@ create_sockets(
                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");
@@ -625,7 +656,8 @@ create_sockets(
                (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
@@ -651,7 +683,7 @@ create_sockets(
                        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) {
@@ -675,7 +707,11 @@ create_sockets(
                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 */
@@ -698,7 +734,7 @@ create_sockets(
                if (i > MAXINTERFACES)
                    break;
        }
-       closesocket(vs);
+       close_socket(vs);
 #endif /* _BSDI_VERSION >= 199510 */
 
        ninterfaces = i;
@@ -733,7 +769,9 @@ create_sockets(
        /*
         * 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 */
 
        /*
@@ -874,7 +912,7 @@ io_multicast_add(
                        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);
@@ -923,7 +961,47 @@ io_multicast_add(
                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
@@ -984,8 +1062,10 @@ io_multicast_del(
 
                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;
                }
 
                /*
@@ -1009,8 +1089,8 @@ io_multicast_del(
                                /* 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
                        {
@@ -1058,8 +1138,8 @@ io_multicast_del(
                                /* 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
                        {
@@ -1092,6 +1172,9 @@ open_socket(
        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)
@@ -1100,27 +1183,35 @@ open_socket(
 
 #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 */
@@ -1178,15 +1269,22 @@ open_socket(
                                 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
@@ -1422,14 +1520,16 @@ sendpkt(
                * 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;
                }
@@ -1938,15 +2038,27 @@ findinterface(
                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);
index e8da874812f5e37322f047ccc959e959e15b7288..4bebb4a7a0c6845a88dc80a4d493c79aa87030c0 100644 (file)
@@ -500,13 +500,13 @@ peer_config(
         */
        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");
@@ -599,7 +599,7 @@ newpeer(
        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)
index cf8a33f689704b71f8927790d8d6f038c8901bde..f3d06ba6d8d1ae256f97be79d7b9d50b1dde8371 100644 (file)
@@ -1065,7 +1065,7 @@ process_packet(
        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
@@ -1304,7 +1304,7 @@ clock_update(void)
         * 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
@@ -1354,7 +1354,7 @@ poll_update(
                else if (hpoll < peer->minpoll)
                        peer->hpoll = peer->minpoll;
                else
-                       peer->hpoll = hpoll;
+                       peer->hpoll = (u_char) hpoll;
        }
 
        /*
@@ -1392,12 +1392,12 @@ poll_update(
        } 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);
        }
@@ -1432,7 +1432,7 @@ peer_clear(
        char    *ident                  /* tally lights */
        )
 {
-       int     i;
+       u_char  i;
 
        /*
         * If cryptographic credentials have been acquired, toss them to
@@ -1557,7 +1557,7 @@ clock_filter(
        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
@@ -1609,7 +1609,7 @@ clock_filter(
         */
        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;
@@ -2104,8 +2104,8 @@ clock_select(void)
         */
        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)
@@ -2935,7 +2935,7 @@ init_proto(void)
        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
index 849d203abb1dc3ba5888242a4255d4791073c368..309b344490dc671c912aeb021fda426bebc07a99 100644 (file)
@@ -108,7 +108,8 @@ refclock_report(
 {
        struct refclockproc *pp;
 
-       if (!(pp = peer->procptr))
+       pp = peer->procptr;
+       if (pp == NULL)
                return;
        if (code == CEVNT_BADREPLY)
                pp->badformat++;
@@ -117,8 +118,8 @@ refclock_report(
        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)",
@@ -212,7 +213,8 @@ refclock_newpeer(
        /*
         * 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;
@@ -222,7 +224,7 @@ refclock_newpeer(
         * 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;
@@ -605,7 +607,7 @@ refclock_gtlin(
         * 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;
 
@@ -984,7 +986,8 @@ refclock_control(
        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;
@@ -1090,7 +1093,8 @@ refclock_buginfo(
        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;
 
index adbf5885413ed27e4826efd9f6cc7a2d00a658b0..f9180969952735b177e21a75231dc816d67a6344 100644 (file)
@@ -867,9 +867,9 @@ peer_info (
                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);
index 441369efb9b366e0aa66c0e8a168854e8147e10c..30c386074bd4405310c5372975386b0a4c5d9749 100644 (file)
@@ -146,6 +146,11 @@ int priority_done = 2;             /* 0 - Set priority */
  */
 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.
  */
@@ -177,8 +182,10 @@ static     RETSIGTYPE      finish          P((int));
 #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 */
@@ -530,8 +537,9 @@ service_main(
        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;
@@ -570,7 +578,7 @@ service_main(
        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);
@@ -852,7 +860,7 @@ service_main(
        {
 # if !defined(HAVE_SIGNALED_IO) 
                extern fd_set activefds;
-               extern SOCKET maxactivefd;
+               extern int maxactivefd;
 
                fd_set rdfdes;
                int nfound;
@@ -948,7 +956,9 @@ service_main(
                 */
        }
        exit(1); /* unreachable */
+#ifndef SYS_WINNT
        return 1;               /* DEC OSF cc braindamage */
+#endif
 }
 
 
@@ -981,6 +991,7 @@ finish(
 
 
 #ifdef DEBUG
+#ifndef SYS_WINNT
 /*
  * moredebug - increase debugging verbosity
  */
@@ -1016,6 +1027,7 @@ lessdebug(
        }
        errno = saved_errno;
 }
+#endif
 #else /* not DEBUG */
 /*
  * no_debug - We don't do the debug here.
index fd7030c492fc2a357a50483356b48f7c94c270b6..2788649ac3a7872e242e3f2eb415adf0a7ac8233 100644 (file)
@@ -119,14 +119,15 @@ dumbclock_start(
        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);
        }
@@ -223,7 +224,7 @@ dumbclock_receive(
                    up->tcswitch = 0;
                return;
        }
-       pp->lencode = temp;
+       pp->lencode = (u_short)temp;
        pp->lastrec = up->laststamp;
        up->laststamp = trtmp;
        up->tcswitch = 1;
@@ -337,7 +338,7 @@ dumbclock_receive(
        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
index 132d5eea284386064bb2d0d60236e51c25ce340f..a384db83d1182e1673a2cd7d02c9fa83b73c0c29 100644 (file)
@@ -149,7 +149,7 @@ hopfpci_start(
        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);
@@ -231,7 +231,7 @@ hopfpci_poll(
        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);
 
index 1a36ce870200b4bd0a9ff7d00edc1c97fd2cccb9..b1f5e0f06b3df95c161437acc30974a396840b23 100644 (file)
@@ -239,7 +239,7 @@ hopfserial_receive (
 
        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;
index a719ff8fd9a9d920711d4a24d806c950bb297ca1..28d62630d17a8730e1c9570e99fbd5b0a17f418f 100644 (file)
@@ -152,14 +152,15 @@ nmea_start(
         */
        (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);
        }
@@ -385,7 +386,7 @@ nmea_receive(
        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
index 21234ffda7e6e108b1fe83fe9f3d0dcd73b0e835..0f2ca9e22ee3b6657d23543529872cb81f655d95 100644 (file)
@@ -109,7 +109,10 @@ volatile int debug = 0;
  * 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
@@ -936,7 +939,7 @@ server_data(
        u_fp e
        )
 {
-       register int i;
+       u_short i;
 
        i = server->filter_nextpt;
        if (i < NTP_SHIFT) {
@@ -944,7 +947,7 @@ server_data(
                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);
        }
 }
 
@@ -1780,7 +1783,7 @@ sendpkt(
 {
         int i;
        int cc;
-        int sock = 0;
+        SOCKET sock = 0;
 
 #ifdef SYS_WINNT
        DWORD err;
index f0236b36427d5963248fc4f4c0f692ea8d0b56ea..5b12d53af9b57cd6eebe92f6ccfe8abee4e233c2 100644 (file)
@@ -161,9 +161,10 @@ static     struct timeval tvout = { DEFTIMEOUT, 0 };       /* time out for reads */
 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;
 
@@ -1440,10 +1441,10 @@ help(
                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);
@@ -1864,7 +1865,7 @@ getkeyid(
        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)
index 7ceb16c0f33351778f5712f11df1b7668781ec98..037c7ce59ac64acaeebc48f77dcc2b63b9461194 100644 (file)
@@ -660,7 +660,7 @@ again:
                        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);
        }
@@ -733,7 +733,7 @@ again:
                        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);
        }
@@ -1762,6 +1762,13 @@ do_restrict(
        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);
index 603ad4973be3064ac616d6b125b374cf15151a95..c07cfaba4fbf177b875cf74c8a7903036eb206f2 100644 (file)
@@ -365,11 +365,8 @@ char currenthost[LENHOSTNAME];                     /* current host name */
 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 */
@@ -493,6 +490,7 @@ ntpqmain(
        int errflg = 0;
        extern int ntp_optind;
        extern char *ntp_optarg;
+       int ai_fam_templ;
 
 #ifdef NO_MAIN_ALLOWED
     clear_globals();
@@ -673,18 +671,12 @@ openhost(
                        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
@@ -1119,7 +1111,7 @@ sendrequest(
         * 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);
@@ -1743,10 +1735,10 @@ rtdatetolfp(
                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++ != '-')
@@ -1761,25 +1753,25 @@ rtdatetolfp(
                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');
        }
 
        /*
@@ -1792,26 +1784,26 @@ rtdatetolfp(
 
        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');
        }
 
        /*
@@ -1990,10 +1982,10 @@ help(
                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);
@@ -2498,7 +2490,7 @@ getkeyid(
        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)
@@ -2546,7 +2538,7 @@ atoascii(
 
                if (c < ' ') {
                        *ocp++ = '^';
-                       *ocp++ = c + '@';
+                       *ocp++ = (u_char)(c + '@');
                } else if (c == 0177) {
                        *ocp++ = '^';
                        *ocp++ = '?';
@@ -2971,7 +2963,7 @@ cookedprint(
        register int varid;
        char *name;
        char *value;
-       int output_raw;
+       char output_raw;
        int fmt;
        struct ctl_var *varlist;
        l_fp lfp;
index dcc61931a47dba17bbb93f68d27fbd83343483fe..16b75f364cac0d5ce8f42fa7d1d442494ebf6a84 100644 (file)
@@ -1245,11 +1245,11 @@ decodeaddrtype(
        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;
index b90463116e16579c83847971d1359f0c2648c7ae..04271f7958364ab9ac08ca2596e1b08ecc57b965 100644 (file)
@@ -85,6 +85,7 @@ int NT_set_process_priority(void);    /* Define this function */
 # define HAVE_NO_NICE
 # define TIME_WITH_SYS_TIME
 # define HAVE_IO_COMPLETION_PORT
+# define HAVE_SOCKADDR_IN6
 //# define volatile
 # define STDC_HEADERS
 
index 53345b32d7a336f4df446cc9ed6fe9cfa519fb5d..a7282000f439adf6701d004fd98d82ddd5d2af07 100644 (file)
@@ -22,7 +22,7 @@ extern        int     io_completion_port_add_clock_io (struct refclockio * /*rio */);
 
 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);
 
index e731c0869e6bc0cb85ec4f32f36a6cc3692e11d5..5cbf30a00a13acafb503d5a37d966d35e033963b 100644 (file)
@@ -1,18 +1,82 @@
-/**************************************************************
- * 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
diff --git a/ports/winnt/libntp/interfaceiter.c b/ports/winnt/libntp/interfaceiter.c
new file mode 100644 (file)
index 0000000..cfea7ec
--- /dev/null
@@ -0,0 +1,380 @@
+/*
+ * 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;
+}
+
index 2781ca76be194a34a24100f895814d5c7fbef5e5..8703b14cb74636d4e86c21dda9b74af2bf689110 100644 (file)
@@ -269,6 +269,10 @@ SOURCE=..\..\..\libntp\netof.c
 # 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
@@ -301,11 +305,23 @@ SOURCE=.\SetSystemTime.c
 # 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
 
diff --git a/ports/winnt/libntp/strerror.c b/ports/winnt/libntp/strerror.c
new file mode 100644 (file)
index 0000000..58d4c65
--- /dev/null
@@ -0,0 +1,440 @@
+/*
+ * 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;
+}
+
diff --git a/ports/winnt/libntp/syslog.c b/ports/winnt/libntp/syslog.c
new file mode 100644 (file)
index 0000000..cbb2833
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * 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
index e75b828936fe4e4e932feef5fc2a584416aa7a91..b5d8ede258e7243432970261edd8cd284bc0d0fe 100644 (file)
@@ -347,7 +347,7 @@ io_completion_port_sendto(
        struct interface *inter,        
        struct pkt *pkt,        
        int len, 
-       struct sockaddr_in* dest)
+       struct sockaddr_storage* dest)
 {
        transmitbuf *buff = NULL;
        DWORD Result = ERROR_SUCCESS;
index 28bef019c9b9c94e845c766afdf5563f62daa427..70b62a99a700f6b50df605303b57a13a0ccca00a 100644 (file)
@@ -120,6 +120,15 @@ SOURCE=..\..\..\ntpd\ntp_intres.c
 # 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
 
index 7801db410ecfd5a69c8713a55b9f7d589e3b5497..0b05129c9bd6a500b0a7c301ba1544c50f683049 100644 (file)
@@ -50,7 +50,7 @@ BSC32=bscmake.exe
 # 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"
 
@@ -74,7 +74,7 @@ BSC32=bscmake.exe
 # 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 
 
index 771017040b8508221df6d9f873cb84c4c06bf679..bff49c0456828d644d573dcbf905b275b938094c 100644 (file)
@@ -50,7 +50,7 @@ BSC32=bscmake.exe
 # 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"
 
@@ -74,7 +74,7 @@ BSC32=bscmake.exe
 # 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