From aa8e9c63ad0300df0eed07c3fe4f19d859a63673 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 2 Aug 2016 03:37:02 +0000 Subject: socket/option.c: inet_ntop * ext/socket/option.c, ext/socket/rubysocket.h (inet_ntop): share the fallback definition. [ruby-core:76646] [Bug #12645] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/socket/getnameinfo.c | 18 ------------------ ext/socket/option.c | 6 +----- ext/socket/rubysocket.h | 8 ++++++++ 3 files changed, 9 insertions(+), 23 deletions(-) (limited to 'ext') diff --git a/ext/socket/getnameinfo.c b/ext/socket/getnameinfo.c index bca97acc1f..b7e75f7d27 100644 --- a/ext/socket/getnameinfo.c +++ b/ext/socket/getnameinfo.c @@ -117,24 +117,6 @@ static struct afd { #define ENI_FAMILY 5 #define ENI_SALEN 6 -#ifndef HAVE_INET_NTOP -static const char * -inet_ntop(int af, const void *addr, char *numaddr, size_t numaddr_len) -{ -#ifdef HAVE_INET_NTOA - struct in_addr in; - memcpy(&in.s_addr, addr, sizeof(in.s_addr)); - snprintf(numaddr, numaddr_len, "%s", inet_ntoa(in)); -#else - unsigned long x = ntohl(*(unsigned long*)addr); - snprintf(numaddr, numaddr_len, "%d.%d.%d.%d", - (int) (x>>24) & 0xff, (int) (x>>16) & 0xff, - (int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff); -#endif - return numaddr; -} -#endif - int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags) { diff --git a/ext/socket/option.c b/ext/socket/option.c index 7307548e50..a823ec7757 100644 --- a/ext/socket/option.c +++ b/ext/socket/option.c @@ -645,7 +645,7 @@ inspect_timeval_as_interval(int level, int optname, VALUE data, VALUE ret) */ #if !defined HAVE_INET_NTOP && ! defined _WIN32 -static const char * +const char * inet_ntop(int af, const void *addr, char *numaddr, size_t numaddr_len) { #ifdef HAVE_INET_NTOA @@ -660,10 +660,6 @@ inet_ntop(int af, const void *addr, char *numaddr, size_t numaddr_len) #endif return numaddr; } -#elif defined __MINGW32__ -# define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l) -#elif defined _MSC_VER && RUBY_MSVCRT_VERSION < 90 -const char *WSAAPI inet_ntop(int, const void *, char *, size_t); #endif /* Although the buffer size needed depends on the prefixes, "%u" may generate "4294967295". */ diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h index ecd1dfd4ef..352da8c56e 100644 --- a/ext/socket/rubysocket.h +++ b/ext/socket/rubysocket.h @@ -430,4 +430,12 @@ static inline void rsock_maybe_wait_fd(int fd) { } # define MSG_DONTWAIT_RELIABLE 0 #endif +#if !defined HAVE_INET_NTOP && ! defined _WIN32 +const char *inet_ntop(int, const void *, char *, size_t); +#elif defined __MINGW32__ +# define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l) +#elif defined _MSC_VER && RUBY_MSVCRT_VERSION < 90 +const char *WSAAPI inet_ntop(int, const void *, char *, size_t); +#endif + #endif -- cgit v1.2.3