From fb672259d926027f4af16847a1aafe8c81506625 Mon Sep 17 00:00:00 2001 From: tarui Date: Mon, 31 Jan 2011 17:31:18 +0000 Subject: [PATCH] * include/ruby/win32.h, win32/win32.c: add rb_w32_inet_ntop. inet_ntop's minimum supported client is Vista. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ include/ruby/win32.h | 4 ++++ win32/win32.c | 16 ++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0d0de1fc9e..925748939b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Feb 1 02:28:14 2011 Masaya Tarui + + * include/ruby/win32.h, win32/win32.c: add rb_w32_inet_ntop. + inet_ntop's minimum supported client is Vista. + Tue Feb 1 00:10:30 2011 NARUSE, Yui * lib/benchmark.rb: fix benchmarck to work with current ruby. diff --git a/include/ruby/win32.h b/include/ruby/win32.h index fac83d4d07..9b1c46de18 100644 --- a/include/ruby/win32.h +++ b/include/ruby/win32.h @@ -267,6 +267,7 @@ extern int rb_w32_urename(const char *, const char *); extern char **rb_w32_get_environ(void); extern void rb_w32_free_environ(char **); extern int rb_w32_map_errno(DWORD); +extern char * WSAAPI rb_w32_inet_ntop(int,void *,char *,size_t); extern int chown(const char *, int, int); extern int rb_w32_uchown(const char *, int, int); @@ -542,6 +543,9 @@ extern char *rb_w32_strerror(int); #define FD_ISSET(f, s) rb_w32_fdisset(f, s) #ifdef RUBY_EXPORT +#undef inet_ntop +#define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l) + #undef accept #define accept(s, a, l) rb_w32_accept(s, a, l) diff --git a/win32/win32.c b/win32/win32.c index 6366d921ed..ef7acce6ca 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -5687,3 +5687,19 @@ signbit(double x) return *ip < 0; } #endif + +char * WSAAPI +rb_w32_inet_ntop(int af, void *addr, char *numaddr, size_t numaddr_len) +{ + typedef char *(WSAAPI inet_ntop_t)(int, void *, char *, size_t); + inet_ntop_t *pInetNtop; + pInetNtop = (inet_ntop_t *)get_proc_address("ws2_32", "inet_ntop", NULL); + if(pInetNtop){ + return pInetNtop(af,addr,numaddr,numaddr_len); + }else{ + struct in_addr in; + memcpy(&in.s_addr, addr, sizeof(in.s_addr)); + snprintf(numaddr, numaddr_len, "%s", inet_ntoa(in)); + } + return numaddr; +}