• Topics: – DNS system – Gathering machine information

advertisement
• Topics:
– DNS system
– Gathering machine information
• How to find out the machines ip address, name, OS, version,
etc.
• Name/Address conversion:
– The mapping between hostnames and IP addresses is
done by the domain name system (DNS)
– domain name system:
• A hierarchical, domain-based naming scheme and a distributed
database system
• Hierarchical naming scheme
– name space partitioned in subdomains.
– Top level of domains: .com .edu .gov .mil .org .net .cn .us .jp .nl
– Each domain can have subdomains
– Simple name .vs. fully qualified domain(absolute) name
• Distributed the delegation of naming authority
– Each domain has the authority to allow names within that
domain.
– naming follows organization boundary not physical network
boundary.
DNS servers
Root DNS Servers
com DNS servers
yahoo.com
amazon.com
DNS servers DNS servers
org DNS servers
pbs.org
DNS servers
edu DNS servers
poly.edu
umass.edu
DNS serversDNS servers
root DNS server
Iterative Queries
2
3
4
iterated query:
• contacted server replies
with name of server to
contact
• “I don’t know this name,
but ask this server”
TLD DNS server
5
local DNS server
dns.poly.edu
1
8
requesting host
7
6
authoritative DNS server
dns.cs.umass.edu
cis.poly.edu
gaia.cs.umass.edu
root DNS server
Recursive queries
2
recursive query:
• puts burden of name
resolution on
contacted name
server
• heavy load?
3
7
6
TLD DNS serve
local DNS server
dns.poly.edu
1
5
4
8
requesting host
authoritative DNS server
dns.cs.umass.edu
cis.poly.edu
gaia.cs.umass.edu
– Domain name system.
• Each server keeps resource records (RRs)
– Format: (domain_name, time to live, class, type, value)
– IP address, mail exchange, canonical name, host
description, other information
• Some relevant RR types:
– A : maps a hostname to an IPv4 address
– AAAA: maps a hostname to an IPv6 address
– PTR: pointer records, map IP addresses to hostnames
– MX: mail exchanger for a host
– CNAME: canonical name. Used to assign a CNAME
records for common services.
• Example:
Aix
Aix-4
ftp
www
IN
IN
IN
IN
IN
IN
IN
A 192.168.42.2
AAAA 3ffe:b80:1f8d:2:204:acff:fe17:bf38
MX 5 aix.unpbook.com.
MX 10 mailhost.unpbook.com.
A 192.168.42.2
CNAME linux.unpbook.com
CNAME linux.unpbook.com
–
The system calls that uses the DNS system:
•
–
gethostbyname, gethostbyaddr
gethostbyname: query on A records;
#include <netdb.h>
struct hostent *gethostbyname(const char *hostname)
struct hostent {
char *h_name;
char **h_aliases;
int h_addrtype;
int h_length;
char **h_addr_list;
};
#include <netdb.h>
struct hostend *gethostbyaddr(const char *addr,
size_t len;int family)
–
–
–
–
–
addr is actually a pointer to an in_addr
structure
Len = 4 for IPv4 and 16 for IPv6
This function queries a the PTR records.
See example1.c and example2.c for the use of
the two functions.
Notice that these system calls incur
communications, you can observe this in
example1a.c
• Older Gethostbyname and getaddrbyname
are not reentrant functions.
• Not thread safe and may have problem using in
signal handlers, or anything that have concurrency.
• Why?
static struct hostent hosts;
struct hostent *gethostbyname2(…) {
/* call DNS function for A or AAAA query */
/* fill in host structure */
return (&host);
}
Struct hostent * gethostbyaddr {
/* call DNS function for PTR query in in-addr.arpa domain */
/* fill in host structure */
return(&host);
}
• Many other functions are not reentrant (can cause
errors in code with signals or threads).
– E.g. malloc, inet_ntoa
– Newer systems have thread-safe implementations.
–
Other functions to obtain system related information:
•
To get the name of the host:
–
Uname: name, os, hardware of the machine
–
Gethostname
#include <sys/utsname.h>
int uname (struct utsname *name)
Struct utsname {
char sysname[_UTS_NAMESIZE];
char nodename[_UTS_NODESIZE];
char release[_UTS_NAMESIZE];
char version[_UTS_NAMESIZE];
char machine[_UTS_NAMESIZE];
}
See example3.c
–
Other functions to get system information:
•
Get service information: not querying the DNS, but a system
specific file: e.g. /etc/services
–
Getservbyname
–
Getservbyport
#include <netdb.h>
Struct servent *getservbyname(const char *servname, const char
*protoname);
Struct servent *getservbyport(int port, const char*protname);
Struct servent {
char *s_name;
char** s_aliases;
int s_port;
char *s_proto;
}
See example4.c and example5.c
–
Other functions to get other network
information:
•
Host, service, network and protocols
•
Getxxxent, setxxxent, endxxxend
– Xxx = host, net, proto, serv
•
These functions manipulate the files (database) on
the local machine:
– /etc/hosts hostent
– /etc/networks netent
– /etc/protocols protoent
– /etc/services
servent
– How to get cpu information and memory
information of the current machine?
– See example6.c
Download