From: Danny Mayer Date: Sun, 27 Dec 2009 20:52:30 +0000 (+0000) Subject: [Bug 1442] Move functions into libntp files X-Git-Tag: NTP_4_2_7P6~5^2~5^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6983af925f7e080f258e84c25cdcf82f289a2049;p=thirdparty%2Fntp.git [Bug 1442] Move functions into libntp files bk: 4b37c90eBMU2RV2Ls0tyT_ZsaoEA2Q --- diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h index d67968b3b..e44c5a3a2 100644 --- a/ports/winnt/include/config.h +++ b/ports/winnt/include/config.h @@ -173,19 +173,6 @@ typedef int socklen_t; #define SO_EXCLUSIVEADDRUSE ((int)(~SO_REUSEADDR)) #endif -/* - * Define this macro to control the behavior of connection - * resets on UDP sockets. See Microsoft KnowledgeBase Article Q263823 - * for details. - * Based on that article, it is surprising that a much newer winsock2.h - * does not define SIO_UDP_CONNRESET (the one that comes with VS 2008). - * NOTE: This requires that Windows 2000 systems install Service Pack 2 - * or later. - */ -#ifndef SIO_UDP_CONNRESET -#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12) -#endif - #if defined _MSC_VER && _MSC_VER < 1400 /* * Use 32-bit time definitions for versions prior to VS 2005 diff --git a/ports/winnt/include/termios.h b/ports/winnt/include/termios.h index 8c241436f..91be2e5ad 100644 --- a/ports/winnt/include/termios.h +++ b/ports/winnt/include/termios.h @@ -1,5 +1,5 @@ -#ifndef WIN32_IO_H -#define WIN32_IO_H +#ifndef _TERMIOS_H +#define _TERMIOS_H /* Flag definitions for compatibility * ================================== @@ -213,4 +213,4 @@ extern int ioctl (int, int, int *); extern int tcsetattr (int, int, const struct termios *); extern int tcgetattr (int, struct termios *); -#endif /* defined WIN32_IO_H */ +#endif diff --git a/ports/winnt/include/win32_io.h b/ports/winnt/include/win32_io.h new file mode 100644 index 000000000..129c8ff2a --- /dev/null +++ b/ports/winnt/include/win32_io.h @@ -0,0 +1,8 @@ +#ifndef WIN32_IO_H +#define WIN32_IO_H + +extern void InitSockets(void); +void connection_reset_fix(SOCKET fd, sockaddr_u *addr) + +#endif /* defined WIN32_IO_H */ +; diff --git a/ports/winnt/libntp/setpriority.c b/ports/winnt/libntp/setpriority.c index 2e648f0ad..c57269ad3 100644 --- a/ports/winnt/libntp/setpriority.c +++ b/ports/winnt/libntp/setpriority.c @@ -1,8 +1,6 @@ #include -#include #include #include /* our private version */ -#include "ntp_machine.h" #include "ntp_stdlib.h" #include "ntp_syslog.h" #include "ntp_debug.h" @@ -77,31 +75,3 @@ int setpriority( return 0; } - -/* - * InitSockets -- once known as Win32InitSockets() - * - * This doesn't have much to do with setpriority but we - * want the routine in libntp and this is a convenient - * existing Windows-only libntp source file. - */ -void -InitSockets( - void - ) -{ - WORD wVersionRequested; - WSADATA wsaData; - int err; - - /* Need Winsock 2.0 or better */ - wVersionRequested = MAKEWORD(2, 0); - - err = WSAStartup(wVersionRequested, &wsaData); - if ( err != 0 ) { - fprintf(stderr, "No useable winsock.dll: %s\n", strerror(err)); - SetLastError(err); - msyslog(LOG_ERR, "No usable winsock.dll: %m"); - exit(1); - } -} diff --git a/ports/winnt/libntp/win32_io.c b/ports/winnt/libntp/win32_io.c new file mode 100644 index 000000000..9bc0a665a --- /dev/null +++ b/ports/winnt/libntp/win32_io.c @@ -0,0 +1,80 @@ +/* This file implements i/o calls that are specific to Windows */ + +#include +#include +#include "ntp_fp.h" +#include "ntp_net.h" +#include "ntp_stdlib.h" +#include "ntp_syslog.h" +#include "win32_io.h" +#include + +/* + * Define this macro to control the behavior of connection + * resets on UDP sockets. See Microsoft KnowledgeBase Article Q263823 + * for details. + * Based on that article, it is surprising that a much newer winsock2.h + * does not define SIO_UDP_CONNRESET (the one that comes with VS 2008). + * NOTE: This requires that Windows 2000 systems install Service Pack 2 + * or later. + */ +#ifndef SIO_UDP_CONNRESET +#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12) +#endif + +void +InitSockets( + void + ) +{ + WORD wVersionRequested; + WSADATA wsaData; + int err; + + /* Need Winsock 2.0 or better */ + wVersionRequested = MAKEWORD(2, 0); + + err = WSAStartup(wVersionRequested, &wsaData); + if ( err != 0 ) { + fprintf(stderr, "No useable winsock.dll: %s\n", strerror(err)); + SetLastError(err); + msyslog(LOG_ERR, "No usable winsock.dll: %m"); + exit(1); + } +} + +/* + * Windows 2000 systems incorrectly cause UDP sockets using WASRecvFrom + * to not work correctly, returning a WSACONNRESET error when a WSASendTo + * fails with an "ICMP port unreachable" response and preventing the + * socket from using the WSARecvFrom in subsequent operations. + * The function below fixes this, but requires that Windows 2000 + * Service Pack 2 or later be installed on the system. NT 4.0 + * systems are not affected by this and work correctly. + * See Microsoft Knowledge Base Article Q263823 for details of this. + */ +void +connection_reset_fix( + SOCKET fd, + sockaddr_u * addr + ) +{ + DWORD dw; + BOOL bNewBehavior = FALSE; + DWORD status; + + /* + * disable bad behavior using IOCTL: SIO_UDP_CONNRESET + * NT 4.0 has no problem + */ + if (isc_win32os_majorversion() >= 5) { + status = WSAIoctl(fd, SIO_UDP_CONNRESET, &bNewBehavior, + sizeof(bNewBehavior), NULL, 0, + &dw, NULL, NULL); + if (SOCKET_ERROR == status) + msyslog(LOG_ERR, + "connection_reset_fix() failed for address %s: %m", + stoa(addr)); + } +} + diff --git a/ports/winnt/vs2005/Instsrv.vcproj b/ports/winnt/vs2005/Instsrv.vcproj index 1691ebf70..1a1726ed4 100644 --- a/ports/winnt/vs2005/Instsrv.vcproj +++ b/ports/winnt/vs2005/Instsrv.vcproj @@ -70,7 +70,7 @@ /> + + @@ -1932,6 +1936,10 @@ /> + + @@ -2222,11 +2230,11 @@ > diff --git a/ports/winnt/vs2005/ntp.sln b/ports/winnt/vs2005/ntp.sln index 32b5e5ddb..6b840bed7 100644 --- a/ports/winnt/vs2005/ntp.sln +++ b/ports/winnt/vs2005/ntp.sln @@ -1,4 +1,3 @@ - Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "instsrv", "Instsrv.vcproj", "{EAA8D0C8-A8AF-4C40-BF14-4A94570DE033}" @@ -21,6 +20,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ntpdc", "ntpdc.vcproj", "{C EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ntpkeygen", "ntpkeygen.vcproj", "{9B768B99-2BC8-4A4C-AC0D-A7DA9C695825}" + ProjectSection(ProjectDependencies) = postProject + {ECDDC7EE-5805-4603-B38D-804C09BDC910} = {ECDDC7EE-5805-4603-B38D-804C09BDC910} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ntpq", "ntpq.vcproj", "{EA10E04E-946B-44A6-B0AB-B5B93A160744}" ProjectSection(ProjectDependencies) = postProject diff --git a/ports/winnt/vs2005/ntpd.vcproj b/ports/winnt/vs2005/ntpd.vcproj index a417c1a9d..19e0ef2f2 100644 --- a/ports/winnt/vs2005/ntpd.vcproj +++ b/ports/winnt/vs2005/ntpd.vcproj @@ -3,7 +3,7 @@ ProjectType="Visual C++" Version="8.00" Name="ntpd" - ProjectGUID="{DDAB6ECD-E9DF-46B2-8737-6DEF96ADA59A}" + ProjectGUID="{F6F7E7C0-AE5E-4D7C-A17E-A3043FE68664}" > - - - - - - - - diff --git a/ports/winnt/vs2008/libntp/libntp.vcproj b/ports/winnt/vs2008/libntp/libntp.vcproj index f91d1bcff..9a826398a 100644 --- a/ports/winnt/vs2008/libntp/libntp.vcproj +++ b/ports/winnt/vs2008/libntp/libntp.vcproj @@ -539,10 +539,18 @@ RelativePath="..\..\libntp\util_clockstuff.c" > + + + + diff --git a/ports/winnt/vs2008/ntpd/ntpd.vcproj b/ports/winnt/vs2008/ntpd/ntpd.vcproj index 23bccd44c..b04ebfd47 100644 --- a/ports/winnt/vs2008/ntpd/ntpd.vcproj +++ b/ports/winnt/vs2008/ntpd/ntpd.vcproj @@ -693,28 +693,6 @@ /> - - - - - - - -