Documente Academic
Documente Profesional
Documente Cultură
Conversions
Domain name system
gethostbyname Function
gethostbyname2 Function and IPv6
support
gethostbyaddr Function
uname and gethostname Functions
getservbyname and getservbyport
Functions
Other networking information
1
Introduction DNS
1. What is
the IP address
of udel.edu ?
It is
128.175.13.92
1. What is
the host name
of
128.175.13.74
It is
strauss.udel.edu
2
DNS
Components
Resolvers:
Client programs that extract information from
Name Servers.
Name Servers:
Server programs which hold information about
the structure and the names.
Resolve
rs
A Resolver maps a name to an address and
vice versa.
Query
Response
Resolver
Name Server
Iterative
Resolution
a.root
server
a3.nstl
d.com
a.gtldserver
udel
server
ns1.goo
gle.com
7
iterative response (referral)
I don't know. Try a.root-servers.net.
iterative response (referral)
9
I don't know. Try a.gtld-servers.net.
1 iterative response (referral)
iterative response (referral)
I don't know. Try a3.nstld.com.
2 4
I don't know. Try ns1.google.com.
6
iterative response
8
The IP address of www.google.com
is 216.239.37.99.
client 10
iterative request
What is the IP address of
5
www.google.com?
3
Recursive
Resolution
root
server
edu
server
udel
serve
r
com
3
8
server
google
server
9
1
10
client
recursive request
What is the IP address of
www.google.com?
recursive response
The IP address of www.google.com is
216.239.37.99.
e.g.
A
206.62.226.33
AAAA 5f1b:df00:ce3e:e200:0020:0800:2078:e3e3
MX
5 solaris.kohala.com
MX
10 mailhost.kohala.com
PTR
33.226.62.206.in-addr.arpa
CNAME bsdi.kohala.com
7
other
name
servers
resolver functions:
gethostbyname/gethostbyaddr
name server: BIND
(Berkeley Internet Name Domain)
static hosts files (DNS alternatives):
/etc/hosts
resolver configuration file (specifies name serve
/etc/resolv.conf
8
gethostbyname Function
performs a DNS query for an A record or a AAAA record
#include <netdb.h>
struct hostent *gethostbyname (const char *hostname);
returns: nonnull pointer if OK, NULL on error with h_err
struct hostent {
char *h_name;
/* official (canonical) name of host *
char **h_aliases; /* ptr to array of ptrs to alias names
/ *A list of aliases that can be accessed with arrays*/
int
h_addrtype; /* host addr type: AF_INET or AF_INE
int
h_length;
/* length of address: 4 or 16 */
char **h_addr_list;
/* ptr to array of ptrs with IPv
};
#define h_addr h_addr_list[0] /* first address in list */
canonical hostname \0
alias #1 \0
NULL
NULL
alias #2 \0
in/6_addr { }
IP addr #1
in/6_addr { }
IP addr #2
in/6_addr { }
IP addr #3
10
11
#include <netdb.h>
struct hostent *gethostbyname2 (const char *hostname, int family
returns: nonnull pointer if oK, NULL on error with h_errno se
gethostbyname
(host)
gethostbyname2
(host, AF_INET)
gethostbyname2
(host, AF_INET6)
RES_USE_INET6 option
of
on
A record
AAAA record
or A record returning
IPv4-mapped IPv6 addr
A record
A record returning
IPv4-mapped IPv6 addr
AAAA record AAAA record
13
gethostbyaddr Function
binary IP address to hostent structure
#include <netdb.h>
struct hostent *gethostbyaddr (const char *addr, size_t len
returns: nonnull pointer if OK, NULL on error with h_e
14
#include <sys/utsname.h>
Thegethostname() function shall return the standard host nam
the current
machine.
int uname (struct utsname *name);
returns: nonnegative value if OK, -1 on error
struct utsname {
char sysname[_UTS_NAMESIZE]; /* name of OS */
char nodename[_UTS_NODESIZE]; /* name of this node
char release[_UTS_NAMESIZE]; /* OS release level */
char version[_UTS_NAMESIZE]; /* OS version level */
char machine[_UTS_NAMESIZE]; /* hardware type */
#include <unistd.h>
int gethostname (char *name, size_t namelen);
returns: 0 if OK, -1 on error
15
#include <netdb.h>
struct servent *getservbyname (const char *servname, const
returns: nonnull pointer if OK, NULL on error
struct servent *getservbyport (int port, const char *protonam
returns: nonnull pointer if OK, NULL on error
struct servent {
char *s_name;
/* official service name */
char **s_aliases; /*alias list */
int
s_port;
/* port number, network-byte
char *s_proto;
/* protocol, TCP or UDP, to use */
17
daytime Client