Menu

#54 Avoid gethostbyname in favor of getnameinfo

None
open
None
5
2017-10-27
2017-10-27
No

http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap03.html:

gethostbyaddr(), gethostbyname()
Applications are recommended to use the getaddrinfo() and getnameinfo() functions instead of these functions.
The gethostbyaddr() and gethostbyname() functions may return pointers to static data, which may be overwritten by subsequent calls to any of these functions. The suggested replacements do not have this problem and are also IPv6-capable.

Discussion

  • Bruno Haible

    Bruno Haible - 2017-10-27

    This would be one way to making socket.d multithread-safe. But it is quite a major rewrite of socket.d.
    The other way is to just use gethostbyname_r (on glibc) or locking (on the other platforms).

     
  • Sam Steingold

    Sam Steingold - 2017-10-27

    I think locking is a relatively expensive operation (OTOH, it is probably cheap compared to gethostbyname and friends).
    btw, are there platforms without getaddrinfo and getnameinfo?

     
    • Bruno Haible

      Bruno Haible - 2017-10-27

      > are there platforms without getaddrinfo and getnameinfo?
      Yes, but we would obviously use the gnulib replacement: https://www.gnu.org/software/gnulib/manual/html_node/getnameinfo.html

       
  • Sam Steingold

    Sam Steingold - 2017-10-27
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,4 @@
    -http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap03.html:
    +<http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap03.html>:
     > gethostbyaddr(), gethostbyname()
     > Applications are recommended to use the getaddrinfo() and getnameinfo() functions instead of these functions.
     > The gethostbyaddr() and gethostbyname() functions may return pointers to static data, which may be overwritten by subsequent calls to any of these functions. The suggested replacements do not have this problem and are also IPv6-capable.
    
    • Group: -->
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.