![Page 1: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/1.jpg)
Name and Address ConversionsName and Address Conversions
Chap 11
![Page 2: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/2.jpg)
Domain Name SystemDomain Name System
A lookup mechanism for translating objects into other objects
A globally distributed, loosely coherent, scalable, reliable, dynamic database
Comprised of three components Name space Servers making that name space available Resolvers (clients) which query the servers about the
name space
![Page 3: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/3.jpg)
Domain Name SpaceDomain Name Space
DNS's distributed database is indexed by domain names. Each domain name is essentially just a path in a large
inverted tree, called the domain name space.
![Page 4: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/4.jpg)
Domain, Delegation, Zone Domain, Delegation, Zone
![Page 5: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/5.jpg)
Name Server ArchitectureName Server Architecture
Master
serverZone transfer
Zone
data
file
From
diskAuthoritative Data
(primary master and
slave zones)
Agent
(looks up queries
on behalf of resolvers)
Cache Data
(responses from
other name servers)
Name Server Process
![Page 6: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/6.jpg)
Authoritative DataAuthoritative Data
ResolverQuery
Response
Authoritative Data
(primary master and
slave zones)
Agent
(looks up queries
on behalf of resolvers)
Cache Data
(responses from
other name servers)
Name Server Process
![Page 7: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/7.jpg)
Using Other Name ServersUsing Other Name Servers
Arbitrary
name
server
Response
ResolverQuery
Query
Authoritative Data
(primary master and
slave zones)
Agent
(looks up queries
on behalf of resolvers)
Cache Data
(responses from
other name servers)
Name Server Process
Response
![Page 8: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/8.jpg)
Cached DataCached Data
Query
Response
Authoritative Data
(primary master and
slave zones)
Agent
(looks up queries
on behalf of resolvers)
Cache Data
(responses from
other name servers)
Name Server Process
Resolver
![Page 9: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/9.jpg)
Name ResolutionName Resolution
A DNS query has three parameters: A domain name (e.g.,
ice.hufs.ac.kr), Remember, every node
has a domain name! A class (e.g., IN), and A type (e.g., A)
DNS message format
AdditionalAuthorityAnswerQuestionHeader
: the question for the name server : RRs answering the question : RRs pointing toward an authority : RRs holding additional information
![Page 10: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/10.jpg)
Mapping Addresses to NamesMapping Addresses to Names
![Page 11: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/11.jpg)
Resource RecordsResource Records 주요 RRs
SOA Record (Start Of Authority): 해당 도메인에 대해 네임서버가 인증 (authoritative) 된 자료를 갖고 있음을 의미
NS(Name Server) Record: 해당 도메인에 대한 delegation 하는 네임서버를 지시
A Record: 도메인에 IPv4 주소를 mapping AAAA Record: 도메인에 IPv6 주소를 mapping CNAME Record: 도메인에 대한 또 다른 이름
설정 MX(Mail eXchanger) Record: 해당 호스트의
메일 라우팅 경로를 조정 PTR(Pointer) Record: IP 주소를 domain name
으로 reverse mapping 해 주며 , Reverse Zone 파일에서 사용
NAME
(Dynamic)
TYPE(2 Byte)
CLASS(2 Byte)
TTL(4 Byte)
RDLENGTH(2 Byte)
RDATA(Dynamic)
![Page 12: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/12.jpg)
IPv4 Name and Address ConversionIPv4 Name and Address Conversion
Domain name IPv4 address
IPv4 address domain name
gethostbyname/gethostbyaddr are not reentrant !!static struct hostent host; /* result stored here */struct hostent *gethostbyname(const char *hostname){ /* call DNS functions for A or AAAA query */ /* fill in host structure */ return(&host);}
![Page 13: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/13.jpg)
Service Name Conversion FunctionsService Name Conversion Functions
Service name port ( See /etc/services )
Port service name (port: network byte order)
![Page 14: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/14.jpg)
Example: name/daytimetcpcli1.cExample: name/daytimetcpcli1.c
Network-related information
![Page 15: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/15.jpg)
set_addressset_address Function (etcp lib) Function (etcp lib)– works on only IPv4– works on only IPv4
![Page 16: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/16.jpg)
New Name/Address Conversion – IPv4/IPv6New Name/Address Conversion – IPv4/IPv6
hostname: hostname or address string service: service name or decimal port
number string result: addrinfo data structure is
dynamically allocated Re-entrant, thread-safe, and protocol
independent functions (support IPv4, IPv6)
![Page 17: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/17.jpg)
New Name/Address Conversion – IPv4/IPv6New Name/Address Conversion – IPv4/IPv6
hints: NULL or pointer to addrinfo data structure The following member can be set by caller
ai_flag /* AI_PASSIVE for server, AI_CANNONNAME */ ai_family /* AF_xxx */ ai_socktype /* SOCK_xxx */ ai_protocol /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
Example
![Page 18: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/18.jpg)
getaddrinfogetaddrinfo Actions and Results Actions and Results
![Page 19: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/19.jpg)
UNP Library FunctionsUNP Library Functions#include “unp.h”
struct addrinfo *host_serv(const char *hostname, const char *service, int family, int socktype);
Returns: pointer to addrinfo structure if OK, NULL on error
int tcp_connect(const char *hostname, const char *service);int tcp_listen(const char *hostname, const char *service,
socklen_t *lenptr);Both returns: connected socket descriptor if OK, no return on error
int udp_client(const char *hostname, const char *service, void **saptr, socklen_t *lenp);
Returns: unconnected socket descriptor if OK, no return on errorsaptr: address of a pointer to a socket address structure that stores destination IP addr/port # for future calls to sendto
int udp_connect(const char *hostname, const char *service);Returns: connected socket descriptor if OK, no return on error
int udp_server(const char *hostname, const char *service, socklen_t *lenptr);
Rerurns: unconnected socket descriptor if OK, no return on error
![Page 20: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/20.jpg)
host_servhost_serv Function Function
![Page 21: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/21.jpg)
tcp_connecttcp_connect and and tcp_listentcp_listen Functions Functions
![Page 22: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/22.jpg)
Protocol-indep Daytime TCP Client/ServerProtocol-indep Daytime TCP Client/Servernames/daytimetcpsrv1.c names/daytimetcpcli.c
![Page 23: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/23.jpg)
Protocol-indep Daytime UDP Client/ServerProtocol-indep Daytime UDP Client/Server
names/daytimeudpsrv2.c names/daytimeudpcli1.c
![Page 24: Name and Address Conversions Chap 11. Domain Name System A lookup mechanism for translating objects into other objects A globally distributed, loosely](https://reader035.vdocuments.net/reader035/viewer/2022081520/5697bf7c1a28abf838c8451c/html5/thumbnails/24.jpg)
getnameinfogetnameinfo Function Function
If the caller does not want to return host(serv) string, specify hostlen(servlen) of 0
flags