[PATCH] Whitespace fixes in ext/Socket/Socket.{pm,xs}

--tsOsTdHNUZQcU9Ye
Content-Type: multipart/mixed; boundary="3MwIy2ne0vdjdPXF"
Content-Disposition: inline


--3MwIy2ne0vdjdPXF
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

The attached patch fixes whitespace in recent code added to
Socket.{xs,pm} to be consistent with the rest of the files. No
functionallity change.

--=20
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

--3MwIy2ne0vdjdPXF
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0001-Reindent-recent-IPv6-getaddrinfo-code-consistently-w.patch"
Content-Transfer-Encoding: quoted-printable

=46rom 720031cac4888192340eaeff3ac36286417353a4 Mon Sep 17 00:00:00 2001
=46rom: Paul "LeoNerd" Evans <leonerd@leonerd.org.uk>
Date: Mon, 24 Jan 2011 18:55:38 +0000
Subject: [PATCH 1/2] Reindent recent IPv6/getaddrinfo code consistently wit=
h the rest of the files

---
 ext/Socket/Socket.pm |  360 +++++++++++++++++++++++++---------------------=
----
 ext/Socket/Socket.xs |  294 ++++++++++++++++++++--------------------
 2 files changed, 327 insertions(+), 327 deletions(-)

diff --git a/ext/Socket/Socket.pm b/ext/Socket/Socket.pm
index c35509e..fb50216 100644
--- a/ext/Socket/Socket.pm
+++ b/ext/Socket/Socket.pm
@@ -584,49 +584,49 @@ XSLoader::load();
 my %errstr;
=20
 if( !defined &getaddrinfo ) {
-   require Scalar::Util;
-
-   *getaddrinfo =3D \&fake_getaddrinfo;
-   *getnameinfo =3D \&fake_getnameinfo;
-
-   # These numbers borrowed from GNU libc's implementation, but since
-   # they're only used by our emulation, it doesn't matter if the real
-   # platform's values differ
-   my %constants =3D (
-       AI_PASSIVE     =3D> 1,
-       AI_CANONNAME   =3D> 2,
-       AI_NUMERICHOST =3D> 4,
-       # RFC 2553 doesn't define this but Linux does - lets be nice and
-       # provide it since we can
-       AI_NUMERICSERV =3D> 1024,
-
-       EAI_BADFLAGS   =3D> -1,
-       EAI_NONAME     =3D> -2,
-       EAI_NODATA     =3D> -5,
-       EAI_FAMILY     =3D> -6,
-       EAI_SERVICE    =3D> -8,
-
-       NI_NUMERICHOST =3D> 1,
-       NI_NUMERICSERV =3D> 2,
-       NI_NAMEREQD    =3D> 8,
-       NI_DGRAM       =3D> 16,
-   );
-
-   foreach my $name ( keys %constants ) {
-      my $value =3D $constants{$name};
-
-      no strict 'refs';
-      defined &$name or *$name =3D sub () { $value };
-   }
-
-   %errstr =3D (
-      # These strings from RFC 2553
-      EAI_BADFLAGS()   =3D> "invalid value for ai_flags",
-      EAI_NONAME()     =3D> "nodename nor servname provided, or not known",
-      EAI_NODATA()     =3D> "no address associated with nodename",
-      EAI_FAMILY()     =3D> "ai_family not supported",
-      EAI_SERVICE()    =3D> "servname not supported for ai_socktype",
-   );
+    require Scalar::Util;
+
+    *getaddrinfo =3D \&fake_getaddrinfo;
+    *getnameinfo =3D \&fake_getnameinfo;
+
+    # These numbers borrowed from GNU libc's implementation, but since
+    # they're only used by our emulation, it doesn't matter if the real
+    # platform's values differ
+    my %constants =3D (
+	AI_PASSIVE     =3D> 1,
+	AI_CANONNAME   =3D> 2,
+	AI_NUMERICHOST =3D> 4,
+	# RFC 2553 doesn't define this but Linux does - lets be nice and
+	# provide it since we can
+	AI_NUMERICSERV =3D> 1024,
+
+	EAI_BADFLAGS   =3D> -1,
+	EAI_NONAME     =3D> -2,
+	EAI_NODATA     =3D> -5,
+	EAI_FAMILY     =3D> -6,
+	EAI_SERVICE    =3D> -8,
+
+	NI_NUMERICHOST =3D> 1,
+	NI_NUMERICSERV =3D> 2,
+	NI_NAMEREQD    =3D> 8,
+	NI_DGRAM       =3D> 16,
+    );
+
+    foreach my $name ( keys %constants ) {
+	my $value =3D $constants{$name};
+
+	no strict 'refs';
+	defined &$name or *$name =3D sub () { $value };
+    }
+
+    %errstr =3D (
+	# These strings from RFC 2553
+	EAI_BADFLAGS()   =3D> "invalid value for ai_flags",
+	EAI_NONAME()     =3D> "nodename nor servname provided, or not known",
+	EAI_NODATA()     =3D> "no address associated with nodename",
+	EAI_FAMILY()     =3D> "ai_family not supported",
+	EAI_SERVICE()    =3D> "servname not supported for ai_socktype",
+    );
 }
=20
 # The following functions are used if the system does not have a
@@ -639,151 +639,151 @@ my $REGEXP_IPv4_DOTTEDQUAD =3D qr/$REGEXP_IPv4_DECI=
MAL\.$REGEXP_IPv4_DECIMAL\.$REG
=20
 sub fake_makeerr
 {
-   my ( $errno ) =3D @_;
-   my $errstr =3D $errno =3D=3D 0 ? "" : ( $errstr{$errno} || $errno );
-   return Scalar::Util::dualvar( $errno, $errstr );
+    my ( $errno ) =3D @_;
+    my $errstr =3D $errno =3D=3D 0 ? "" : ( $errstr{$errno} || $errno );
+    return Scalar::Util::dualvar( $errno, $errstr );
 }
=20
 sub fake_getaddrinfo
 {
-   my ( $node, $service, $hints ) =3D @_;
-
-   $node =3D "" unless defined $node;
-
-   $service =3D "" unless defined $service;
-
-   my ( $family, $socktype, $protocol, $flags ) =3D @$hints{qw( family soc=
ktype protocol flags )};
-
-   $family ||=3D Socket::AF_INET(); # 0 =3D=3D AF_UNSPEC, which we want too
-   $family =3D=3D Socket::AF_INET() or return fake_makeerr( EAI_FAMILY() );
-
-   $socktype ||=3D 0;
-
-   $protocol ||=3D 0;
-
-   $flags ||=3D 0;
-
-   my $flag_passive     =3D $flags & AI_PASSIVE();     $flags &=3D ~AI_PAS=
SIVE();
-   my $flag_canonname   =3D $flags & AI_CANONNAME();   $flags &=3D ~AI_CAN=
ONNAME();
-   my $flag_numerichost =3D $flags & AI_NUMERICHOST(); $flags &=3D ~AI_NUM=
ERICHOST();
-   my $flag_numericserv =3D $flags & AI_NUMERICSERV(); $flags &=3D ~AI_NUM=
ERICSERV();
-
-   $flags =3D=3D 0 or return fake_makeerr( EAI_BADFLAGS() );
-
-   $node eq "" and $service eq "" and return fake_makeerr( EAI_NONAME() );
-
-   my $canonname;
-   my @addrs;
-   if( $node ne "" ) {
-      return fake_makeerr( EAI_NONAME() ) if( $flag_numerichost and $node =
!~ m/^$REGEXP_IPv4_DOTTEDQUAD$/ );
-      ( $canonname, undef, undef, undef, @addrs ) =3D gethostbyname( $node=
 );
-      defined $canonname or return fake_makeerr( EAI_NONAME() );
-
-      undef $canonname unless $flag_canonname;
-   }
-   else {
-      $addrs[0] =3D $flag_passive ? Socket::inet_aton( "0.0.0.0" )
-                                : Socket::inet_aton( "127.0.0.1" );
-   }
-
-   my @ports; # Actually ARRAYrefs of [ socktype, protocol, port ]
-   my $protname =3D "";
-   if( $protocol ) {
-      $protname =3D getprotobynumber( $protocol );
-   }
-
-   if( $service ne "" and $service !~ m/^\d+$/ ) {
-      return fake_makeerr( EAI_NONAME() ) if( $flag_numericserv );
-      getservbyname( $service, $protname ) or return fake_makeerr( EAI_SER=
VICE() );
-   }
-
-   foreach my $this_socktype ( Socket::SOCK_STREAM(), Socket::SOCK_DGRAM()=
, Socket::SOCK_RAW() ) {
-      next if $socktype and $this_socktype !=3D $socktype;
-
-      my $this_protname =3D "raw";
-      $this_socktype =3D=3D Socket::SOCK_STREAM() and $this_protname =3D "=
tcp";
-      $this_socktype =3D=3D Socket::SOCK_DGRAM()  and $this_protname =3D "=
udp";
-
-      next if $protname and $this_protname ne $protname;
-
-      my $port;
-      if( $service ne "" ) {
-         if( $service =3D~ m/^\d+$/ ) {
-            $port =3D "$service";
-         }
-         else {
-            ( undef, undef, $port, $this_protname ) =3D getservbyname( $se=
rvice, $this_protname );
-            next unless defined $port;
-         }
-      }
-      else {
-         $port =3D 0;
-      }
-
-      push @ports, [ $this_socktype, scalar getprotobyname( $this_protname=
 ) || 0, $port ];
-   }
-
-   my @ret;
-   foreach my $addr ( @addrs ) {
-      foreach my $portspec ( @ports ) {
-         my ( $socktype, $protocol, $port ) =3D @$portspec;
-         push @ret, {
-            family    =3D> $family,
-            socktype  =3D> $socktype,
-            protocol  =3D> $protocol,
-            addr      =3D> Socket::pack_sockaddr_in( $port, $addr ),
-            canonname =3D> $canonname,
-         };
-      }
-   }
-
-   return ( fake_makeerr( 0 ), @ret );
+    my ( $node, $service, $hints ) =3D @_;
+
+    $node =3D "" unless defined $node;
+
+    $service =3D "" unless defined $service;
+
+    my ( $family, $socktype, $protocol, $flags ) =3D @$hints{qw( family so=
cktype protocol flags )};
+
+    $family ||=3D Socket::AF_INET(); # 0 =3D=3D AF_UNSPEC, which we want t=
oo
+    $family =3D=3D Socket::AF_INET() or return fake_makeerr( EAI_FAMILY() =
);
+
+    $socktype ||=3D 0;
+
+    $protocol ||=3D 0;
+
+    $flags ||=3D 0;
+
+    my $flag_passive     =3D $flags & AI_PASSIVE();     $flags &=3D ~AI_PA=
SSIVE();
+    my $flag_canonname   =3D $flags & AI_CANONNAME();   $flags &=3D ~AI_CA=
NONNAME();
+    my $flag_numerichost =3D $flags & AI_NUMERICHOST(); $flags &=3D ~AI_NU=
MERICHOST();
+    my $flag_numericserv =3D $flags & AI_NUMERICSERV(); $flags &=3D ~AI_NU=
MERICSERV();
+
+    $flags =3D=3D 0 or return fake_makeerr( EAI_BADFLAGS() );
+
+    $node eq "" and $service eq "" and return fake_makeerr( EAI_NONAME() );
+
+    my $canonname;
+    my @addrs;
+    if( $node ne "" ) {
+	return fake_makeerr( EAI_NONAME() ) if( $flag_numerichost and $node !~ m/=
^$REGEXP_IPv4_DOTTEDQUAD$/ );
+	( $canonname, undef, undef, undef, @addrs ) =3D gethostbyname( $node );
+	defined $canonname or return fake_makeerr( EAI_NONAME() );
+
+	undef $canonname unless $flag_canonname;
+    }
+    else {
+	$addrs[0] =3D $flag_passive ? Socket::inet_aton( "0.0.0.0" )
+				  : Socket::inet_aton( "127.0.0.1" );
+    }
+
+    my @ports; # Actually ARRAYrefs of [ socktype, protocol, port ]
+    my $protname =3D "";
+    if( $protocol ) {
+	$protname =3D getprotobynumber( $protocol );
+    }
+
+    if( $service ne "" and $service !~ m/^\d+$/ ) {
+	return fake_makeerr( EAI_NONAME() ) if( $flag_numericserv );
+	getservbyname( $service, $protname ) or return fake_makeerr( EAI_SERVICE(=
) );
+    }
+
+    foreach my $this_socktype ( Socket::SOCK_STREAM(), Socket::SOCK_DGRAM(=
), Socket::SOCK_RAW() ) {
+	next if $socktype and $this_socktype !=3D $socktype;
+
+	my $this_protname =3D "raw";
+	$this_socktype =3D=3D Socket::SOCK_STREAM() and $this_protname =3D "tcp";
+	$this_socktype =3D=3D Socket::SOCK_DGRAM()  and $this_protname =3D "udp";
+
+	next if $protname and $this_protname ne $protname;
+
+	my $port;
+	if( $service ne "" ) {
+	    if( $service =3D~ m/^\d+$/ ) {
+		$port =3D "$service";
+	    }
+	    else {
+		( undef, undef, $port, $this_protname ) =3D getservbyname( $service, $th=
is_protname );
+		next unless defined $port;
+	    }
+	}
+	else {
+	    $port =3D 0;
+	}
+
+	push @ports, [ $this_socktype, scalar getprotobyname( $this_protname ) ||=
 0, $port ];
+    }
+
+    my @ret;
+    foreach my $addr ( @addrs ) {
+	foreach my $portspec ( @ports ) {
+	    my ( $socktype, $protocol, $port ) =3D @$portspec;
+	    push @ret, {
+		family    =3D> $family,
+		socktype  =3D> $socktype,
+		protocol  =3D> $protocol,
+		addr      =3D> Socket::pack_sockaddr_in( $port, $addr ),
+		canonname =3D> $canonname,
+	    };
+	}
+    }
+
+    return ( fake_makeerr( 0 ), @ret );
 }
=20
 sub fake_getnameinfo
 {
-   my ( $addr, $flags ) =3D @_;
-
-   my ( $port, $inetaddr );
-   eval { ( $port, $inetaddr ) =3D Socket::unpack_sockaddr_in( $addr ) }
-      or return fake_makeerr( EAI_FAMILY() );
-
-   my $family =3D Socket::AF_INET();
-
-   $flags ||=3D 0;
-
-   my $flag_numerichost =3D $flags & NI_NUMERICHOST(); $flags &=3D ~NI_NUM=
ERICHOST();
-   my $flag_numericserv =3D $flags & NI_NUMERICSERV(); $flags &=3D ~NI_NUM=
ERICSERV();
-   my $flag_namereqd    =3D $flags & NI_NAMEREQD();    $flags &=3D ~NI_NAM=
EREQD();
-   my $flag_dgram       =3D $flags & NI_DGRAM()   ;    $flags &=3D ~NI_DGR=
AM();
-
-   $flags =3D=3D 0 or return fake_makeerr( EAI_BADFLAGS() );
-
-   my $node;
-   if( $flag_numerichost ) {
-      $node =3D Socket::inet_ntoa( $inetaddr );
-   }
-   else {
-      $node =3D gethostbyaddr( $inetaddr, $family );
-      if( !defined $node ) {
-         return fake_makeerr( EAI_NONAME() ) if $flag_namereqd;
-         $node =3D Socket::inet_ntoa( $inetaddr );
-      }
-   }
-
-   my $service;
-   if( $flag_numericserv ) {
-      $service =3D "$port";
-   }
-   else {
-      my $protname =3D $flag_dgram ? "udp" : "";
-      $service =3D getservbyport( $port, $protname );
-      if( !defined $service ) {
-         $service =3D "$port";
-      }
-   }
-
-   return ( fake_makeerr( 0 ), $node, $service );
+    my ( $addr, $flags ) =3D @_;
+
+    my ( $port, $inetaddr );
+    eval { ( $port, $inetaddr ) =3D Socket::unpack_sockaddr_in( $addr ) }
+	or return fake_makeerr( EAI_FAMILY() );
+
+    my $family =3D Socket::AF_INET();
+
+    $flags ||=3D 0;
+
+    my $flag_numerichost =3D $flags & NI_NUMERICHOST(); $flags &=3D ~NI_NU=
MERICHOST();
+    my $flag_numericserv =3D $flags & NI_NUMERICSERV(); $flags &=3D ~NI_NU=
MERICSERV();
+    my $flag_namereqd    =3D $flags & NI_NAMEREQD();    $flags &=3D ~NI_NA=
MEREQD();
+    my $flag_dgram       =3D $flags & NI_DGRAM()   ;    $flags &=3D ~NI_DG=
RAM();
+
+    $flags =3D=3D 0 or return fake_makeerr( EAI_BADFLAGS() );
+
+    my $node;
+    if( $flag_numerichost ) {
+	$node =3D Socket::inet_ntoa( $inetaddr );
+    }
+    else {
+	$node =3D gethostbyaddr( $inetaddr, $family );
+	if( !defined $node ) {
+	    return fake_makeerr( EAI_NONAME() ) if $flag_namereqd;
+	    $node =3D Socket::inet_ntoa( $inetaddr );
+	}
+    }
+
+    my $service;
+    if( $flag_numericserv ) {
+	$service =3D "$port";
+    }
+    else {
+	my $protname =3D $flag_dgram ? "udp" : "";
+	$service =3D getservbyport( $port, $protname );
+	if( !defined $service ) {
+	    $service =3D "$port";
+	}
+    }
+
+    return ( fake_makeerr( 0 ), $node, $service );
 }
=20
 1;
diff --git a/ext/Socket/Socket.xs b/ext/Socket/Socket.xs
index d91fcab..0dda808 100644
--- a/ext/Socket/Socket.xs
+++ b/ext/Socket/Socket.xs
@@ -223,183 +223,183 @@ not_here(const char *s)
 #ifdef HAS_GETADDRINFO
 static SV *err_to_SV(pTHX_ int err)
 {
-  SV *ret =3D sv_newmortal();
-  SvUPGRADE(ret, SVt_PVNV);
+	SV *ret =3D sv_newmortal();
+	SvUPGRADE(ret, SVt_PVNV);
=20
-  if(err) {
-    const char *error =3D gai_strerror(err);
-    sv_setpv(ret, error);
-  }
-  else {
-    sv_setpv(ret, "");
-  }
+	if(err) {
+		const char *error =3D gai_strerror(err);
+		sv_setpv(ret, error);
+	}
+	else {
+		sv_setpv(ret, "");
+	}
=20
-  SvIV_set(ret, err); SvIOK_on(ret);
+	SvIV_set(ret, err); SvIOK_on(ret);
=20
-  return ret;
+	return ret;
 }
=20
 static void xs_getaddrinfo(pTHX_ CV *cv)
 {
-    dVAR;
-    dXSARGS;
-
-    SV   *host;
-    SV   *service;
-    SV   *hints;
-
-    char *hostname =3D NULL;
-    char *servicename =3D NULL;
-    STRLEN len;
-    struct addrinfo hints_s;
-    struct addrinfo *res;
-    struct addrinfo *res_iter;
-    int err;
-    int n_res;
-
-    if(items > 3)
-      croak_xs_usage(cv, "host, service, hints");
-
-    SP -=3D items;
-
-    if(items < 1)
-      host =3D &PL_sv_undef;
-    else
-      host =3D ST(0);
-
-    if(items < 2)
-      service =3D &PL_sv_undef;
-    else
-      service =3D ST(1);
-
-    if(items < 3)
-      hints =3D NULL;
-    else
-      hints =3D ST(2);
-
-    SvGETMAGIC(host);
-    if(SvOK(host)) {
-      hostname =3D SvPV_nomg(host, len);
-      if (!len)
-        hostname =3D NULL;
-    }
-
-    SvGETMAGIC(service);
-    if(SvOK(service)) {
-      servicename =3D SvPV_nomg(service, len);
-      if (!len)
-        servicename =3D NULL;
-    }
-
-    Zero(&hints_s, sizeof hints_s, char);
-
-    if(hints && SvOK(hints)) {
-      HV *hintshash;
-      SV **valp;
-
-      if(!SvROK(hints) || SvTYPE(SvRV(hints)) !=3D SVt_PVHV)
-        croak("hints is not a HASH reference");
-
-      hintshash =3D (HV*)SvRV(hints);
-
-      if((valp =3D hv_fetch(hintshash, "flags", 5, 0)) !=3D NULL)
-        hints_s.ai_flags =3D SvIV(*valp);
-      if((valp =3D hv_fetch(hintshash, "family", 6, 0)) !=3D NULL)
-        hints_s.ai_family =3D SvIV(*valp);
-      if((valp =3D hv_fetch(hintshash, "socktype", 8, 0)) !=3D NULL)
-        hints_s.ai_socktype =3D SvIV(*valp);
-      if((valp =3D hv_fetch(hintshash, "protocol", 8, 0)) !=3D NULL)
-        hints_s.ai_protocol =3D SvIV(*valp);
-    }
-
-    err =3D getaddrinfo(hostname, servicename, &hints_s, &res);
-
-    XPUSHs(err_to_SV(aTHX_ err));
-
-    if(err)
-      XSRETURN(1);
-
-    n_res =3D 0;
-    for(res_iter =3D res; res_iter; res_iter =3D res_iter->ai_next) {
-      HV *res_hv =3D newHV();
-
-      (void)hv_stores(res_hv, "family",   newSViv(res_iter->ai_family));
-      (void)hv_stores(res_hv, "socktype", newSViv(res_iter->ai_socktype));
-      (void)hv_stores(res_hv, "protocol", newSViv(res_iter->ai_protocol));
-
-      (void)hv_stores(res_hv, "addr",     newSVpvn((char*)res_iter->ai_add=
r, res_iter->ai_addrlen));
-
-      if(res_iter->ai_canonname)
-        (void)hv_stores(res_hv, "canonname", newSVpv(res_iter->ai_canonnam=
e, 0));
-      else
-        (void)hv_stores(res_hv, "canonname", newSV(0));
-
-      XPUSHs(sv_2mortal(newRV_noinc((SV*)res_hv)));
-      n_res++;
-    }
-
-    freeaddrinfo(res);
-
-    XSRETURN(1 + n_res);
+	dVAR;
+	dXSARGS;
+
+	SV   *host;
+	SV   *service;
+	SV   *hints;
+
+	char *hostname =3D NULL;
+	char *servicename =3D NULL;
+	STRLEN len;
+	struct addrinfo hints_s;
+	struct addrinfo *res;
+	struct addrinfo *res_iter;
+	int err;
+	int n_res;
+
+	if(items > 3)
+		croak_xs_usage(cv, "host, service, hints");
+
+	SP -=3D items;
+
+	if(items < 1)
+		host =3D &PL_sv_undef;
+	else
+		host =3D ST(0);
+
+	if(items < 2)
+		service =3D &PL_sv_undef;
+	else
+		service =3D ST(1);
+
+	if(items < 3)
+		hints =3D NULL;
+	else
+		hints =3D ST(2);
+
+	SvGETMAGIC(host);
+	if(SvOK(host)) {
+		hostname =3D SvPV_nomg(host, len);
+		if (!len)
+			hostname =3D NULL;
+	}
+
+	SvGETMAGIC(service);
+	if(SvOK(service)) {
+		servicename =3D SvPV_nomg(service, len);
+		if (!len)
+			servicename =3D NULL;
+	}
+
+	Zero(&hints_s, sizeof hints_s, char);
+
+	if(hints && SvOK(hints)) {
+		HV *hintshash;
+		SV **valp;
+
+		if(!SvROK(hints) || SvTYPE(SvRV(hints)) !=3D SVt_PVHV)
+			croak("hints is not a HASH reference");
+
+		hintshash =3D (HV*)SvRV(hints);
+
+		if((valp =3D hv_fetch(hintshash, "flags", 5, 0)) !=3D NULL)
+			hints_s.ai_flags =3D SvIV(*valp);
+		if((valp =3D hv_fetch(hintshash, "family", 6, 0)) !=3D NULL)
+			hints_s.ai_family =3D SvIV(*valp);
+		if((valp =3D hv_fetch(hintshash, "socktype", 8, 0)) !=3D NULL)
+			hints_s.ai_socktype =3D SvIV(*valp);
+		if((valp =3D hv_fetch(hintshash, "protocol", 8, 0)) !=3D NULL)
+			hints_s.ai_protocol =3D SvIV(*valp);
+	}
+
+	err =3D getaddrinfo(hostname, servicename, &hints_s, &res);
+
+	XPUSHs(err_to_SV(aTHX_ err));
+
+	if(err)
+		XSRETURN(1);
+
+	n_res =3D 0;
+	for(res_iter =3D res; res_iter; res_iter =3D res_iter->ai_next) {
+		HV *res_hv =3D newHV();
+
+		(void)hv_stores(res_hv, "family",   newSViv(res_iter->ai_family));
+		(void)hv_stores(res_hv, "socktype", newSViv(res_iter->ai_socktype));
+		(void)hv_stores(res_hv, "protocol", newSViv(res_iter->ai_protocol));
+
+		(void)hv_stores(res_hv, "addr",     newSVpvn((char*)res_iter->ai_addr, r=
es_iter->ai_addrlen));
+
+		if(res_iter->ai_canonname)
+			(void)hv_stores(res_hv, "canonname", newSVpv(res_iter->ai_canonname, 0)=
);
+		else
+			(void)hv_stores(res_hv, "canonname", newSV(0));
+
+		XPUSHs(sv_2mortal(newRV_noinc((SV*)res_hv)));
+		n_res++;
+	}
+
+	freeaddrinfo(res);
+
+	XSRETURN(1 + n_res);
 }
 #endif
=20
 #ifdef HAS_GETNAMEINFO
 static void xs_getnameinfo(pTHX_ CV *cv)
 {
-    dVAR;
-    dXSARGS;
+	dVAR;
+	dXSARGS;
=20
-    SV  *addr;
-    int  flags;
+	SV  *addr;
+	int  flags;
=20
-    char host[1024];
-    char serv[256];
-    char *sa; /* we'll cast to struct sockaddr * when necessary */
-    STRLEN addr_len;
-    int err;
+	char host[1024];
+	char serv[256];
+	char *sa; /* we'll cast to struct sockaddr * when necessary */
+	STRLEN addr_len;
+	int err;
=20
-    if(items < 1 || items > 2)
-      croak_xs_usage(cv, "addr, flags=3D0");
+	if(items < 1 || items > 2)
+		croak_xs_usage(cv, "addr, flags=3D0");
=20
-    SP -=3D items;
+	SP -=3D items;
=20
-    addr =3D ST(0);
+	addr =3D ST(0);
=20
-    if(items < 2)
-      flags =3D 0;
-    else
-      flags =3D SvIV(ST(1));
+	if(items < 2)
+		flags =3D 0;
+	else
+		flags =3D SvIV(ST(1));
=20
-    if(!SvPOK(addr))
-      croak("addr is not a string");
+	if(!SvPOK(addr))
+		croak("addr is not a string");
=20
-    addr_len =3D SvCUR(addr);
+	addr_len =3D SvCUR(addr);
=20
-    /* We need to ensure the sockaddr is aligned, because a random SvPV mi=
ght
-     * not be due to SvOOK */
-    Newx(sa, addr_len, char);
-    Copy(SvPV_nolen(addr), sa, addr_len, char);
+	/* We need to ensure the sockaddr is aligned, because a random SvPV might
+	 * not be due to SvOOK */
+	Newx(sa, addr_len, char);
+	Copy(SvPV_nolen(addr), sa, addr_len, char);
 #ifdef HAS_SOCKADDR_SA_LEN
-    ((struct sockaddr *)sa)->sa_len =3D addr_len;
+	((struct sockaddr *)sa)->sa_len =3D addr_len;
 #endif
=20
-    err =3D getnameinfo((struct sockaddr *)sa, addr_len,
-      host, sizeof(host),
-      serv, sizeof(serv),
-      flags);
+	err =3D getnameinfo((struct sockaddr *)sa, addr_len,
+			host, sizeof(host),
+			serv, sizeof(serv),
+			flags);
=20
-    Safefree(sa);
+	Safefree(sa);
=20
-    XPUSHs(err_to_SV(aTHX_ err));
+	XPUSHs(err_to_SV(aTHX_ err));
=20
-    if(err)
-      XSRETURN(1);
+	if(err)
+		XSRETURN(1);
=20
-    XPUSHs(sv_2mortal(newSVpv(host, 0)));
-    XPUSHs(sv_2mortal(newSVpv(serv, 0)));
+	XPUSHs(sv_2mortal(newSVpv(host, 0)));
+	XPUSHs(sv_2mortal(newSVpv(serv, 0)));
=20
-    XSRETURN(3);
+	XSRETURN(3);
 }
 #endif
=20
--=20
1.7.2.3


--3MwIy2ne0vdjdPXF--

--tsOsTdHNUZQcU9Ye
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iD8DBQFNPcyUvLS2TC8cBo0RAm3UAKDynP44P+lLtveq/GzKRmJPa1odIQCg3ulK
LjiXOV64YLxvGowzsopTe/s=
=Z1ZR
-----END PGP SIGNATURE-----

--tsOsTdHNUZQcU9Ye--
0
leonerd
1/24/2011 7:01:40 PM
perl.perl5.porters 48287 articles. 1 followers. Follow

1 Replies
500 Views

Similar Articles

[PageSpeed] 56

--EP0wieDxd4TSJjHq
Content-Type: multipart/mixed; boundary="FsscpQKzF/jJk6ya"
Content-Disposition: inline


--FsscpQKzF/jJk6ya
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Following the previous patch, this patch fixes a small bug in the
pureperl emulation of getaddrinfo(3).

--=20
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

--FsscpQKzF/jJk6ya
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0002-canonname-should-only-be-present-on-the-first-return.patch"
Content-Transfer-Encoding: quoted-printable

=46rom 61fdece8ab9a729206f2633f47e25afd6f05af6a Mon Sep 17 00:00:00 2001
=46rom: Paul "LeoNerd" Evans <leonerd@leonerd.org.uk>
Date: Mon, 24 Jan 2011 18:58:40 +0000
Subject: [PATCH 2/2] canonname should only be present on the first returned=
 result

---
 ext/Socket/Socket.pm |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ext/Socket/Socket.pm b/ext/Socket/Socket.pm
index fb50216..3d32788 100644
--- a/ext/Socket/Socket.pm
+++ b/ext/Socket/Socket.pm
@@ -282,7 +282,8 @@ The address in a packed string (such as would be return=
ed by pack_sockaddr_in)
 =3Ditem canonname =3D> STRING
=20
 The canonical name for the host if the C<AI_CANONNAME> flag was provided, =
or
-C<undef> otherwise.
+C<undef> otherwise. This field will only be present on the first returned
+address.
=20
 =3Dback
=20
@@ -732,11 +733,16 @@ sub fake_getaddrinfo
 		socktype  =3D> $socktype,
 		protocol  =3D> $protocol,
 		addr      =3D> Socket::pack_sockaddr_in( $port, $addr ),
-		canonname =3D> $canonname,
+		canonname =3D> undef,
 	    };
 	}
     }
=20
+    # Only supply canonname for the first result
+    if( defined $canonname ) {
+	$ret[0]->{canonname} =3D $canonname;
+    }
+
     return ( fake_makeerr( 0 ), @ret );
 }
=20
--=20
1.7.2.3


--FsscpQKzF/jJk6ya--

--EP0wieDxd4TSJjHq
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iD8DBQFNPcz4vLS2TC8cBo0RAkdBAKCql2CmB43zKJyPXrC+Fq06jbsE1wCgr9DF
Yu4ddpf4ZU5QGO2WWc9+eXA=
=+jHV
-----END PGP SIGNATURE-----

--EP0wieDxd4TSJjHq--
0
leonerd
1/24/2011 7:03:20 PM
Reply: