Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring 20061 CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Ipv4 Socket Address Structure struct in_addr { in_addr_t s_addr; /* 32-bit IPv4 address */ /* network byte ordered */ }; struct sockaddr_in { uint8_t sin_len;
Topics: –DNS system –Gathering machine information How to find out the machines ip address, name, OS, version, etc.
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Data Communications and Networking (Third Edition)
CS3516 (B10) HELP Session 2 Presented by Lei Cao.
CS3516 B10 Help Session 1 CS3516 — TCP/IP Socket Programming Presented by Can (John) Tatar.
Lecture 10 Doman Name System CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Kurose & Ross.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
Client Design. Issues Server Identification Setting up a socket on client side TCP –Reading and writing with a socket –Closing a socket UDP –Reading and.
Sockets Programming Introduction © Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
Tutorial 8 Socket Programming
CS4514 B05 HELP Session 1 CS4514 – TCP/IP Socket Programming Presented by Feng Li
CS 311 – Lecture 19 Outline Internet Sockets – gethostname utility – struct hostent – inet_addr – Machine byte to Network byte order translation and vice.
#include DatatypeDescription int8_t uint8_t int16_t uint16_t int32_t uint32_t Signed 8-bit integer Unsigned 8-bit integer Signed 16-bit integer Unsigned.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Introduction to Socket Programming April What is a socket? An interface between application and network –The application creates a socket –The socket.
SOCKETS Lecture #3. The Socket Interface Funded by ARPA (Advanced Research Projects Agency) in Developed at UC Berkeley Objective: to transport.
Ken French HELP Session 1 CS4514. CS4514 We expect that you have had a programming course similar to 2005 before coming into this class. Programs will.
1 Advanced Name and Address Conversions getaddrinfo, getnameinfo, gai_strerror, freeaddrinfo host_serv, tcp_connect, tcp_listen, udp_client, udp_connect,
Introduction to Project 1 Web Client and Server Jan 2006.
Threads© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department.
Advanced UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
CS640: Computer Networks Aditya Akella Lecture 17 Naming and the DNS.
Babak Esfandiari (based on slides by Qusay Mahmoud)
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Assignment 3 A Client/Server Application: Chatroom.
Netprog: DNS and name lookups1 Address Conversion Functions and The Domain Name System Refs: Chapter 9 RFC 1034 RFC 1035.
Lecture on DHCP, DNS & SNMPDebashis Saha Thursday, May 17, DHCP, DNS, SNMP Debashis Saha MIS Group, IIM Calcutta
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
Elementary Name and Address Conversions
Chapter 29 Domain Name System (DNS) Allows users to reference computer names via symbolic names translates symbolic host names into associated IP addresses.
CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.
1 CMPT 471 Networking II Transport Layer Network Programming © Janice Regan, 2013.
Netprog: DNS and name lookups1 Address Conversion Functions and The Domain Name System Refs: Chapter 9 RFC 1034 RFC 1035.
The Application Layer Application Services (Telnet, FTP, , WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable.
Socket 实验汇总 1. 2 Lab1( 需验收 ) Run all the sample programs today and answer the mentioned questions. Learn about the O_APPEND flag used in open(). Question:
1 Kyung Hee University Chapter 18 Domain Name System.
Elementary Name and Address Conversions
Name and Address Conversions Chap 11. Domain Name System  A lookup mechanism for translating objects into other objects  A globally distributed, loosely.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 19 Domain Name System (DNS)
Socket Programming Lab 1 1CS Computer Networks.
TELE 402 Lecture 6: Name and address conversions 1 Overview Last Lecture –Socket Options and elementary UDP sockets This Lecture –Name and address conversions.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 25 Acknowledgements: The syllabus and power point presentations are modified versions.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
Socket address structures Byte ordering IP address conversion
Sockets Introduction Socket address structures Value-result arguments
1 Network Programming. 2 Background Important guidelines –Use conductor.tamucc.edu or any LINUX machine to develop your network applications –Do not use.
In unistd.h : int gethostname(char * name, int maxlen) Purpose : Find the computer's name.
TCP/IP Protocol Suite 1 Chapter 17 Upon completion you will be able to: Domain Name System: DNS Understand how the DNS is organized Know the domains in.
Chapter 11 Advanced Name and Address Conversion. Introduction gethostbyname, gethostbyaddr: protocol dependent getaddrinfo: –a function providing protocol.
EECS340 Recitation 1: Very helpful to your project Hongyu Gao 1.
Client-Server model. Socket programming 
Name and Address Conversions
Name/Address conversion:
Network Programming CSC- 341
CpSc 360: Distributed and Network Programming
Chapter4 Elementary TCP Socket
Name and Address Conversions Part I
Things that are nice to know when you’re doing this project
Recitation 11 – 4/29/01 Outline Sockets Interface
Advanced Network Programming spring 2007
in unistd.h: int gethostname(char * name, int maxlen)
Presentation transcript:

Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department Virginia Tech Name and Address Conversions

© Dr. Ayman Abdel-Hamid, CS4254 Spring Outline Name and Address Conversions (Chapter 11)  Domain Name System  gethostbyname Function  gethostbyaddr Function  gethostname Function  getservbyname and getservbyport Functions

Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring Domain Name System Fully Qualified Domain Name FQDN DNS uses Resource Records RR to store information about items SOAStart of AuthortiyParameters for this zone AIP address of a host32 bit integer MXMail Exchangepriority, domain willing to accept NSName servername of a server for this domain CNAMECanonical namecreate aliases PTRPointermap IP addresses into host names HINFOHost DescriptionCPU and OS in ASCII TXTTextUn-interpreted ASCII text m.cs.vt.edu.86400INHINFOSun Unix m.cs.vt.edu.86400INA m.cs.vt.edu86400INA

Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring Domain Name System Application code Resolver code Local name server Other name server Resolver configuration files Function callFunction return UDP request UDP reply Application /etc/resolv.conf (contains IP addresses of local name servers) Typical arrangement of clients, resolvers, and name servers Resolver code can also be link- edited into applications when built

Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring gethostbyname Function 1/2 #include struct hostent *gethostbyname (const char *hostname); Returns: non-null 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 of pointers to alias names */ int h_addrtype; /* host address type : AF_INET*/ int h_length;/* length of address : 4*/ char **h_addr_list;/* ptr to array of ptrs with IPv4 addrs*/ }; hostent{} h_name h_aliases h_addrtype h_length h_addr_list official hostname \0 NULL Alias #1 \0 Alias #2 \0 IP addr #1 IP addr #2 IP addr #3 h_length =4 in_addr{} AF_INET 4 A host which has 2 aliases and 3 IP addresses

Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring gethostbyname Function 2/3 #define h_addr h_addr_list[0] /* for backward compatibility */ struct hostent * hp = gethostbyname(argv[1]); bcopy ( hp->h_addr, &server.sin_addr, hp->h_length); //see intro/daytimetcpcli_hostname.c Will only retrieve IPv4 addresses, performs a query for an A record Some versions of gethostbyname will allow the following hptr = gethostbyname (“ ”);  not portable

Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring gethostbyname Function 3/3 If error, sets global integer h_errno to  HOST_NOT_FOUND  TRY_AGAIN  NO_RECOVERY  NO_DATA  specified name valid but does not have A records Can use hstrerror function to get a description of the error (value of h_errno) See names/hostent.c for an example Example Usage > hostent ap1> hostent cnn.com> hostent www

Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring gethostbyaddr Function Takes a binary IPv4 address and tries to find the hostname corresponding to that address Performs a query for a PTR record #include struct hostent *gethostbyaddr(const char *addr, socklen_t len, int family); Returns non-null pointer if OK, NULL on error with h_errno set Field of interest in the returning structure is h_name (canonical host name) addr argument is not a char* but really a pointer to an in_addr structure containing the IPv4 address

Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring gethostname Function Obtains the host name #include int gethostname(char *name, size_t len); // On success, zero is returned. On error, -1 is returned, and errno is set appropriately Example #define MAXHOSTNAME 80 char ThisHost[80]; gethostname (ThisHost, MAXHOSTNAME);

Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring getservbyname and getservbyport Functions 1/2 #include struct servent *getservbyname(const char *servname, const char *protoname); //returns non-null pointer if OK, NULL on error struct servent *getservbyport(int port, const char *protoname); //returns non-null pointer is OK, NULL on error //port value must by in network byte order struct servent { char *s_name;/* official service name */ char **s_ aliases;/* aliases list*/ int s_port;/* port number, network byte order */ char *s_proto;/* protocol to use */ };

Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring getservbyname and getservbyport Functions 2/2 struct servent *sptr; sptr = getservbyname (“domain”,”udp”); //DNS using UDP sptr = getservbyname (“ftp”,”tcp”); //FTP using TCP sptr=getservbyname(“ftp”,”udp”); //this call will fail sptr = getsrvbyport(htons(21),”tcp”); // FTP using TCP sptr = getsrvbyport(htons(21),NULL); // FTP using TCP sptr = getsrvbyport(htons(21),”udp”); // This call will fail See names/daytimetcpcli1.c for a program that takes a hostname and service name as arguments