[Python-de] socket.create_connection() ipv4 oder ipv6?

Julian Gethmann mail.python.org at gethmann.org
Di Jun 25 09:42:00 EDT 2019


Hi,

bei mir liefert

 >>> sock.family 
 

<AddressFamily.AF_INET6: 10>

zurück. Ein Blick in die Python-Quellen zeigt, dass getaddrinfo benutzt 
wird, welches auch sowohl v6, als auch v4 zurück liefert.
Ich denke, dass die Betriebssystem-Funktionen genutzt werden, sprich auf 
aktuellen Linux, Mac und Windows v6 priorisiert wird (afaik).

Hoffentlich hilft das schon mal ein bisschen weiter. Nach 
"socket.getaddrinfo??" kommt dann C-code ;)


Mit freundlichen Grüßen,
Julian Gethmann

On 25/06/2019 15.16, Ulli Horlacher wrote:
> Peter Heitzer <peter.heitzer at rz.uni-regensburg.de> wrote:
> 
>>>   sock = socket.create_connection(('flupp.belwue.de',591))
>>
>>> bekomme ich einen tcp Link. Das funktioniert.
>>
>>> In der Doku steht dazu:
>>
>>> https://docs.python.org/3/library/socket.html
>>
>>>   Connect to a TCP service listening on the Internet address (a 2-tuple
>>>   (host, port)), and return the socket object. This is a higher-level
>>>   function than socket.connect(): if host is a non-numeric hostname, it
>>>   will try to resolve it for both AF_INET and AF_INET6, and then try to
>>>   connect to all possible addresses in turn until a connection succeeds.
>>
>>
>>> flupp.belwue.de hat sowohl ipv4 als auch ipv6 Adresse.
>>> Welche wird genommen und warum?
>>
>> In der Doku steht auch:
>> To use create_connection() to connect to a IPv6 address the server socket also should have been created using the address family AF_INET6.
>> Ich verstehe das so, daß du wenn du den Socket mit AF_INET erzeugt hast,
>> nur eine V4 Auflösung gemacht wird und bei Erzeugen mit AF_INET6 nur
>> eine V6 Auflösung. Der Socket kann ja nur entweder V4 oder V6 sein.
>> Der Default für socket.socket ist AF_INET, also wird wohl eine V4 Adresse
>> genommen.
> 
> Ich hab nichts (mehr) gemacht als:
> 
>    sock = socket.create_connection(('flupp.belwue.de',591))
> 
> Ich hab also weder AF_INET noch AF_INET6 angegeben.
> 
> Genau DAS ist ja meine Frage: was passiert, wenn ich nichts angebe?
> 
> 


Mehr Informationen über die Mailingliste python-de