From: Danny Mayer Date: Thu, 7 Aug 2003 02:15:52 +0000 (-0400) Subject: Use the Win32InitSockets code now in port/winnt/libisc/net.c so we use common code. X-Git-Tag: NTP_4_2_0~28^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fcba497ec8b86e38405501d1b4152b8cd91d30dc;p=thirdparty%2Fntp.git Use the Win32InitSockets code now in port/winnt/libisc/net.c so we use common code. Need to force the isc headers to not include the isc/ipv6.h code. bk: 3f31b6584omMweWn4QlMhiYYsZpqdA --- diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 68ee2fafb7..8ecc9320d7 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -187,8 +187,6 @@ void init_io(void) { #ifdef SYS_WINNT - WORD wVersionRequested; - WSADATA wsaData; init_transmitbuff(); #endif /* SYS_WINNT */ @@ -214,8 +212,7 @@ init_io(void) #endif #ifdef SYS_WINNT - wVersionRequested = MAKEWORD(2,0); - if (WSAStartup(wVersionRequested, &wsaData)) + if (!Win32InitSockets()) { netsyslog(LOG_ERR, "No useable winsock.dll: %m"); exit(1); diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index a49df1681f..294b88da2d 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -8,6 +8,8 @@ #include "ntp_select.h" #include "ntp_io.h" #include "ntp_stdlib.h" +/* Don't include ISC's version of IPv6 variables and structures */ +#define ISC_IPV6_H 1 #include "isc/net.h" #include "isc/result.h" @@ -176,8 +178,6 @@ char password[9]; #endif /* SYS_WINNT || SYS_VXWORKS */ #ifdef SYS_WINNT -WORD wVersionRequested; -WSADATA wsaData; DWORD NumberOfBytesWritten; HANDLE TimerThreadHandle = NULL; /* 1998/06/03 - Used in ntplib/machines.c */ @@ -301,6 +301,15 @@ ntpdcmain( taskPrioritySet(taskIdSelf(), 100 ); #endif +#ifdef SYS_WINNT + if (!Win32InitSockets()) + { + fprintf(stderr, "No useable winsock.dll:"); + exit(1); + } +#endif /* SYS_WINNT */ + + /* Check to see if we have IPv6. Otherwise force the -4 flag */ if (isc_net_probeipv6() != ISC_R_SUCCESS) { ai_fam_default = AF_INET; } @@ -373,14 +382,6 @@ ntpdcmain( } pktdatasize = INITDATASIZE; -#ifdef SYS_WINNT - wVersionRequested = MAKEWORD(1,1); - if (WSAStartup(wVersionRequested, &wsaData)) { - fprintf(stderr, "No useable winsock.dll"); - exit(1); - } -#endif /* SYS_WINNT */ - if (numcmds == 0) { (void) openhost(chosts[0]); getcmds(); diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 5ba7f23f67..e45a4af748 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -10,6 +10,8 @@ #include "ntp_io.h" #include "ntp_select.h" #include "ntp_stdlib.h" +/* Don't include ISC's version of IPv6 variables and structures */ +#define ISC_IPV6_H 1 #include "isc/net.h" #include "isc/result.h" @@ -375,8 +377,6 @@ int s_port = 0; struct servent *server_entry = NULL; /* server entry for ntp */ #ifdef SYS_WINNT -WORD wVersionRequested; -WSADATA wsaData; DWORD NumberOfBytesWritten; HANDLE TimerThreadHandle = NULL; /* 1998/06/03 - Used in ntplib/machines.c */ @@ -501,6 +501,15 @@ ntpqmain( delay_time.l_ui = 0; delay_time.l_uf = DEFDELAY; +#ifdef SYS_WINNT + if (!Win32InitSockets()) + { + fprintf(stderr, "No useable winsock.dll:"); + exit(1); + } +#endif /* SYS_WINNT */ + + /* Check to see if we have IPv6. Otherwise force the -4 flag */ if (isc_net_probeipv6() != ISC_R_SUCCESS) { ai_fam_default = AF_INET; } @@ -557,14 +566,6 @@ ntpqmain( (void) signal_no_reset(SIGINT, abortcmd); #endif /* SYS_WINNT */ -#ifdef SYS_WINNT - wVersionRequested = MAKEWORD(1,1); - if (WSAStartup(wVersionRequested, &wsaData)) { - fprintf(stderr, "No useable winsock.dll"); - exit(1); - } -#endif /* SYS_WINNT */ - if (numcmds == 0) { (void) openhost(chosts[0]); getcmds(); diff --git a/ports/winnt/include/isc/net.h b/ports/winnt/include/isc/net.h index 43e54fbe36..462a7a3f3b 100644 --- a/ports/winnt/include/isc/net.h +++ b/ports/winnt/include/isc/net.h @@ -265,6 +265,11 @@ isc_net_aton(const char *cp, struct in_addr *addr); #define inet_aton isc_net_aton #endif +/* Socket Initialization Code */ + +BOOL +Win32InitSockets(); + ISC_LANG_ENDDECLS #endif /* ISC_NET_H */ diff --git a/ports/winnt/libisc/net.c b/ports/winnt/libisc/net.c index dd23549674..34a62887b0 100644 --- a/ports/winnt/libisc/net.c +++ b/ports/winnt/libisc/net.c @@ -117,3 +117,21 @@ isc_net_probeipv6(void) { initialize(); return (ipv6_result); } +/* + * Initialize socket services + */ +BOOL Win32InitSockets() { + WORD wVersionRequested; + WSADATA wsaData; + int err; + + /* Need Winsock 2.0 or better */ + wVersionRequested = MAKEWORD(2, 0); + + err = WSAStartup(wVersionRequested, &wsaData); + if ( err != 0 ) { + /* Tell the user that we could not find a usable Winsock DLL */ + return(FALSE); + } + return(TRUE); +}