mirror of
https://github.com/hufrea/byedpi.git
synced 2024-11-20 12:25:05 +00:00
42 lines
734 B
C
42 lines
734 B
C
#include <stdio.h>
|
|
#include <errno.h>
|
|
|
|
#ifdef _WIN32
|
|
#include <winsock2.h>
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
#define get_e() \
|
|
unie(WSAGetLastError())
|
|
#else
|
|
#define get_e() \
|
|
errno
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
#define uniperror(str) \
|
|
fprintf(stderr, "%s: %d\n", str, WSAGetLastError())
|
|
#else
|
|
#define uniperror(str) \
|
|
perror(str)
|
|
#endif
|
|
|
|
inline const int unie(int e)
|
|
{
|
|
#ifdef _WIN32
|
|
switch (e) {
|
|
case WSAEWOULDBLOCK:
|
|
return EAGAIN;
|
|
case WSAETIMEDOUT:
|
|
return ETIMEDOUT;
|
|
case WSAENETUNREACH:
|
|
return ENETUNREACH;
|
|
case WSAEHOSTUNREACH:
|
|
return EHOSTUNREACH;
|
|
case WSAECONNREFUSED:
|
|
return ECONNREFUSED;
|
|
}
|
|
#endif
|
|
return e;
|
|
}
|