Presentation is loading. Please wait.

Presentation is loading. Please wait.

Name and Address Conversions Part I

Similar presentations


Presentation on theme: "Name and Address Conversions Part I"— Presentation transcript:

1 Name and Address Conversions Part I
Chapter 11 Name and Address Conversions Part I Presented by Jessy Yau Chiew Lian

2 11.1 Introduction Conversion Protocol Information
hostnames  IPv4 addresses gethostbyname gethostbyaddr Server names  post numbers getservbyname getservbyport Protocol Information getaddrinfo getnameinfo

3 11.2 Domain Name System(DNS)
DNS maps between hostnames and IP addresses. Simple hostname : solaries, freebsd Fully qualified domain name (FQDN) :solaries.unpbook.com An absolute name Must end with a period but ignored by users often Entries in the DNS Resource Records(RRs) Trailing period tells the resolver that this name is fully qualified and it doesn’t need to search its list of possible domains.

4 Type of Resource Records
A - maps a hostname into a 32-bit IPv4 address AAAA – maps a hostname into a 128-bit IPv6 addresses. PTR – maps IP address into hostname IPv4 address 4 bytes are reversed each byte converted to decimal ASCII value (0-255) in-addr.arpa is appended Ipv6 address 32 bytes are reversed each byte converted to hexadecimal ASCII value (0-9,a-f) ip6.arpa is appended

5 MX – mail exchanger CNAME – canonical name Multiple MX records exist
Starting with the smallest value CNAME – canonical name ftp and www AAAA with host’s link-local address

6 Link-Local address vs Site-Local address
Prefix of fe80::/64 Host bits are built from the interface’s EUI64 address Contacting host and router on the same network only. Addresses are not visible or reachable from different subnet. Site-local address Prefix of fec0::/10 Subnet and hosts can be addressed just as for provider-assigned network. The addresses will not be visible to outside machines, as these are on a different network, and their site-local addresses are in a different physical net Site-local addresses are rather uncommon today, and is no substitute for globally unique addresses if global connectivity is required. For IPv6, it's most common to have hosts assigned a local link and a global IP address.

7 Resolvers and Name Servers
Applications such as the clients and servers that we are writing contact a DNS server by calling functions in a library known as Resolver It is contained in a system library and is link-edited into application. It reads its system-dependent configuration files to determine the location of the organization's name servers. /etc/resolv.conf Example functions: gethostbyname and gethostbyaddr There are a centralized resolver daemon that all applications share, and the system library code performs RPCs to this daemon.

8 The resolver sends the query to the local name server using UDP.
If the local name server does not know the answer, it will query to other name servers If answer is too large to fit in UDP packet, it will automatically switch to TCP.

9 DNS Alternatives Get name and address information without using DNS
Static host files - file /etc/hosts Network Information System(NIS) Lightweight Directory Access Protocol (LDAP) Implementation-dependent Solaries 2.x, HP-UX 10, FreeBSD 5.x - file /etc/nsswitch.conf AIX - file /etc/netsvc.conf BIND file /etc/irs.conf If a name server is used for hostname lookups Uses file /etc/resolv.conf to specify IP addresses of name servers. Calls resolver functions

10 11.3 gethostbyname Function
Previous example using IP addresses instead of names connect, sendto, accept and recvfrom Most of applications should deal with names especially when move to IPv6 addresses (hex strings) gethostbyname returns a pointer to a hostent structure that contains all the IPv4 addresses for the host Not supports IPv6 addresses

11

12

13 11.4 gethostbyaddr Function
Reverses of gethostbyname, takes a binary IPv4 address to look up hostname addr is a pointer to an in_addr structure len is 4 Family argument is AF_INET In term of DNS, gethostbyaddr queries a name server for a PTR record in the in-addr.arpa domain.

14 11.5 getservbyname and getservbyport Functions
getservbyname gets port number associated with an Internet service and protocol. file /etc/services

15 getservbyport gets Internet service which corresponds to port and protocol
file /etc/services

16 we try using the inet_aton function (Section 3
we try using the inet_aton function (Section 3.6) to see if the argument was an ASCII-format address. If it was, we construct a single-element list consisting of the corresponding address. Continues..

17 Resource Records Try each server address
29–35 We now code the calls to socket and connect in a loop that is executed for every server address until a connect succeeds or the list of IP addresses is exhausted

18 11.6 getaddrinfo Function gethostbyname and gethostbyaddr functions only support IPv4 getaddrinfo handles both name-to-address and service-to-port translation, and returns sockaddr structures instead of addresses. hostname - hostname or address string (dotted-decimal for IPv4 or hex string for IPv6) service - service name or a decimal port number string hints – null pointer or pointer to an addrinfo structure

19

20 There are two ways that multiple structures can be returned:
If multiple addresses associated with the hostname, a structure is returned for each address – ai_family hint If service is provided for multiple socket types, a structure is returned for each socket type – ai_socktype hint

21 Port 53 is for the domain service
Port 53 is for the domain service. This port number will be in network byte order in the socket address structures. We also show the returned ai_protocol values as IPPROTO_TCP or IPPROTO_UDP. It would also be acceptable for getaddrinfo to return an ai_protocol of 0 for the two SOCK_STREAM structures if that is sufficient to specify TCP (it is not sufficient if the system implements SCTP, for example), and an ai_protocol of 0 for the two SOCK_DGRAM structures if the system doesn't implement any other SOCK_DGRAM protocols for IP (as of this writing, none are yet standardized, but two are in development in the IETF). It is safest for getaddrinfo to always return the specific protocol.

22 11.7 gai_strerror Function
Nonzero error returns values from getaddrinfo have the names and meanings gai_strerror takes one of these values as an argument and returns a pointer to the corresponding error string

23 11.8 freeaddrinfo Function
All the storage returned by getaddrinfo, the addrinfo structures, the ai_addr structures, and the ai_canonname string are obtained dynamically. This storage is returned by calling freeaddrinfo.

24 11.9 getaddrinfo Function: IPv6
getaddrinfo is dealing with two different inputs: Type of socket address structure the caller wants back Type of records that should be searched for in the DNS or other database.

25 11.10 getaddrinfo Function: Examples
Example of Figure 11.5: Example of a multihomed host with three IPv4 addresses:

26 Example: we specify our host aix, which has both a AAAA record and an A record. We do not specify the address family, but we provide a service name of ftp, which is provided by TCP only Example: we specify the AI_PASSIVE flag. We do not specify an address family or hostname. We also specify a port number of 8888 and a stream socket.


Download ppt "Name and Address Conversions Part I"

Similar presentations


Ads by Google