From: Guus Sliepen Date: Sat, 24 Oct 2009 22:50:09 +0000 (+0200) Subject: Use WSAGetLastError() to determine cause of network errors on Windows. X-Git-Tag: release-1.0.11~4 X-Git-Url: https://git.librecmc.org/?p=oweals%2Ftinc.git;a=commitdiff_plain;h=c11dc8079b60d9f8c5b1c7e8fecd90d0fac5a20c Use WSAGetLastError() to determine cause of network errors on Windows. This reduces log spam and lets path MTU discovery work faster. --- diff --git a/src/net_packet.c b/src/net_packet.c index 054a66f..3243670 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -46,8 +46,16 @@ #include "utils.h" #include "xalloc.h" -#ifdef WSAEMSGSIZE +#ifdef HAVE_MINGW +#include #define EMSGSIZE WSAEMSGSIZE +#define EAGAIN WSATRY_AGAIN +#define EINTR WSAEINTR +#define sockstrerror(x) winerror(x) +#define sockerrno WSAGetLastError() +#else +#define sockstrerror(x) strerror(x) +#define sockerrno errno #endif int keylifetime = 0; @@ -450,13 +458,13 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { #endif if((sendto(listen_socket[sock].udp, (char *) &inpkt->seqno, inpkt->len, 0, &(n->address.sa), SALEN(n->address.sa))) < 0) { - if(errno == EMSGSIZE) { + if(sockerrno == EMSGSIZE) { if(n->maxmtu >= origlen) n->maxmtu = origlen - 1; if(n->mtu >= origlen) n->mtu = origlen - 1; } else - logger(LOG_ERR, "Error sending packet to %s (%s): %s", n->name, n->hostname, strerror(errno)); + logger(LOG_ERR, "Error sending packet to %s (%s): %s", n->name, n->hostname, sockstrerror(sockerrno)); } end: @@ -562,8 +570,8 @@ void handle_incoming_vpn_data(int sock) { pkt.len = recvfrom(sock, (char *) &pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen); if(pkt.len < 0) { - if(errno != EAGAIN && errno != EINTR) - logger(LOG_ERR, "Receiving packet failed: %s", strerror(errno)); + if(sockerrno != EAGAIN && sockerrno != EINTR) + logger(LOG_ERR, "Receiving packet failed: %s", sockstrerror(sockerrno)); return; }