This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
A clearer layout for the fall-through logic of Socket::inet_aton()
authorNicholas Clark <nick@ccl4.org>
Sun, 6 Mar 2011 10:31:23 +0000 (10:31 +0000)
committerNicholas Clark <nick@ccl4.org>
Sun, 6 Mar 2011 10:31:23 +0000 (10:31 +0000)
ext/Socket/Socket.xs

index 3e81105..9214fc1 100644 (file)
@@ -423,15 +423,19 @@ inet_aton(host)
        {
        struct in_addr ip_address;
        struct hostent * phe;
-       int ok = (*host != '\0') && inet_aton(host, &ip_address);
 
-       if (!ok && (phe = gethostbyname(host)) &&
-                       phe->h_addrtype == AF_INET && phe->h_length == 4) {
-               Copy( phe->h_addr, &ip_address, phe->h_length, char );
-               ok = 1;
+       if ((*host != '\0') && inet_aton(host, &ip_address)) {
+               ST(0) = newSVpvn_flags((char *)&ip_address, sizeof ip_address, SVs_TEMP);
+               XSRETURN(1);
+       }
+
+       phe = gethostbyname(host);
+       if (phe && phe->h_addrtype == AF_INET && phe->h_length == 4) {
+               ST(0) = newSVpvn_flags((char *)phe->h_addr, phe->h_length, SVs_TEMP);
+               XSRETURN(1);
        }
 
-       ST(0) = newSVpvn_flags(ok ? (char *)&ip_address : NULL, sizeof ip_address, SVs_TEMP);
+       XSRETURN_UNDEF;
        }
 
 void