make sure networking is initialized before doing /anything/. this should

fix the host lookup failurs for win32 when using -f.
This commit is contained in:
Bill Currie 2002-02-13 17:58:30 +00:00
parent 2c1173aadf
commit 234305f0ab
1 changed files with 19 additions and 12 deletions

View File

@ -234,24 +234,12 @@ void
QW_Master (struct sockaddr_in *addr) QW_Master (struct sockaddr_in *addr)
{ {
int sock; int sock;
#ifdef _WIN32
int i;
WSADATA winsockdata;
#endif
if (!servers) { if (!servers) {
printf ("initial malloc failed\n"); printf ("initial malloc failed\n");
return; return;
} }
#ifdef _WIN32
i = WSAStartup (MAKEWORD (1, 1), &winsockdata);
if (i) {
printf ("Winsock initialization failed.\n");
return;
}
#endif
sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0) { if (sock < 0) {
printf ("socket failed\n"); printf ("socket failed\n");
@ -373,6 +361,22 @@ read_hosts (const char *fname)
fclose (host_file); fclose (host_file);
} }
static int
net_init (void)
{
#ifdef _WIN32
int i;
WSADATA winsockdata;
i = WSAStartup (MAKEWORD (1, 1), &winsockdata);
if (i) {
printf ("Winsock initialization failed.\n");
return 0;
}
#endif
return 1;
}
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
@ -380,6 +384,9 @@ main (int argc, char **argv)
short port = htons (PORT_MASTER); short port = htons (PORT_MASTER);
int c; int c;
if (!net_init ())
return 1;
servers = calloc (sizeof (server_t), serverlen); servers = calloc (sizeof (server_t), serverlen);
while ((c = getopt (argc, argv, "p:f:")) != -1) { while ((c = getopt (argc, argv, "p:f:")) != -1) {