fixed error message for socket creation on windows

This commit is contained in:
oy 2011-12-04 17:09:30 +01:00
parent 8e0ce38e29
commit c057f96540

View file

@ -7,9 +7,7 @@
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
/*#include "detect.h"*/
#include "system.h" #include "system.h"
/*#include "e_console.h"*/
#if defined(CONF_FAMILY_UNIX) #if defined(CONF_FAMILY_UNIX)
#include <sys/time.h> #include <sys/time.h>
@ -828,7 +826,15 @@ static int priv_net_create_socket(int domain, int type, struct sockaddr *addr, i
sock = socket(domain, type, 0); sock = socket(domain, type, 0);
if(sock < 0) if(sock < 0)
{ {
#if defined(CONF_FAMILY_WINDOWS)
char buf[128];
int error = WSAGetLastError();
if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, 0, buf, sizeof(buf), 0) == 0)
buf[0] = 0;
dbg_msg("net", "failed to create socket with domain %d and type %d (%d '%s')", domain, type, error, buf);
#else
dbg_msg("net", "failed to create socket with domain %d and type %d (%d '%s')", domain, type, errno, strerror(errno)); dbg_msg("net", "failed to create socket with domain %d and type %d (%d '%s')", domain, type, errno, strerror(errno));
#endif
return -1; return -1;
} }
@ -845,7 +851,15 @@ static int priv_net_create_socket(int domain, int type, struct sockaddr *addr, i
e = bind(sock, addr, sockaddrlen); e = bind(sock, addr, sockaddrlen);
if(e != 0) if(e != 0)
{ {
#if defined(CONF_FAMILY_WINDOWS)
char buf[128];
int error = WSAGetLastError();
if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, 0, buf, sizeof(buf), 0) == 0)
buf[0] = 0;
dbg_msg("net", "failed to create socket with domain %d and type %d (%d '%s')", domain, type, error, buf);
#else
dbg_msg("net", "failed to bind socket with domain %d and type %d (%d '%s')", domain, type, errno, strerror(errno)); dbg_msg("net", "failed to bind socket with domain %d and type %d (%d '%s')", domain, type, errno, strerror(errno));
#endif
priv_net_close_socket(sock); priv_net_close_socket(sock);
return -1; return -1;
} }