From 8f95cb2f48e1dc1595b0a9ebbdc63995b2cb99e9 Mon Sep 17 00:00:00 2001 From: Kiritow-Tablet <1362050620@qq.com> Date: Wed, 6 Jun 2018 08:42:54 +0800 Subject: [PATCH] Fix bug in convertback_ipv46() --- gsock.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gsock.cpp b/gsock.cpp index 41bbd3f..bb5a1a5 100644 --- a/gsock.cpp +++ b/gsock.cpp @@ -12,8 +12,8 @@ #ifdef GSOCK_DEBUG #pragma message("GSock Debug mode compiled in") #include -#define myliblog(fmt,...) printf(" " fmt,__func__,__VA_ARGS__) -#define myliblog_ex(cond,fmt,...) do{if(cond){myliblog(fmt,__VA_ARGS__);}}while(0) +#define myliblog(fmt,...) printf(" " fmt,__func__,##__VA_ARGS__) +#define myliblog_ex(cond,fmt,...) do{if(cond){myliblog(fmt,##__VA_ARGS__);}}while(0) #else #define myliblog(fmt,...) #define myliblog_ex(cond,fmt,...) @@ -38,6 +38,7 @@ #include #define closesocket close using BYTE = unsigned char; +#define WSAGetLastError() errno #endif #include /// memset @@ -678,7 +679,7 @@ static int convertback_ipv46(const sockaddr* paddr, std::string& _out_IPStr) char buff[128] = { 0 }; if (paddr->sa_family == AF_INET) { - if (inet_ntop(AF_INET, paddr, buff, 128)!=NULL) + if (inet_ntop(AF_INET, &(((const sockaddr_in*)paddr)->sin_addr), buff, 128)!=NULL) { _out_IPStr = std::move(std::string(buff)); return 0; @@ -687,7 +688,7 @@ static int convertback_ipv46(const sockaddr* paddr, std::string& _out_IPStr) } else if (paddr->sa_family == AF_INET6) { - if (inet_ntop(AF_INET6, paddr, buff, 128) != NULL) + if (inet_ntop(AF_INET6, &(((const sockaddr_in6*)paddr)->sin6_addr), buff, 128) != NULL) { _out_IPStr = std::move(std::string(buff)); return 1; @@ -1135,4 +1136,4 @@ int DNSResolve(const std::string& HostName, std::string& _out_IPStr) /// Undefine marcos #undef myliblog_ex -#undef myliblog +#undef myliblog \ No newline at end of file