@@ -920,7 +920,9 @@ The :mod:`socket` module also offers various network-related services:
920920
921921 .. versionadded :: 3.7
922922
923- .. function :: getaddrinfo(host, port, family=0, type=0, proto=0, flags=0)
923+ .. function :: getaddrinfo(host, port, family=AF_UNSPEC, type=0, proto=0, flags=0)
924+
925+ This function wraps the C function ``getaddrinfo `` of the underlying system.
924926
925927 Translate the *host */*port * argument into a sequence of 5-tuples that contain
926928 all the necessary arguments for creating a socket connected to that service.
@@ -930,8 +932,10 @@ The :mod:`socket` module also offers various network-related services:
930932 and *port *, you can pass ``NULL `` to the underlying C API.
931933
932934 The *family *, *type * and *proto * arguments can be optionally specified
933- in order to narrow the list of addresses returned. Passing zero as a
934- value for each of these arguments selects the full range of results.
935+ in order to provide options and limit the list of addresses returned.
936+ Pass their default values (:data: `AF_UNSPEC `, 0, and 0, respectively)
937+ to not limit the results. See the note below for details.
938+
935939 The *flags * argument can be one or several of the ``AI_* `` constants,
936940 and will influence how results are computed and returned.
937941 For example, :const: `AI_NUMERICHOST ` will disable domain name resolution
@@ -951,6 +955,29 @@ The :mod:`socket` module also offers various network-related services:
951955 :const: `AF_INET6 `), and is meant to be passed to the :meth: `socket.connect `
952956 method.
953957
958+ .. note ::
959+
960+ If you intend to use results from :func: `!getaddrinfo ` to create a socket
961+ (rather than, for example, retrieve *canonname *),
962+ consider limiting the results by *type * (e.g. :data: `SOCK_STREAM ` or
963+ :data: `SOCK_DGRAM `) and/or *proto * (e.g. :data: `IPPROTO_TCP ` or
964+ :data: `IPPROTO_UDP `) that your application can handle.
965+
966+ The behavior with default values of *family *, *type *, *proto *
967+ and *flags * is system-specific.
968+
969+ Many systems (for example, most Linux configurations) will return a sorted
970+ list of all matching addresses.
971+ These addresses should generally be tried in order until a connection succeeds
972+ (possibly tried in parallel, for example, using a `Happy Eyeballs `_ algorithm).
973+ In these cases, limiting the *type * and/or *proto * can help eliminate
974+ unsuccessful or unusable connecton attempts.
975+
976+ Some systems will, however, only return a single address.
977+ (For example, this was reported on Solaris and AIX configurations.)
978+ On these systems, limiting the *type * and/or *proto * helps ensure that
979+ this address is usable.
980+
954981 .. audit-event :: socket.getaddrinfo host,port,family,type,protocol socket.getaddrinfo
955982
956983 The following example fetches address information for a hypothetical TCP
@@ -970,6 +997,8 @@ The :mod:`socket` module also offers various network-related services:
970997 for IPv6 multicast addresses, string representing an address will not
971998 contain ``%scope_id `` part.
972999
1000+ .. _Happy Eyeballs : https://en.wikipedia.org/wiki/Happy_Eyeballs
1001+
9731002.. function :: getfqdn([name])
9741003
9751004 Return a fully qualified domain name for *name *. If *name * is omitted or empty,
0 commit comments