Subject: Re: bug#23615: 25.1.50; Which platforms can safely use getsockopt(,,SO_ERROR,,)?

From: Ken Brown <[email-masked]>
Date: Thu, 2 Jun 2016 13:55:14 -0400

On 6/2/2016 1:17 PM, Ken Brown wrote:
> On 6/2/2016 12:00 PM, Paul Eggert wrote:
>> On Solaris 10 on a host with only IPv4 configured, socket_test.c fails
>> with the diagnostic "Can't start server." 'truss' says connect(3,
>> 0x00021EE8, 16, SOV_DEFAULT) failed with errno == EOPNOTSUPP.
>>
>> On Solaris 11 with both IPv4 and IPv6, the same symptoms except errno ==
>> EADDRNOTAVAIL.
>
> Thanks for testing.  This means that my test program is not portable
> enough to answer the question in the subject; the failure occurred
> before the program reached the getsockopt call.  I'll see if I can fix
> that.

I wonder if the problem was calling 'connect' after calling 'listen'. 
Eli pointed out that this doesn't work on MS-Windows, and in any case I 
can't see why it would ever be needed.  (I only did it because the code 
in process.c that I was imitating did it.)

Does the following help?

--- socket_test.c~      2016-05-25 21:27:46.000000000 -0400
+++ socket_test.c       2016-06-02 13:47:52.719883900 -0400
@@ -122,6 +122,7 @@
             return -1;
           }
           *pservice = ntohs (sa.sin_port);
+         ret = 0;
         }
        else
         /* Nonblocking client.  */
@@ -132,8 +133,8 @@
               s = -1;
               continue;
             }
+         ret = connect (s, rp->ai_addr, rp->ai_addrlen);
         }
-      ret = connect (s, rp->ai_addr, rp->ai_addrlen);
        if (ret == 0 || errno == EISCONN)
         break;
        if (!server && errno == EINPROGRESS)