@@ -928,7 +928,9 @@ The :mod:`socket` module also offers various network-related services:
928928
929929 .. versionadded :: 3.7
930930
931- .. function :: getaddrinfo(host, port, family=0, type=0, proto=0, flags=0)
931+ .. function :: getaddrinfo(host, port, family=AF_UNSPEC, type=0, proto=0, flags=0)
932+
933+ This function wraps the C function ``getaddrinfo `` of the underlying system.
932934
933935 Translate the *host */*port * argument into a sequence of 5-tuples that contain
934936 all the necessary arguments for creating a socket connected to that service.
@@ -938,8 +940,10 @@ The :mod:`socket` module also offers various network-related services:
938940 and *port *, you can pass ``NULL `` to the underlying C API.
939941
940942 The *family *, *type * and *proto * arguments can be optionally specified
941- in order to narrow the list of addresses returned. Passing zero as a
942- value for each of these arguments selects the full range of results.
943+ in order to provide options and limit the list of addresses returned.
944+ Pass their default values (:data: `AF_UNSPEC `, 0, and 0, respectively)
945+ to not limit the results. See the note below for details.
946+
943947 The *flags * argument can be one or several of the ``AI_* `` constants,
944948 and will influence how results are computed and returned.
945949 For example, :const: `AI_NUMERICHOST ` will disable domain name resolution
@@ -959,6 +963,29 @@ The :mod:`socket` module also offers various network-related services:
959963 :const: `AF_INET6 `), and is meant to be passed to the :meth: `socket.connect `
960964 method.
961965
966+ .. note ::
967+
968+ If you intend to use results from :func: `!getaddrinfo ` to create a socket
969+ (rather than, for example, retrieve *canonname *),
970+ consider limiting the results by *type * (e.g. :data: `SOCK_STREAM ` or
971+ :data: `SOCK_DGRAM `) and/or *proto * (e.g. :data: `IPPROTO_TCP ` or
972+ :data: `IPPROTO_UDP `) that your application can handle.
973+
974+ The behavior with default values of *family *, *type *, *proto *
975+ and *flags * is system-specific.
976+
977+ Many systems (for example, most Linux configurations) will return a sorted
978+ list of all matching addresses.
979+ These addresses should generally be tried in order until a connection succeeds
980+ (possibly tried in parallel, for example, using a `Happy Eyeballs `_ algorithm).
981+ In these cases, limiting the *type * and/or *proto * can help eliminate
982+ unsuccessful or unusable connecton attempts.
983+
984+ Some systems will, however, only return a single address.
985+ (For example, this was reported on Solaris and AIX configurations.)
986+ On these systems, limiting the *type * and/or *proto * helps ensure that
987+ this address is usable.
988+
962989 .. audit-event :: socket.getaddrinfo host,port,family,type,protocol socket.getaddrinfo
963990
964991 The following example fetches address information for a hypothetical TCP
@@ -978,6 +1005,8 @@ The :mod:`socket` module also offers various network-related services:
9781005 for IPv6 multicast addresses, string representing an address will not
9791006 contain ``%scope_id `` part.
9801007
1008+ .. _Happy Eyeballs : https://en.wikipedia.org/wiki/Happy_Eyeballs
1009+
9811010.. function :: getfqdn([name])
9821011
9831012 Return a fully qualified domain name for *name *. If *name * is omitted or empty,
0 commit comments