mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
w32: Almost everywhere include winsock2.h before windows.h.
-- This is required by newer mingw toolchain versions which demand that winsock2.h is included before windows.h. Now, due to the use of socket definitions in pth.h we need to include winsock2.h also in pth.h, now pth.h is often included after an include of windows.h and thus the compiler spits out a warning. To avoid that we include winsock2.h at all places the compiler complains about.
This commit is contained in:
parent
a557a74615
commit
40ca0022a7
20 changed files with 436 additions and 380 deletions
|
@ -28,7 +28,10 @@
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
#include <windows.h>
|
||||
# ifdef HAVE_WINSOCK2_H
|
||||
# include <winsock2.h>
|
||||
# endif
|
||||
# include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -79,9 +82,9 @@ connect_server (const char *server, unsigned short port)
|
|||
|
||||
/* Win32 gethostbyname doesn't handle IP addresses internally, so we
|
||||
try inet_addr first on that platform only. */
|
||||
if ((l = inet_addr (server)) != INADDR_NONE)
|
||||
if ((l = inet_addr (server)) != INADDR_NONE)
|
||||
memcpy (&addr.sin_addr, &l, sizeof l);
|
||||
else if ((hp = gethostbyname (server)))
|
||||
else if ((hp = gethostbyname (server)))
|
||||
{
|
||||
if (hp->h_addrtype != AF_INET)
|
||||
{
|
||||
|
@ -107,14 +110,14 @@ connect_server (const char *server, unsigned short port)
|
|||
sock = socket (AF_INET, SOCK_STREAM, 0);
|
||||
if (sock == INVALID_SOCKET)
|
||||
{
|
||||
fprintf (console, "gpgkeys: error creating socket: ec=%d\n",
|
||||
fprintf (console, "gpgkeys: error creating socket: ec=%d\n",
|
||||
(int)WSAGetLastError ());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connect (sock, (struct sockaddr *)&addr, sizeof addr))
|
||||
{
|
||||
fprintf (console, "gpgkeys: error connecting `%s': ec=%d\n",
|
||||
fprintf (console, "gpgkeys: error connecting `%s': ec=%d\n",
|
||||
server, (int)WSAGetLastError ());
|
||||
sock_close (sock);
|
||||
return -1;
|
||||
|
@ -134,26 +137,26 @@ connect_server (const char *server, unsigned short port)
|
|||
server, strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
addr.sin_addr = *(struct in_addr*)host->h_addr;
|
||||
|
||||
sock = socket (AF_INET, SOCK_STREAM, 0);
|
||||
if (sock == -1)
|
||||
{
|
||||
fprintf (console, "gpgkeys: error creating socket: %s\n",
|
||||
fprintf (console, "gpgkeys: error creating socket: %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (connect (sock, (struct sockaddr *)&addr, sizeof addr) == -1)
|
||||
{
|
||||
fprintf (console, "gpgkeys: error connecting `%s': %s\n",
|
||||
fprintf (console, "gpgkeys: error connecting `%s': %s\n",
|
||||
server, strerror (errno));
|
||||
close (sock);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
|
@ -163,11 +166,11 @@ write_server (int sock, const char *data, size_t length)
|
|||
int nleft;
|
||||
|
||||
nleft = length;
|
||||
while (nleft > 0)
|
||||
while (nleft > 0)
|
||||
{
|
||||
int nwritten;
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
nwritten = send (sock, data, nleft, 0);
|
||||
if ( nwritten == SOCKET_ERROR )
|
||||
{
|
||||
|
@ -184,7 +187,7 @@ write_server (int sock, const char *data, size_t length)
|
|||
if (errno == EAGAIN)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 50000;
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
|
@ -197,7 +200,7 @@ write_server (int sock, const char *data, size_t length)
|
|||
nleft -=nwritten;
|
||||
data += nwritten;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -227,7 +230,7 @@ send_request (const char *request, int *r_sock)
|
|||
return KEYSERVER_GENERAL_ERROR;
|
||||
}
|
||||
*server++ = 0;
|
||||
|
||||
|
||||
sock = connect_server (server, 79);
|
||||
if (sock == -1)
|
||||
{
|
||||
|
@ -272,7 +275,7 @@ get_key (char *getkey)
|
|||
sock_close (sock);
|
||||
return KEYSERVER_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Hmmm, we use iobuf here only to cope with Windows socket
|
||||
peculiarities (we can't used fdopen). */
|
||||
fp_read = iobuf_sockopen (sock , "r");
|
||||
|
@ -286,7 +289,7 @@ get_key (char *getkey)
|
|||
while ( iobuf_read_line ( fp_read, &line, &buflen, &maxlen))
|
||||
{
|
||||
maxlen=1024;
|
||||
|
||||
|
||||
if(gotit)
|
||||
{
|
||||
print_nocr(output, (const char*)line);
|
||||
|
@ -299,7 +302,7 @@ get_key (char *getkey)
|
|||
gotit=1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(gotit)
|
||||
fprintf (output,"KEY 0x%s END\n", getkey);
|
||||
else
|
||||
|
@ -316,7 +319,7 @@ get_key (char *getkey)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
static void
|
||||
show_help (FILE *fp)
|
||||
{
|
||||
fprintf (fp,"-h, --help\thelp\n");
|
||||
|
|
|
@ -36,7 +36,10 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
#include <windows.h>
|
||||
# ifdef HAVE_WINSOCK2_H
|
||||
# include <winsock2.h>
|
||||
# endif
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBCURL
|
||||
|
@ -78,7 +81,7 @@ register_timeout(void)
|
|||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags=0;
|
||||
return sigaction(SIGALRM,&act,NULL);
|
||||
#else
|
||||
#else
|
||||
if(signal(SIGALRM,catch_alarm)==SIG_ERR)
|
||||
return -1;
|
||||
else
|
||||
|
@ -597,7 +600,7 @@ ks_hextobyte (const char *s)
|
|||
|
||||
|
||||
/* Non localized version of toupper. */
|
||||
int
|
||||
int
|
||||
ks_toupper (int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue