Carnegie Mellon Introduction to Computer Systems 15 213 18 243 spring 2009 23rd Lecture Apr 14th Instructors Gregory Kesden and Markus P schel Carnegie Mellon Last Time Client Server Transaction 1 Client sends request Client process 4 Client handles response Server process 3 Server sends response Resource 2 Server handles request Note clients and servers are processes running on hosts can be the same or different hosts Carnegie Mellon Last Time Logical Structure of an internet host router host router router router router router Carnegie Mellon Last Time internet Protocol Provides a naming scheme An internet protocol defines a uniform format for host addresses Each host and router is assigned at least one of these internet addresses that uniquely identifies it Provides a delivery mechanism An internet protocol defines a standard transfer unit packet Packet consists of header and payload Header contains info such as packet size source and destination addresses Payload contains data bits sent from source host Carnegie Mellon Transferring Data Over an internet LAN1 1 client server protocol software data PH data PH LAN2 8 data 7 data PH FH2 6 data PH FH2 protocol software FH1 LAN1 frame 3 Host B data internet packet 2 Host A LAN1 adapter LAN2 adapter Router FH1 LAN1 adapter LAN2 adapter LAN2 frame 4 PH Internet packet header FH LAN frame header data PH FH1 data protocol software PH FH2 5 Carnegie Mellon Today Programmer s view of the internet Sockets interface Carnegie Mellon A Programmer s View of the Internet Hosts are mapped to a set of 32 bit IP addresses 128 2 203 179 The set of IP addresses is mapped to a set of identifiers called Internet domain names 128 2 203 179 is mapped to www cs cmu edu A process on one Internet host can communicate with a process on another Internet host over a connection Carnegie Mellon IP Addresses 32 bit IP addresses are stored in an IP address struct IP addresses are always stored in memory in network byte order big endian byte order True in general for any integer transferred in a packet header from one machine to another E g the port number used to identify an Internet connection Internet address structure struct in addr unsigned int s addr network byte order big endian Useful network byte order conversion functions htonl convert long int from host to network byte order htons convert short int from host to network byte order ntohl convert long int from network to host byte order ntohs convert short int from network to host byte order Carnegie Mellon Dotted Decimal Notation By convention each byte in a 32 bit IP address is represented by a string decimal values for bytes separated by a period Blackboard IP address 0x8002C2F2 128 2 194 242 Carnegie Mellon Dotted Decimal Notation By convention each byte in a 32 bit IP address is represented by a string decimal values for bytes separated by a period IP address 0x8002C2F2 128 2 194 242 Functions for converting between binary IP addresses and dotted decimal strings inet aton dotted decimal string IP address in network byte order inet ntoa IP address in network byte order dotted decimal string n denotes network representation a denotes application representation Carnegie Mellon IP Address Structure IP V4 Address space divided into classes 0123 8 Class A 0 Net ID Class B 1 0 Net ID Class C 16 24 Host ID Host ID Net ID 110 Class D 1 1 1 0 Multicast address Class E Reserved for experiments 1111 31 Host ID Network ID written in form w x y z n n number of bits in net id yellow part above E g CMU written as 128 2 0 0 16 Which class is that Unrouted private IP addresses 10 0 0 0 8 172 16 0 0 12 192 168 0 0 16 Nowadays CIDR Classless interdomain routing Carnegie Mellon Internet Domain Names unnamed root net edu mit cmu cs gov berkeley ece First level domain names com amazon www 208 216 181 15 cmcl pdl kittyhawk imperial 128 2 194 242 128 2 189 40 Second level domain names Third level domain names Carnegie Mellon Domain Naming System DNS The Internet maintains a mapping between IP addresses and domain names in a huge worldwide distributed DNS database Conceptually programmers can view the DNS database as a collection of millions of host entry structures DNS host entry structure struct hostent char h name char h aliases int h addrtype int h length char h addr list official domain name of host null terminated array of domain names host address type AF INET length of an address in bytes null terminated array of in addr structs Functions for retrieving host entries from DNS gethostbyname query key is a DNS domain name gethostbyaddr query key is an IP address Carnegie Mellon Properties of DNS Host Entries Each host entry is an equivalence class of domain names and IP addresses Each host has a locally defined domain name localhost which always maps to the loopback address 127 0 0 1 Different kinds of mappings are possible Simple case one to one mapping between domain name and IP address kittyhawk cmcl cs cmu edu maps to 128 2 194 242 Multiple domain names mapped to the same IP address eecs mit edu and cs mit edu both map to 18 62 1 6 Multiple domain names mapped to multiple IP addresses aol com and www aol com map to multiple IP addresses Some valid domain names don t map to any IP address for example cmcl cs cmu edu Carnegie Mellon A Program That Queries DNS int main int argc char argv argv 1 is a domain name char pp or dotted decimal IP addr struct in addr addr struct hostent hostp if inet aton argv 1 addr 0 hostp Gethostbyaddr const char addr sizeof addr AF INET else hostp Gethostbyname argv 1 printf official hostname s n hostp h name for pp hostp h aliases pp NULL pp printf alias s n pp for pp hostp h addr list pp NULL pp addr s addr struct in addr pp s addr printf address s n inet ntoa addr Carnegie Mellon Querying DNS from the Command Line Domain Information Groper dig provides a scriptable command line interface to DNS linux dig short kittyhawk cmcl cs cmu edu 128 2 194 242 linux dig short x 128 2 194 242 KITTYHAWK CMCL CS CMU EDU linux dig short aol com 205 188 145 215 205 188 160 121 64 12 149 24 64 12 187 25 linux dig short x 64 12 187 25 aol v5 websys aol com Carnegie Mellon Internet Connections Clients and servers communicate by sending streams of bytes over connections Point to point full duplex 2 way communication and reliable A socket is an endpoint of a connection Socket address is an IPaddress port pair A port is a 16 bit integer that identifies a process Ephemeral port Assigned automatically on
View Full Document