calls to socket() fail when calling getaddrinfo() with IPPROTO_TCP

Corinna Vinschen corinna-cygwin@cygwin.com
Fri Jul 30 10:47:39 GMT 2021


On Jul 30 11:34, Corinna Vinschen via Cygwin wrote:
> Yeah, that's a bad joke as well.  The reason is that the http service is
> defined for TCP only.  Not for UDP.  As a result, Windows' getaddrinfo
> suddenly returns a valid ai_socktype field:
> 
>   family: 23 socktype 1 protocol 6	AF_INET6, STREAM, TCP
>   family: 2 socktype 1 protocol 6	AF_INET,  STREAM, TCP

Just to be precise here, the fact that ai_protocol is IPPROTO_TCP
in this example output is only because of your hints.  If you don't
restrict ai_protocol, you'll get:

    family: 23 socktype 1 protocol 0	AF_INET6, STREAM, any
    family: 2 socktype 1 protocol 0	AF_INET,  STREAM, any

> Cygwin implements a shallow (~300 lines) wrapper over the WinSock
> GetAddrInfoW function and otherwise relies on the values returned by the
> OS.  However, it already duplicates the returned list to self-allocated
> memory, which is required for fork(2) semantics.  It should be possible
> to improve the wrapper to duplicate entries with socktype and protocol
> 0-entries, but that would be in the next Cygwin version earliest.

I hacked up a patch which is supposed to do exactly that.  In your case
it now returns

  family: 23 socktype 1 protocol 6
  family: 2 socktype 1 protocol 6

and in case you omit the ai_protocol restriction it returns with

  family: 23 socktype 1 protocol 6
  family: 23 socktype 2 protocol 17
  family: 2 socktype 1 protocol 6
  family: 2 socktype 2 protocol 17

rather than with

  family: 23 socktype 0 protocol 0
  family: 2 socktype 0 protocol 0

I've uploaded a new developer snapshot to https://cygwin.com/snapshots

Please give it a try and report back.


Thanks,
Corinna


More information about the Cygwin mailing list