Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Berkeley sockets
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===gethostbyname and gethostbyaddr=== The functions ''gethostbyname()'' and ''gethostbyaddr()'' are used to resolve host names and addresses in the [[domain name system]] or the local host's other resolver mechanisms (e.g., /etc/hosts lookup). They return a pointer to an object of type <var>struct hostent</var>, which describes an [[Internet Protocol]] host. The functions use the following arguments: * <var>name</var> specifies the name of the host. * <var>addr</var> specifies a pointer to a <var>struct in_addr</var> containing the address of the host. * <var>len</var> specifies the length, in bytes, of <var>addr</var>. * <var>type</var> specifies the address family type (e.g., AF_INET) of the host address. The functions return a NULL pointer in case of error, in which case the external integer {{mono|<var>h_errno</var>}} may be checked to see whether this is a temporary failure or an invalid or unknown host. Otherwise a valid <var>struct hostent *</var> is returned. These functions are not strictly a component of the BSD socket API, but are often used in conjunction with the API functions for looking up a host. These functions are now considered legacy interfaces for querying the domain name system. New functions that are completely protocol-agnostic (supporting IPv6) have been defined. These new functions are [[getaddrinfo|getaddrinfo() and getnameinfo()]], and are based on a new ''[[addrinfo]]'' data structure.<ref>POSIX.1-2004</ref> This pair of functions appeared at the same time as the BSD socket API proper in 4.2BSD (1983),<ref>{{man|3|gethostbyname|FreeBSD}}</ref> the same year DNS was first created. Early versions did not query DNS and only performed /etc/hosts lookup. The 4.3BSD (1984) version added DNS in a crude way. The current implementation using [[Name Service Switch]] derives Solaris and later NetBSD 1.4 (1999).<ref name="Conill">{{cite web |last1=Conill |first1=Ariadne |title=the tragedy of gethostbyname |url=https://ariadne.space/2022/03/27/the-tragedy-of-gethostbyname/ |website=ariadne.space |date=March 27, 2022}}</ref> Initially defined for [[NIS+]], NSS makes DNS only one of the many options for lookup by these functions and its use can be disabled even today.<ref>{{man|5|nsswitch.conf|FreeBSD}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)