summaryrefslogtreecommitdiff
path: root/ext/socket/getnameinfo.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-05-07 08:24:37 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-05-07 08:24:37 +0000
commit3376271d9e3c6b96acb63720eb4d59643abeb32c (patch)
tree9a9d174d90329951c082fb46e950a8edcdb001b8 /ext/socket/getnameinfo.c
parentc09a226803d177f2ab3426ec2c72a3186d789010 (diff)
990507
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/getnameinfo.c')
-rw-r--r--ext/socket/getnameinfo.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/ext/socket/getnameinfo.c b/ext/socket/getnameinfo.c
index e217b50895..e4a57c6554 100644
--- a/ext/socket/getnameinfo.c
+++ b/ext/socket/getnameinfo.c
@@ -83,16 +83,23 @@ struct sockinet {
#define ENI_SALEN 6
#ifndef HAVE_INET_NTOP
-static char *
+static const char *
inet_ntop(af, addr, numaddr, numaddr_len)
int af;
- char *addr;
+ __const void *addr;
char *numaddr;
- int numaddr_len;
+ size_t numaddr_len;
{
+#ifdef HAVE_INET_NTOA
struct in_addr in;
memcpy(&in.s_addr, addr, sizeof(in.s_addr));
- strcpy(numaddr, inet_ntoa(in));
+ strncpy(numaddr, numaddr_len, 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