muduo
muduo copied to clipboard
gethostbyname_r ?
Why not use getaddrinfo instead of gethostbyname_r ?
I guess for MT-safe.
https://man7.org/linux/man-pages/man3/gethostbyname_r.3.html#ATTRIBUTES
┌───────────────────┬───────────────┬───────────────────────────────┐
│Interface │ Attribute │ Value │
├───────────────────┼───────────────┼───────────────────────────────┤
│gethostbyname() │ Thread safety │ MT-Unsafe race:hostbyname env │
│ │ │ locale │
├───────────────────┼───────────────┼───────────────────────────────┤
│gethostbyaddr() │ Thread safety │ MT-Unsafe race:hostbyaddr env │
│ │ │ locale │
├───────────────────┼───────────────┼───────────────────────────────┤
│sethostent(), │ Thread safety │ MT-Unsafe race:hostent env │
│endhostent(), │ │ locale │
│gethostent_r() │ │ │
├───────────────────┼───────────────┼───────────────────────────────┤
│herror(), │ Thread safety │ MT-Safe │
│hstrerror() │ │ │
├───────────────────┼───────────────┼───────────────────────────────┤
│gethostent() │ Thread safety │ MT-Unsafe race:hostent │
│ │ │ race:hostentbuf env locale │
├───────────────────┼───────────────┼───────────────────────────────┤
│gethostbyname2() │ Thread safety │ MT-Unsafe race:hostbyname2 │
│ │ │ env locale │
├───────────────────┼───────────────┼───────────────────────────────┤
│gethostbyaddr_r(), │ Thread safety │ MT-Safe env locale │
│gethostbyname_r(), │ │ │
│gethostbyname2_r() │ │ │
└───────────────────┴───────────────┴───────────────────────────────┘
The same page also says:
The gethostbyname*(), gethostbyaddr*(), herror(), and hstrerror()
functions are obsolete. Applications should use [getaddrinfo(3)](https://man7.org/linux/man-pages/man3/getaddrinfo.3.html),
[getnameinfo(3)](https://man7.org/linux/man-pages/man3/getnameinfo.3.html), and [gai_strerror(3)](https://man7.org/linux/man-pages/man3/gai_strerror.3.html) instead.
and getaddrinfo(3)
is also MT-Safe env locale
.