Elementary Name and Address. Conversions



Similar documents
Elementary Name and Address Conversions

Name and Address Conversions

Domain Name System (1)! gethostbyname (2)! gethostbyaddr (2)!

Hostnames. HOSTS.TXT was a bottleneck. Once there was HOSTS.TXT. CSCE515 Computer Network Programming. Hierarchical Organization of DNS

CSE 333 SECTION 6. Networking and sockets

Concurrent Server Design Alternatives

Porting applications & DNS issues. socket interface extensions for IPv6. Eva M. Castro. ecastro@dit.upm.es. dit. Porting applications & DNS issues UPM

DNS Domain Name System

CS640: Computer Networks. Naming /ETC/HOSTS

IPv6 Enabling CIFS/SMB Applications

Socket Programming. Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur

Best practices in IPv6 enabled networking software development.

- Domain Name System -

Copyright

ECE 4321 Computer Networks. Network Programming

Network Programming with Sockets. Anatomy of an Internet Connection

Motivation. Domain Name System (DNS) Flat Namespace. Hierarchical Namespace

416 Distributed Systems. Feb 24, 2016 DNS and CDNs

Network Programming. Chapter The Client-Server Programming Model

DNS. The Root Name Servers. DNS Hierarchy. Computer System Security and Management SMD139. Root name server. .se name server. .

A Client Server Transaction. Introduction to Computer Systems /18 243, fall th Lecture, Nov. 3 rd

DNS : Domain Name System

Socket Programming in C/C++

INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens

Software changes for Website and Application IPv6 Readiness

DNS. Computer networks - Administration 1DV202. fredag 30 mars 12

BSD Sockets Interface Programmer s Guide

TCP/IP - Socket Programming

Domain Name System (DNS) Fundamentals

Domain Name System :49:44 UTC Citrix Systems, Inc. All rights reserved. Terms of Use Trademarks Privacy Statement

Tutorial on Socket Programming

DNS. Computer Networks. Seminar 12

My Services Online Service Support. User Guide for DNS and NTP services

Lecture 2 CS An example of a middleware service: DNS Domain Name System

UNIX Sockets. COS 461 Precept 1

Writing Client/Server Programs in C Using Sockets (A Tutorial) Part I. Session Greg Granger grgran@sas. sas.com. SAS/C & C++ Support

Windows Socket Programming & IPv6 Translation Middleware

Introduction to Socket programming using C

Applications and Services. DNS (Domain Name System)

First Workshop on Open Source and Internet Technology for Scientific Environment: with case studies from Environmental Monitoring

Introduction to Socket Programming Part I : TCP Clients, Servers; Host information

NS3 Lab 1 TCP/IP Network Programming in C

Domain Name System (DNS) Session-1: Fundamentals. Ayitey Bulley

Understand Names Resolution

Porting and Deploying VoIP to IPv6: Lessons Learned

The Domain Name System

IPv6 Applications. Formation IPv6 RENATER -Rouen, FR

Writing a C-based Client/Server

Domain Name System. DNS is an example of a large scale client-server application. Copyright 2014 Jim Martin

Installing and Setting up Microsoft DNS Server

Using Webmin and Bind9 to Setup DNS Sever on Linux

Domain Name System (DNS)

DNS & IPv6. Agenda 4/14/2009. MENOG4, 8-9 April Raed Al-Fayez SaudiNIC CITC rfayez@citc.gov.sa, DNS & IPv6.

Socket Programming. Srinidhi Varadarajan

DNS (Domain Name System) is the system & protocol that translates domain names to IP addresses.

IPv6 Support in the DNS. Workshop Name Workshop Location, Date

Deploying & Configuring a DNS Server on OpenServer 6 or UnixWare 7. Kirk Farquhar

Network Layers. CSC358 - Introduction to Computer Networks

Introduction to the Domain Name System

Lab 4: Socket Programming: netcat part

Motivation. Users can t remember IP addresses. Implemented by library functions & servers. - Need to map symbolic names (

File transfer and login using IPv6, plus What to do when things don t work

The Application Layer: DNS

Fasthosts Internet Parallels Plesk 10 Manual

DNS Resolving using nslookup

An Advanced 4.4BSD Interprocess Communication Tutorial

Agenda. Network Services. Domain Names. Domain Name. Domain Names Domain Name System Internationalized Domain Names. Domain Names & DNS

Generalised Socket Addresses for Unix Squeak

1 Introduction: Network Applications

CS3250 Distributed Systems

IBM Software Group Enterprise Networking Solutions z/os V1R11 Communications Server

Client / Server Programming with TCP/IP Sockets

How to Configure the Windows DNS Server

How to Add Domains and DNS Records

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software

Forouzan: Chapter 17. Domain Name System (DNS)

IPv6 support in the DNS

Use Domain Name System and IP Version 6

Application Architecture

Lesson 13: DNS Security. Javier Osuna GMV Head of Security and Process Consulting Division

Internet-Praktikum I Lab 3: DNS

Introduction to Network Operating Systems

THE DOMAIN NAME SYSTEM DNS

IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking.

Domain Name System (DNS)

Configuring an External Domain

NetIQ Advanced Authentication Framework - MacOS Client

Internetworking with TCP/IP Unit 10. Domain Name System

Application. Transport. Network. Data Link. Physical. Network Layers. Goal

Networking Domain Name System

Application Protocols in the TCP/IP Reference Model

Domain Name System DNS

HTG XROADS NETWORKS. Network Appliance How To Guide: EdgeDNS. How To Guide

Transcription:

Elementary Name and Address Domain name system Conversions gethostbyname Function RES_USE_INET6 resolver option gethostbyname2 Function and IPv6 support gethostbyaddr Function uname and gethostname Functions getservbyname andgetservbyport Functions Other networking information 1 Some materials in these slides are taken from Prof. Ying-Dar Lin with his permission of usage

Domain Name System Entries in DNS: resource records (RRs) for a host A record: maps a hostname to a 32-bit IPv4 addr AAAA (quad A) record: maps to a 128-bit IPv6 addr PTR record: maps IP addr to hostname (p. 11) MX record: specifies a mail exchanger of the host CNAME record: assigns canonical name for common e.g. services 正 式 名 稱 solaris IN A 206.62.226.33 IN AAAA 5f1b:df00:ce3e:e200:0020:0800:2078:e3e3 IN MX 5 solaris.kohala.com IN MX 10 mailhost.kohala.com 5, 10 是 偏 好 值 www IN CNAME bsdi.kohala.com 2

DNS: Application, Resolver, Name Servers application application 以 domain name 為 階 層 架 構 code UDP call return request resolver local other code name name UDP server servers reply resolver configuration files resolver functions: gethostbyname, gethostbyaddr name server: BIND (Berkeley Internet Name Domain) static hosts files (DNS alternatives): /etc/hosts resolver configuration file (specifies name server IPs): /etc/resolv.conf 3

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_errno set struct hostent { char *h_name; /* official (canonical) name of host */ char **h_aliases; /* pointer to array of pointers to alias names */ int h_addrtype; /* host addr type: AF_INET or AF_INET6 */ int h_length; /* length of address: 4 or 16 */ char **h_addr_list; /* ptr to array of ptrs with IPv4/IPv6 addrs */ }; #define h_addr h_addr_list[0] /* first address in list */ 4

hostent Structure Returned by gethostbyname Socket address structure (Ch.3) hostent { } h_name canonical hostname \0 h_aliases h_addrtype AF_INET/6 h_length 4/16 h_addr_list NULL 字 串 alias #1 \0 alias #2 \0 NULL in/6_addr { } IP addr #1 in/6_addr { } IP addr #2 in/6_addr { } IP addr #3 5

Callgethostbyname and Print Returned Info #include "unp.h" names/hostent.c int main(int argc, char **argv) { char *ptr, **pptr, str[inet6_addrstrlen]; struct hostent *hptr; 下 個 命 令 列 參 數 while (--argc > 0) { ptr = *++argv; if ( (hptr = gethostbyname(ptr)) == NULL) { err_msg("gethostbyname error for host: %s: %s", ptr, hstrerror(h_errno)); continue; 印 出 正 式 名 稱 } 印 出 所 有 別 名 printf("official hostname: %s\n", hptr->h_name); for (pptr = hptr->h_aliases; *pptr!= NULL; pptr++) printf( \talias: %s\n", *pptr); 6

#ifdef #endif } switch (hptr->h_addrtype) { case AF_INET: AF_INET6 case AF_INET6: } exit(0); pptr = hptr->h_addr_list; for ( ; *pptr!= NULL; pptr++) printf( \taddress: %s\n, default: err_ret("unknown address type"); break; } names/hostent.c 呼 叫 Inet_ntop 將 所 有 位 址 全 部 列 出 來 Inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str))); break; Address type: AF_INET or AF_INET6 7

Program Output lhyen@lhyen-desktop:~/np/unpv13e/names$./hostent www.yahoo.com.tw official hostname: tw1-w2.rd.tw.g1.b.yahoo.com alias: www.yahoo.com.tw alias: rc.tpe.yahoo.com alias: tw.rc.yahoo.com alias: w2.rd.tw.g1.b.yahoo.com address: 119.160.246.23 lhyen@lhyen-desktop:~/np/unpv13e/names$ 8

Reversed Name Resolution 原 始 DNS 架 構 下 由 IP address 查 domain name 時 不 容 易 找 到 正 確 的 DNS server, 因 DNS 是 以 domain name 而 不 是 以 IP address 為 階 層 架 構 例 如, 某 固 網 公 司 DNS 伺 服 器 存 有 所 有 *.idv.tw 主 機 的 domain name 與 IP 位 址 的 對 應, 但 這 些 主 機 的 IP 位 址 並 沒 有 規 律 性 ( 來 自 各 處 ) 如 果 給 定 了 某 個 IP 位 址, 怎 能 知 道 要 去 此 DNS 伺 服 器 查 它 的 domain name? 9

Reversed Name Resolution (cont.) 解 決 方 案 : 建 立 一 個 特 殊 的 domain (inaddr.arpa for IPv4), 專 門 用 來 由 IP address 查 domain name 要 查 206.62.226.33 對 應 的 domain name 到 負 責 33.226.62.206.in-addr.arpa 的 DNS 伺 服 器 去 查 所 謂 的 PTR record 處 理 起 來 就 如 同 由 domain name 查 IP 位 址 33.226.62.206.in-addr.arpa. IN PTR admin1.uohio.edu. 10

gethostbyaddr Function binary IP address tohostent structure 由 IP Address ( 置 於 位 址 結 構 中 ) 查 hostname ( 在 struct hostent 中 ) #include <netdb.h> struct hostent *gethostbyaddr (const char *addr, size_t len, int family); returns: non-null pointer if OK, NULL on error with h_errno set addr argument: a pointer to an in_addr or in6_addr structure h_name inhostent: canonical hostname gethostbyaddr: queries a DNS name server for a PTR record in the in-addr.arpa domain for IPv4 or a PTR record in the ip6.int domain for IPv6. 11

getservbyname / getservbyport Function Service name ( 如 ftp, domain, tftp) 與 port number ( 如 21,53,69) 間 的 互 查 通 常 定 義 在 /etc/services 檔 中 同 時 支 援 TCP 與 UDP 的 服 務 通 常 在 這 兩 個 protocol 內 使 用 相 同 的 port, 但 也 有 例 外 : shell 514/tcp syslog 514/udp 12

getservbyname / getservbyport Function ftp, domain #include <netdb.h> struct servent *getservbyname(const char *servname, const char *protoname); udp, tcp or NULL returns: non-null pointer if OK, NULL on error struct servent *getservbyport (int port, const char *protoname); returns: non-null pointer if OK, NULL on error struct servent { char *s_name; /* official service name */ char **s_aliases; /* service alias list */ int s_port; /* port number, network-byte order */ char *s_proto; /* protocol, TCP or UDP, to use */ }; 13

daytime Client using gethostbyname and getservbyname (see Figure 11.4) Call gethostbyname and getservbyname Try each server address Call connect Check for failure Read server s reply 14

getaddrinfo Function Handle both name-to-address and service-to-port translation #include <netdb.h> int getaddrinfo (const char *hostname, const char *service, const structure addrinfo *hints, struct addrinfo **result); returns: 0 if OK, nonzero on error hostname: either a host name or an address string service: either a service name or a decimal port num string hints: types of information the caller wants returned result: a pointer to a linked list ofaddrinfo structure 15

addrinfo members of hints that can be set by the caller #include <netdb.h> struct addrinfo { int ai_flags; /* AI_PASSIVE, AI_CANNONNAME */ int ai_family; /* AF_xxx */ int ai_socktype; /* SOCK_xxx */ int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPV6 */ socklen_t ai_addrlen; char *ai_canonmame; struct sockaddr *ai_addr; struct addrinfo *ai_next; }; 16

Other Networking Info Four types of info: hosts (gethostbyname, gethostbyaddr) through DNS or /etc/hosts, hostent structure networks (getnetbyname, getnetbyaddr) through DNS or /etc/networks, netent structure protocols (getprotobyname, getprotobynumber) through /etc/protocols, protoent structure services (getservbyname, getservbyport) through /etc/services, servent structure 17