/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* ---
*
* host.c: make stream connection to empire
- *
+ *
* Known contributors to this file:
* Dave Pare, 1989
* Steve McClure, 1998
#include <netdb.h>
#include <unistd.h>
#else
-#include <winsock2.h>
-#include <ws2tcpip.h>
+#define close(fd) w32_close_socket((fd))
#endif
#include "misc.h"
+/* Portability cruft, should become unnecessary eventually */
+#ifndef AI_ADDRCONFIG
+#define AI_ADDRCONFIG 0
+#endif
+
#ifdef HAVE_GETADDRINFO
/*
* Inspired by example code from W. Richard Stevens: UNIX Network
struct addrinfo hints, *res, *ressave;
memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_flags = AI_ADDRCONFIG;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
if (connect(sockfd, res->ai_addr, res->ai_addrlen) == 0)
break; /* success */
-#ifdef _WIN32
- closesocket(sockfd); /* ignore this one */
-#else
close(sockfd); /* ignore this one */
-#endif
} while ((res = res->ai_next) != NULL);
if (res == NULL) { /* errno set from final connect() */
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) {
-#ifdef _WIN32
- errno = WSAGetLastError();
-#endif
return -1;
}
addr->sin_family = AF_INET;
if (connect(s, (struct sockaddr *)addr, sizeof(*addr)) < 0) {
-#ifdef _WIN32
- errno = WSAGetLastError();
- (void)closesocket(s);
-#else
(void)close(s);
-#endif
return -1;
}
return s;