Order of addresses returned by socket.gethostbyname_ex()
tjreedy at udel.edu
Mon Aug 22 19:34:57 CEST 2011
On 8/22/2011 7:39 AM, Tomas Lidén wrote:
> On 22 Aug, 13:26, Roy Smith<r... at panix.com> wrote:
>> In article
>> <356978ef-e9c1-48fd-bb87-849fe8e27... at p5g2000vbl.googlegroups.com>,
>> Tomas Lidén<to... at liden-privat.net> wrote:
>>> In what order are the addresses returned by socket.gethostbyname_ex()?
>>> We know that gethostbyname() is indeterministic but hope that
>>> gethostbyname_ex() has a specified order.
>> Why would you hope that? Or maybe a better question is, why would you
>> expect that? In general, all name resolution calls return results in
>> arbitrary order. In some cases, results are intentionally changed on
>> every call (i.e. round-robin) in an attempt at load sharing.
>> What kind of ordering were you hoping for?
> See previous posts.
> Basically I was asking about the contract for this method..
The doc "Return a triple (hostname, aliaslist, ipaddrlist) where
hostname is the primary host name responding to the given ip_address,
aliaslist is a (possibly empty) list of alternative host names for the
same address, and ipaddrlist is a list of IPv4/v6 addresses for the same
interface on the same host (most likely containing only a single address)."
> hoping that it is deterministic.
As far as I can see, that is not in the contract.
> Our testing indicated that the interfaces are returned in a specific
> order, but we want to know if this is really the case (on all
Even if it were so now, a patch could change things.
Terry Jan Reedy
More information about the Python-list