Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Berkeley sockets
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Berkeley sockets
(section)
Add topic