Subject: | gethostbyname2 doesn't return aliases correctly |
gethostbyname2 returns a useless string for the aliases.
The included patch contains code that generates a useful string
by joining the list of aliases with spaces, just like gethostbyname
in the core.
Subject: | Socket6-gethostbyname2.diff |
diff -u -r Socket6-0.23/Socket6.xs Socket6-0.23-patched/Socket6.xs
--- Socket6-0.23/Socket6.xs 2008-08-16 16:47:00.000000000 +0000
+++ Socket6-0.23-patched/Socket6.xs 2008-11-10 23:21:27.000000000 +0000
@@ -441,14 +441,21 @@
#ifdef HAVE_GETHOSTBYNAME2
struct hostent *phe;
int count, i;
+ int acount;
+ SV *aliases;
if ((phe = gethostbyname2(host, af)) != NULL) {
for (count = 0; phe->h_addr_list[count]; ++count);
EXTEND(sp, 4 + count);
PUSHs(sv_2mortal(newSVpv((char *) phe->h_name,
strlen(phe->h_name))));
- PUSHs(sv_2mortal(newSVpv((char *) phe->h_aliases,
- sizeof(char *))));
+ aliases=newSVpv("",0);
+ for (acount=0; phe->h_aliases[acount]; acount++) {
+ if (acount>0)
+ sv_catpv(aliases," ");
+ sv_catpv(aliases,phe->h_aliases[acount]);
+ }
+ PUSHs(sv_2mortal(aliases));
PUSHs(sv_2mortal(newSViv((IV) phe->h_addrtype)));
PUSHs(sv_2mortal(newSViv((IV) phe->h_length)));
for (i = 0; i < count; ++i) {