Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gethostbyname_r ? #504

Open
gh2517956473 opened this issue Mar 8, 2021 · 2 comments
Open

gethostbyname_r ? #504

gh2517956473 opened this issue Mar 8, 2021 · 2 comments

Comments

@gh2517956473
Copy link

Why not use getaddrinfo instead of gethostbyname_r ?

@DigGe
Copy link

DigGe commented Nov 25, 2021

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() │               │                               │
└───────────────────┴───────────────┴───────────────────────────────┘

@ericonr
Copy link

ericonr commented Sep 5, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants