From bc59ac7fd1fcf751e2c43e9aa28ee467efe95bbb Mon Sep 17 00:00:00 2001 From: Greg Hazel Date: Thu, 27 May 2010 19:30:15 -0700 Subject: [PATCH] build fixes for VS 2010 --- utp.cpp | 8 ++++++-- utp_file/utp_recv.cpp | 21 ++++++++++++--------- utp_file/utp_send.cpp | 21 ++++++++++++--------- utp_test/utp_test.cpp | 23 ++++++++++++----------- utp_utils.cpp | 1 + 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/utp.cpp b/utp.cpp index 29ee684..4715f4d 100644 --- a/utp.cpp +++ b/utp.cpp @@ -7,17 +7,21 @@ #include #include #include +#include #include #include // for UINT_MAX #ifdef WIN32 #include "win32_inet_ntop.h" +// newer versions of MSVC define these in errno.h +#ifndef ECONNRESET #define ECONNRESET WSAECONNRESET #define EMSGSIZE WSAEMSGSIZE #define ECONNREFUSED WSAECONNREFUSED #define ETIMEDOUT WSAETIMEDOUT #endif +#endif #ifdef POSIX typedef sockaddr_storage SOCKADDR_STORAGE; @@ -191,13 +195,13 @@ struct PackedSockAddr { const byte family = get_family(); str i; if (family == AF_INET) { - inet_ntop(family, &_sin4, s, len); + inet_ntop(family, (uint32*)&_sin4, s, len); i = s; while (*++i) {} } else { i = s; *i++ = '['; - inet_ntop(family, &_in._in6addr, i, len-1); + inet_ntop(family, (in6_addr*)&_in._in6addr, i, len-1); while (*++i) {} *i++ = ']'; } diff --git a/utp_file/utp_recv.cpp b/utp_file/utp_recv.cpp index 8eee891..2264d1f 100644 --- a/utp_file/utp_recv.cpp +++ b/utp_file/utp_recv.cpp @@ -3,14 +3,6 @@ #define WIN32_LEAN_AND_MEAN #endif -#ifdef WIN32 -#define ECONNRESET WSAECONNRESET -#define EMSGSIZE WSAEMSGSIZE -#define ECONNREFUSED WSAECONNREFUSED -#define ECONNRESET WSAECONNRESET -#define ETIMEDOUT WSAETIMEDOUT -#endif - #include #include #include @@ -19,6 +11,17 @@ #include #include +#ifdef WIN32 +// newer versions of MSVC define these in errno.h +#ifndef ECONNRESET +#define ECONNRESET WSAECONNRESET +#define EMSGSIZE WSAEMSGSIZE +#define ECONNREFUSED WSAECONNREFUSED +#define ECONNRESET WSAECONNRESET +#define ETIMEDOUT WSAETIMEDOUT +#endif +#endif + // platform-specific includes #ifdef POSIX #include @@ -152,7 +155,7 @@ SOCKET make_socket(const struct sockaddr *addr, socklen_t addrlen) if (bind(s, addr, addrlen) < 0) { char str[20]; printf("UDP port bind failed %s: (%d) %s\n", - inet_ntop(addr->sa_family, addr, str, sizeof(str)), errno, strerror(errno)); + inet_ntop(addr->sa_family, (sockaddr*)addr, str, sizeof(str)), errno, strerror(errno)); closesocket(s); return INVALID_SOCKET; } diff --git a/utp_file/utp_send.cpp b/utp_file/utp_send.cpp index bf533ad..4c03861 100644 --- a/utp_file/utp_send.cpp +++ b/utp_file/utp_send.cpp @@ -3,14 +3,6 @@ #define WIN32_LEAN_AND_MEAN #endif -#ifdef WIN32 -#define ECONNRESET WSAECONNRESET -#define EMSGSIZE WSAEMSGSIZE -#define ECONNREFUSED WSAECONNREFUSED -#define ECONNRESET WSAECONNRESET -#define ETIMEDOUT WSAETIMEDOUT -#endif - #include #include #include @@ -19,6 +11,17 @@ #include #include +#ifdef WIN32 +// newer versions of MSVC define these in errno.h +#ifndef ECONNRESET +#define ECONNRESET WSAECONNRESET +#define EMSGSIZE WSAEMSGSIZE +#define ECONNREFUSED WSAECONNREFUSED +#define ECONNRESET WSAECONNRESET +#define ETIMEDOUT WSAETIMEDOUT +#endif +#endif + // platform-specific includes #ifdef POSIX #include @@ -152,7 +155,7 @@ SOCKET make_socket(const struct sockaddr *addr, socklen_t addrlen) if (bind(s, addr, addrlen) < 0) { char str[20]; printf("UDP port bind failed %s: (%d) %s\n", - inet_ntop(addr->sa_family, addr, str, sizeof(str)), errno, strerror(errno)); + inet_ntop(addr->sa_family, (sockaddr*)addr, str, sizeof(str)), errno, strerror(errno)); closesocket(s); return INVALID_SOCKET; } diff --git a/utp_test/utp_test.cpp b/utp_test/utp_test.cpp index 4cee3ee..22c93e8 100644 --- a/utp_test/utp_test.cpp +++ b/utp_test/utp_test.cpp @@ -3,14 +3,6 @@ #define WIN32_LEAN_AND_MEAN #endif -#ifdef WIN32 -#define ECONNRESET WSAECONNRESET -#define EMSGSIZE WSAEMSGSIZE -#define ECONNREFUSED WSAECONNREFUSED -#define ECONNRESET WSAECONNRESET -#define ETIMEDOUT WSAETIMEDOUT -#endif - #include #include #include @@ -19,6 +11,17 @@ #include #include +#ifdef WIN32 +// newer versions of MSVC define these in errno.h +#ifndef ECONNRESET +#define ECONNRESET WSAECONNRESET +#define EMSGSIZE WSAEMSGSIZE +#define ECONNREFUSED WSAECONNREFUSED +#define ECONNRESET WSAECONNRESET +#define ETIMEDOUT WSAETIMEDOUT +#endif +#endif + // platform-specific includes #ifdef POSIX #include @@ -165,7 +168,7 @@ SOCKET make_socket(const struct sockaddr *addr, socklen_t addrlen) if (bind(s, addr, addrlen) < 0) { char str[20]; printf("UDP port bind failed %s: (%d) %s\n", - inet_ntop(addr->sa_family, addr, str, sizeof(str)), errno, strerror(errno)); + inet_ntop(addr->sa_family, (sockaddr*)addr, str, sizeof(str)), errno, strerror(errno)); closesocket(s); return INVALID_SOCKET; } @@ -197,7 +200,6 @@ void UDPSocketManager::set_socket(SOCKET s) if (_socket != INVALID_SOCKET) closesocket(_socket); assert(s != INVALID_SOCKET); _socket = s; - } void send_to(void *userdata, const byte *p, size_t len, const struct sockaddr *to, socklen_t tolen) @@ -499,4 +501,3 @@ int main(int argc, char* argv[]) fclose(log_file); } - diff --git a/utp_utils.cpp b/utp_utils.cpp index f289609..a3ba801 100644 --- a/utp_utils.cpp +++ b/utp_utils.cpp @@ -2,6 +2,7 @@ #include "utypes.h" #include +#include #ifdef WIN32