1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

net_gethostbyname_nonblock(): don't crash if net_gethosterror() returns

error message as NULL.

Initialize winsock with win32.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@966 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-12-05 19:43:12 +00:00 committed by cras
parent 4316840890
commit 346808789c
2 changed files with 20 additions and 3 deletions

View File

@ -103,11 +103,11 @@ int net_gethostbyname_nonblock(const char *addr, GIOChannel *pipe)
errorstr = NULL; errorstr = NULL;
} else { } else {
errorstr = net_gethosterror(rec.error); errorstr = net_gethosterror(rec.error);
rec.errlen = strlen(errorstr)+1; rec.errlen = errorstr == NULL ? 0 : strlen(errorstr)+1;
} }
g_io_channel_write_block(pipe, &rec, sizeof(rec)); g_io_channel_write_block(pipe, &rec, sizeof(rec));
if (rec.error != 0) if (rec.errlen != 0)
g_io_channel_write_block(pipe, (void *) errorstr, rec.errlen); g_io_channel_write_block(pipe, (void *) errorstr, rec.errlen);
#ifndef WIN32 #ifndef WIN32

View File

@ -223,10 +223,27 @@ static void check_files(void)
g_free(path); g_free(path);
} }
#ifdef WIN32
static void winsock_init(void)
{
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 2);
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
printf("Error initializing winsock\n");
exit(1);
}
}
#endif
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
check_files(); check_files();
#ifdef WIN32
winsock_init();
#endif
#ifdef HAVE_SOCKS #ifdef HAVE_SOCKS
SOCKSinit(argv[0]); SOCKSinit(argv[0]);
#endif #endif