Page MenuHomePhabricator

Remove call to obsolete gethostbyname, using getaddrinfo
ClosedPublic

Authored by serge-sans-paille on Thu, Sep 5, 9:59 AM.

Details

Summary

From the man page:

The gethostbyname*() and gethostbyaddr*() functions are obsolete.
Applications should use getaddrinfo(3) and getnameinfo(3) instead.

That's what I did, using the canonical name as a relevant entry, which looks like the closer match to the original call.

Diff Detail

Repository
rL LLVM

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptThu, Sep 5, 9:59 AM
labath accepted this revision.Fri, Sep 6, 1:43 AM
labath added a subscriber: labath.

Sounds like a good idea, particularly as gethostbyname is not thread safe. It seems getaddrinfo is already used in lldb, so it should be supported by all OSs that we care about.

This revision is now accepted and ready to land.Fri, Sep 6, 1:43 AM
Closed by commit rL371195: Remove call to obsolete gethostbyname, using getaddrinfo (authored by serge_sans_paille, committed by ). · Explain WhyFri, Sep 6, 4:06 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFri, Sep 6, 4:06 AM

This code is trying too hard and failing. Either the result of gethostname() is canonical or it is not. If it is not, then trying to canonicalize it is – for various reasons – a lost cause. For example, a given machine might have multiple network interfaces with multiple addresses per interface, each with a different canonical name. Separably, the result of HostInfoPosix::GetHostname() and latency thereof shouldn't depend on whether networking is up or down or what network the machine happened to be attached to at any given moment (like a laptop that travels between work and home).

@davezarzycki I tend to agree with you. We can just remove 35:44 and just keep the hostname.

@davezarzycki I tend to agree with you. We can just remove 35:44 and just keep the hostname.

sounds good to me

Great. See: r371596