SlideShare une entreprise Scribd logo
1  sur  39
Télécharger pour lire hors ligne
Some slides are in courtesy of J. Kurose and K. Ross
Review of Previous Lecture
• Principles of app layer protocols
– clients and servers
– app requirements
• Web and HTTP
Announcement
• All got partners and IP addresses ?
– One undergrad group can take an extra student
• Should complete at least part I by the end
of this week
• Networking research projects available
(preferably with OS background)
– Quarter-long bonus project for undergrads
– Extensible to 399, potential support available
– Contact me after the class or in the OH
FTP: the file transfer protocol
• transfer file to/from remote host
• client/server model
– client: side that initiates transfer (either to/from
remote)
– server: remote host
• ftp: RFC 959
• ftp server: port 21
file transfer
FTP
server
FTP
user
interface
FTP
client
local file
system
remote file
system
user
at host
FTP: separate control, data connections
• FTP client contacts FTP server
at port 21, specifying TCP as
transport protocol
• Client obtains authorization
over control connection
• Client browses remote
directory by sending commands
over control connection.
• When server receives a
command for a file transfer,
the server opens a TCP data
connection to client
• After transferring one file,
server closes connection.
FTP
client
FTP
server
TCP control connection
port 21
TCP data connection
port 20
• Server opens a second TCP
data connection to transfer
another file.
• Control connection: “out of
band”
• Stateful or stateless?
– FTP server maintains “state”:
current directory, earlier
authentication
Outline
• Electronic Mail: SMTP, POP3, IMAP
• DNS
• Socket programming with TCP
Electronic Mail
Three major components:
• user agents
• mail servers
• simple mail transfer protocol:
SMTP
User Agent
• a.k.a. “mail reader”
• composing, editing, reading mail
messages
• e.g., Eudora, Outlook, elm,
Netscape Messenger
• outgoing, incoming messages
stored on server
user mailbox
outgoing
message queue
mail
server
user
agent
user
agent
user
agent
mail
server
user
agent
user
agent
mail
server
user
agent
SMTP
SMTP
SMTP
Electronic Mail: mail servers
Mail Servers
• mailbox contains incoming
messages for user
• message queue of outgoing (to
be sent) mail messages
• SMTP protocol between mail
servers to send email
messages
– client: sending mail server
– “server”: receiving mail
server
mail
server
user
agent
user
agent
user
agent
mail
server
user
agent
user
agent
mail
server
user
agent
SMTP
SMTP
SMTP
Electronic Mail: SMTP [RFC 2821]
• uses TCP to reliably transfer email message from client to server,
port 25
• direct transfer: sending server to receiving server
• three phases of transfer
– handshaking (greeting)
– transfer of messages
– closure
• command/response interaction
– commands: ASCII text
– response: status code and phrase
• messages must be in 7-bit ASCII
Scenario: Alice sends message to Bob
1) Alice uses UA to compose
message and “to”
bob@someschool.edu
2) Alice’s UA sends message
to her mail server; message
placed in message queue
3) Client side of SMTP opens
TCP connection with Bob’s
mail server
4) SMTP client sends Alice’s
message over the TCP
connection
5) Bob’s mail server places the
message in Bob’s mailbox
6) Bob invokes his user agent
to read message
user
agent
mail
server
mail
server user
agent
1
2 3 4 5
6
SMTP: final words
• SMTP uses persistent
connections
• SMTP requires message
(header & body) to be in
7-bit ASCII
Comparison with HTTP:
• HTTP: pull
• SMTP: push
• both have ASCII
command/response
interaction, status codes
Mail message format
SMTP: protocol for exchanging
email msgs
RFC 822: standard for text
message format:
• header lines, e.g.,
– To:
– From:
– Subject:
different from SMTP
commands!
• body
– the “message”, ASCII
characters only
header
body
blank
line
Message format: multimedia extensions
• MIME: multimedia mail extension, RFC 2045, 2056
• additional lines in msg header declare MIME content type
From: alice@crepes.fr
To: bob@hamburger.edu
Subject: Picture of yummy crepe.
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
base64 encoded data .....
.........................
......base64 encoded data
multimedia data
type, subtype,
parameter declaration
method used
to encode data
MIME version
encoded data
MIME types
Content-Type: type/subtype; parameters
Seven top-level types defined
Text
• example subtypes: plain, html
Image
• example subtypes: jpeg, gif
Application
• other data that must be processed by reader before
“viewable”
• example subtypes: msword, octet-stream
Mail access protocols
• SMTP: delivery/storage to receiver’s server
• Mail access protocol: retrieval from server
– POP: Post Office Protocol [RFC 1939]
• authorization (agent <-->server) and download
– IMAP: Internet Mail Access Protocol [RFC 1730]
• more features (more complex)
• manipulation of stored msgs on server
– HTTP: Hotmail , Yahoo! Mail, etc.
user
agent
sender’s mail
server
user
agent
SMTP SMTP access
protocol
receiver’s mail
server
Outline
• Electronic Mail: SMTP, POP3, IMAP
• DNS
• Socket programming with TCP
DNS: Domain Name System
People: many identifiers:
– SSN, name, passport #
Internet hosts, routers:
– IP address (32 bit) - used
for addressing datagrams
– “name”, e.g.,
home1.cs.nwu.edu - used
by humans
Q: map between IP
addresses and name ?
Domain Name System:
• distributed database
implemented in hierarchy of
many name servers
• application-layer protocol host,
routers, name servers to
communicate to resolve names
(address/name translation)
– note: core Internet function,
implemented as application-
layer protocol
– complexity at network’s
“edge”
DNS
DNS services
• Hostname to IP
address translation
• Host aliasing
– Canonical and alias
names
• Mail server aliasing
• Load distribution
– Replicated Web
servers: set of IP
addresses for one
canonical name
Why not centralize DNS?
• single point of failure
• traffic volume
• distant centralized
database
• maintenance
doesn’t scale!
Root DNS Servers
com DNS servers org DNS servers edu DNS servers
poly.edu
DNS servers
umass.edu
DNS servers
yahoo.com
DNS servers
amazon.com
DNS servers
pbs.org
DNS servers
Distributed, Hierarchical Database
Client wants IP for www.amazon.com; 1st approx:
• Client queries a root server to find com DNS
server
• Client queries com DNS server to get amazon.com
DNS server
• Client queries amazon.com DNS server to get IP
address for www.amazon.com
DNS: Root name servers
• contacted by local name server that can not resolve name
13 root name
servers worldwide
b USC-ISI Marina del Rey, CA
l ICANN Los Angeles, CA
e NASA Mt View, CA
f Internet Software C. Palo Alto,
CA (and 17 other locations)
i Autonomica, Stockholm (plus 3
other locations)
k RIPE London (also Amsterdam, Frankfurt)
m WIDE Tokyo
a Verisign, Dulles, VA
c Cogent, Herndon, VA (also Los Angeles)
d U Maryland College Park, MD
g US DoD Vienna, VA
h ARL Aberdeen, MD
j Verisign, ( 11 locations)
TLD and Authoritative Servers
• Top-level domain (TLD) servers: responsible
for com, org, net, edu, etc, and all top-level
country domains uk, fr, ca, jp.
– Network solutions maintains servers for com TLD
– Educause for edu TLD
• Authoritative DNS servers: organization’s
DNS servers, providing authoritative
hostname to IP mappings for organization’s
servers (e.g., Web and mail).
– Can be maintained by organization or service
provider
Local Name Server
• Does not strictly belong to hierarchy
• Each ISP (residential ISP, company,
university) has one.
– Also called “default name server”
• When a host makes a DNS query, query is
sent to its local DNS server
– Acts as a proxy, forwards query into hierarchy.
requesting host
cis.poly.edu
gaia.cs.umass.edu
root DNS server
local DNS server
dns.poly.edu
1
2
3
4
5
6
authoritative DNS server
dns.cs.umass.edu
7
8
TLD DNS server
Example
• Host at cis.poly.edu
wants IP address for
gaia.cs.umass.edu
requesting host
cis.poly.edu
gaia.cs.umass.edu
root DNS server
local DNS server
dns.poly.edu
1
2
4
5
6
authoritative DNS server
dns.cs.umass.edu
7
8
TLD DNS server
3
Recursive queries
recursive query:
• puts burden of name
resolution on
contacted name
server
• heavy load?
iterated query:
• contacted server
replies with name of
server to contact
• “I don’t know this
name, but ask this
server”
DNS: caching and updating records
• once (any) name server learns mapping, it caches
mapping
– cache entries timeout (disappear) after some
time
– TLD servers typically cached in local name
servers
• Thus root name servers not often visited
• update/notify mechanisms under design by IETF
– RFC 2136
– http://www.ietf.org/html.charters/dnsind-charter.html
DNS records
DNS: distributed db storing resource records (RR)
• Type=NS
– name is domain (e.g.
foo.com)
– value is IP address of
authoritative name server
for this domain
RR format: (name, value, type, ttl)
• Type=A
– name is hostname
– value is IP address
• Type=CNAME
– name is alias name for some
“cannonical” (the real) name
www.ibm.com is really
servereast.backup2.ibm.com
– value is cannonical name
• Type=MX
– value is name of mailserver
associated with name
Outline
• Electronic Mail: SMTP, POP3, IMAP
• DNS
• Socket programming with TCP
Socket programming
Socket API
• introduced in BSD4.1 UNIX,
1981
• explicitly created, used,
released by apps
• two types of transport
service via socket API:
– unreliable datagram
– reliable, byte stream
a host-local,
application-created,
OS-controlled interface
(a “door”) into which
application process can
both send and
receive messages to/from
another application
process
socket
Goal: learn how to build client/server application that
communicate using sockets
Socket-programming using TCP
Socket: a door between application process and end-
end-transport protocol (UCP or TCP)
TCP service: reliable transfer of bytes from one
process to another
process
TCP with
buffers,
variables
socket
controlled by
application
developer
controlled by
operating
system
host or
server
process
TCP with
buffers,
variables
socket
controlled by
application
developer
controlled by
operating
system
host or
server
internet
Socket programming with TCP
Client must contact server
• server process must first be
running
• server must have created
socket (door) that welcomes
client’s contact
Client contacts server by:
• creating client-local TCP
socket
• specifying IP address, port
number of server process
• When client creates socket:
client TCP establishes
connection to server TCP
• When contacted by client,
server TCP creates new
socket for server process to
communicate with client
– allows server to talk with
multiple clients
– source port numbers
used to distinguish
clients (more in Chap 3)
TCP provides reliable, in-order
transfer of bytes (“pipe”)
between client and server
application viewpoint
socket()
bind()
listen()
accept()
read()
write()
read()
close()
Socket()
connect()
write()
read()
close()
TCP Client
TCP Server
Well-known port
blocks until connection from client
process request
Connection establishment
Client – high level view
Create a socket
Setup the server address
Connect to the server
Read/write data
Shutdown connection
Creating a Socket
int socket(int family,int type,int
proto);
• Returns a socket descriptor
• family specifies the protocol family.
• type specifies the type of service
(SOCK_STREAM, SOCK_DGRAM).
• protocol specifies the specific protocol (usually
0, which means the default).
Address and port byte-ordering
• Address and port are stored as
integers
– u_short sin_port; (16 bit)
– in_addr sin_addr; (32 bit)
struct in_addr {
u_long s_addr;
};
 Problem:
 different machines / OS’s use different word orderings
• little-endian: lower bytes first
• big-endian: higher bytes first
 these machines may communicate with one another over the
network
128.119.40.12
128 119 40 12
12.40.119.128
128 119 40 12
Big-Endian
machine Little-Endian
machine
Solution: Network Byte-Ordering
• Defs:
– Host Byte-Ordering: the byte ordering used by
a host (big or little)
– Network Byte-Ordering: the byte ordering used
by the network – always big-endian
• Any words sent through the network should be
converted to Network Byte-Order prior to
transmission (and back to Host Byte-Order once
received)
 Q: Given big-endian machines don’t need
conversion routines and little-endian machines do,
how do we avoid writing two versions of code?
Network Byte Order Functions
• u_long htonl(u_long x);
• u_short htons(u_short x);
• u_long ntohl(u_long x);
• u_short ntohs(u_short x);
 On big-endian machines, these routines do nothing
 On little-endian machines, they reverse the byte
order
128.119.40.12
128 119 40 12
128.119.40.12
128 119 40 12
Big-Endian
machine Little-Endian
machine
ntohl
128 119 40 12 128
119
40
12
Network Byte Order Functions
‘h’ : host byte order ‘n’ : network byte order
‘s’ : short (16bit) ‘l’ : long (32bit)
uint16_t htons(uint16_t);
uint16_t ntohs(uint_16_t);
uint32_t htonl(uint32_t);
uint32_t ntohl(uint32_t);
connect()
int connect( int sockfd,
const struct sockaddr *server,
socklen_t addrlen);
sockfd is an already created TCP socket.
server contains the address of the server (IP
Address and TCP port number)
connect() returns 0 if OK, -1 on error
int connect_ socket( char *hostname, int port) {
int sock;
struct sockaddr_in sin;
struct hostent *host;
sock = socket( PF_ INET, SOCK_ STREAM, 0);
if (sock == -1)
return sock;
host = gethostbyname( hostname);
if (host == NULL) {
close( sock);
return -1;
}
memset (& sin, 0, sizeof( sin));
sin. sin_ family = AF_ INET;
sin. sin_ port = htons( port);
sin. sin_ addr. s_ addr = *( unsigned long *) host-> h_ addr_ list[ 0];
if (connect( sock, (struct sockaddr *) &sin, sizeof( sin)) != 0) {
close (sock);
return -1;
}
return sock;
}
Resolve the host
struct hostent *gethostbyname( const char *hostname);
/*Return nonnull pointer if OK, NULL on error */
Setup up the struct
unit16_t htons(unit16_t host16bitvaule)
/*Change the port number from host byte order to
network byte order */
Connect
connect(int socketfd, const struct sockaddr * servaddr,
socket_t addrlen)
/*Perform the TCP three way handshaking*/
Hostent structure
struct hostent{
char * h_name /*official name of host*/
char ** h_aliases; /* pointer ot array of
pointers to alias name*/
int h_addrtype /* host address type*/
int h_length /* length of address */
char ** h_addr_list /*prt to array of ptrs with 
IPv4 or IPv6 address*/
}
Ipv4 socket address structure
struct socketaddr_in{
uint8_t sin_len; /*length of the structure (16)*/
sa_falimily_t sin_family /* AF_INT*/
in_port_t sin_port /* 16 bit TCP or UDP port number*/
struct in_addr sin_addr /* 32 bit Ipv4 address */
char sin_zero(8)/* unused*/
}
Make the socket
Socket(int family , int type, in t protocol);
return nonnegative value for OK, -1 for error
Conclusions
• Ftp
• Electronic Mail: SMTP, POP3, IMAP
• DNS
• Socket programming with TCP

Contenu connexe

Similaire à 009478419.pdf

Similaire à 009478419.pdf (20)

08Mapping.ppt
08Mapping.ppt08Mapping.ppt
08Mapping.ppt
 
Dns
DnsDns
Dns
 
Topic 2.4 network services
Topic 2.4 network servicesTopic 2.4 network services
Topic 2.4 network services
 
Computer Networks Module 1 - part 2.pdf
Computer Networks Module 1 - part 2.pdfComputer Networks Module 1 - part 2.pdf
Computer Networks Module 1 - part 2.pdf
 
applayer.pptx
applayer.pptxapplayer.pptx
applayer.pptx
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
2. application layer
2. application layer2. application layer
2. application layer
 
Application layer
Application layerApplication layer
Application layer
 
DNS & HTTP overview
DNS & HTTP overviewDNS & HTTP overview
DNS & HTTP overview
 
Ftp.75 to 76
Ftp.75 to 76Ftp.75 to 76
Ftp.75 to 76
 
Application layer
Application layerApplication layer
Application layer
 
Dns detail understanding
Dns detail understandingDns detail understanding
Dns detail understanding
 
FTP
FTPFTP
FTP
 
Week3 lec 2
Week3 lec 2Week3 lec 2
Week3 lec 2
 
Tcpip services and applications
Tcpip services and applicationsTcpip services and applications
Tcpip services and applications
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
File service architecture and network file system
File service architecture and network file systemFile service architecture and network file system
File service architecture and network file system
 
Network Fundamentals: Ch3 - Application Layer Functionality and Protocols
Network Fundamentals: Ch3 - Application Layer Functionality and ProtocolsNetwork Fundamentals: Ch3 - Application Layer Functionality and Protocols
Network Fundamentals: Ch3 - Application Layer Functionality and Protocols
 
Lecture3
Lecture3Lecture3
Lecture3
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 

Plus de EidTahir

Servlets+JSP.ppt
Servlets+JSP.pptServlets+JSP.ppt
Servlets+JSP.pptEidTahir
 
servlets.ppt
servlets.pptservlets.ppt
servlets.pptEidTahir
 
005428058.pdf
005428058.pdf005428058.pdf
005428058.pdfEidTahir
 
005428055.pdf
005428055.pdf005428055.pdf
005428055.pdfEidTahir
 
2.J2EE_Overview.ppt
2.J2EE_Overview.ppt2.J2EE_Overview.ppt
2.J2EE_Overview.pptEidTahir
 
009458666.pdf
009458666.pdf009458666.pdf
009458666.pdfEidTahir
 
009921362.pdf
009921362.pdf009921362.pdf
009921362.pdfEidTahir
 
009445185.pdf
009445185.pdf009445185.pdf
009445185.pdfEidTahir
 
009705432.pdf
009705432.pdf009705432.pdf
009705432.pdfEidTahir
 
009694598.pdf
009694598.pdf009694598.pdf
009694598.pdfEidTahir
 
enterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdfenterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdfEidTahir
 
010118565.pdf
010118565.pdf010118565.pdf
010118565.pdfEidTahir
 
005528214.pdf
005528214.pdf005528214.pdf
005528214.pdfEidTahir
 
005432796.pdf
005432796.pdf005432796.pdf
005432796.pdfEidTahir
 
009586150.pdf
009586150.pdf009586150.pdf
009586150.pdfEidTahir
 
009551323.pdf
009551323.pdf009551323.pdf
009551323.pdfEidTahir
 
009723779.pdf
009723779.pdf009723779.pdf
009723779.pdfEidTahir
 
005443266.pdf
005443266.pdf005443266.pdf
005443266.pdfEidTahir
 
005237663.pdf
005237663.pdf005237663.pdf
005237663.pdfEidTahir
 

Plus de EidTahir (20)

Servlets+JSP.ppt
Servlets+JSP.pptServlets+JSP.ppt
Servlets+JSP.ppt
 
servlets.ppt
servlets.pptservlets.ppt
servlets.ppt
 
005428058.pdf
005428058.pdf005428058.pdf
005428058.pdf
 
005428055.pdf
005428055.pdf005428055.pdf
005428055.pdf
 
DNS.pptx
DNS.pptxDNS.pptx
DNS.pptx
 
2.J2EE_Overview.ppt
2.J2EE_Overview.ppt2.J2EE_Overview.ppt
2.J2EE_Overview.ppt
 
009458666.pdf
009458666.pdf009458666.pdf
009458666.pdf
 
009921362.pdf
009921362.pdf009921362.pdf
009921362.pdf
 
009445185.pdf
009445185.pdf009445185.pdf
009445185.pdf
 
009705432.pdf
009705432.pdf009705432.pdf
009705432.pdf
 
009694598.pdf
009694598.pdf009694598.pdf
009694598.pdf
 
enterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdfenterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdf
 
010118565.pdf
010118565.pdf010118565.pdf
010118565.pdf
 
005528214.pdf
005528214.pdf005528214.pdf
005528214.pdf
 
005432796.pdf
005432796.pdf005432796.pdf
005432796.pdf
 
009586150.pdf
009586150.pdf009586150.pdf
009586150.pdf
 
009551323.pdf
009551323.pdf009551323.pdf
009551323.pdf
 
009723779.pdf
009723779.pdf009723779.pdf
009723779.pdf
 
005443266.pdf
005443266.pdf005443266.pdf
005443266.pdf
 
005237663.pdf
005237663.pdf005237663.pdf
005237663.pdf
 

Dernier

Call Girls Near Delhi Pride Hotel, New Delhi|9873777170
Call Girls Near Delhi Pride Hotel, New Delhi|9873777170Call Girls Near Delhi Pride Hotel, New Delhi|9873777170
Call Girls Near Delhi Pride Hotel, New Delhi|9873777170Sonam Pathan
 
SBP-Market-Operations and market managment
SBP-Market-Operations and market managmentSBP-Market-Operations and market managment
SBP-Market-Operations and market managmentfactical
 
fca-bsps-decision-letter-redacted (1).pdf
fca-bsps-decision-letter-redacted (1).pdffca-bsps-decision-letter-redacted (1).pdf
fca-bsps-decision-letter-redacted (1).pdfHenry Tapper
 
NO1 WorldWide Genuine vashikaran specialist Vashikaran baba near Lahore Vashi...
NO1 WorldWide Genuine vashikaran specialist Vashikaran baba near Lahore Vashi...NO1 WorldWide Genuine vashikaran specialist Vashikaran baba near Lahore Vashi...
NO1 WorldWide Genuine vashikaran specialist Vashikaran baba near Lahore Vashi...Amil baba
 
212MTAMount Durham University Bachelor's Diploma in Technology
212MTAMount Durham University Bachelor's Diploma in Technology212MTAMount Durham University Bachelor's Diploma in Technology
212MTAMount Durham University Bachelor's Diploma in Technologyz xss
 
Classical Theory of Macroeconomics by Adam Smith
Classical Theory of Macroeconomics by Adam SmithClassical Theory of Macroeconomics by Adam Smith
Classical Theory of Macroeconomics by Adam SmithAdamYassin2
 
Stock Market Brief Deck FOR 4/17 video.pdf
Stock Market Brief Deck FOR 4/17 video.pdfStock Market Brief Deck FOR 4/17 video.pdf
Stock Market Brief Deck FOR 4/17 video.pdfMichael Silva
 
magnetic-pensions-a-new-blueprint-for-the-dc-landscape.pdf
magnetic-pensions-a-new-blueprint-for-the-dc-landscape.pdfmagnetic-pensions-a-new-blueprint-for-the-dc-landscape.pdf
magnetic-pensions-a-new-blueprint-for-the-dc-landscape.pdfHenry Tapper
 
(办理学位证)美国加州州立大学东湾分校毕业证成绩单原版一比一
(办理学位证)美国加州州立大学东湾分校毕业证成绩单原版一比一(办理学位证)美国加州州立大学东湾分校毕业证成绩单原版一比一
(办理学位证)美国加州州立大学东湾分校毕业证成绩单原版一比一S SDS
 
(中央兰开夏大学毕业证学位证成绩单-案例)
(中央兰开夏大学毕业证学位证成绩单-案例)(中央兰开夏大学毕业证学位证成绩单-案例)
(中央兰开夏大学毕业证学位证成绩单-案例)twfkn8xj
 
The Core Functions of the Bangko Sentral ng Pilipinas
The Core Functions of the Bangko Sentral ng PilipinasThe Core Functions of the Bangko Sentral ng Pilipinas
The Core Functions of the Bangko Sentral ng PilipinasCherylouCamus
 
原版1:1复刻堪萨斯大学毕业证KU毕业证留信学历认证
原版1:1复刻堪萨斯大学毕业证KU毕业证留信学历认证原版1:1复刻堪萨斯大学毕业证KU毕业证留信学历认证
原版1:1复刻堪萨斯大学毕业证KU毕业证留信学历认证jdkhjh
 
AfRESFullPaper22018EmpiricalPerformanceofRealEstateInvestmentTrustsandShareho...
AfRESFullPaper22018EmpiricalPerformanceofRealEstateInvestmentTrustsandShareho...AfRESFullPaper22018EmpiricalPerformanceofRealEstateInvestmentTrustsandShareho...
AfRESFullPaper22018EmpiricalPerformanceofRealEstateInvestmentTrustsandShareho...yordanosyohannes2
 
NO1 WorldWide online istikhara for love marriage vashikaran specialist love p...
NO1 WorldWide online istikhara for love marriage vashikaran specialist love p...NO1 WorldWide online istikhara for love marriage vashikaran specialist love p...
NO1 WorldWide online istikhara for love marriage vashikaran specialist love p...Amil Baba Dawood bangali
 
Financial Leverage Definition, Advantages, and Disadvantages
Financial Leverage Definition, Advantages, and DisadvantagesFinancial Leverage Definition, Advantages, and Disadvantages
Financial Leverage Definition, Advantages, and Disadvantagesjayjaymabutot13
 
Tenets of Physiocracy History of Economic
Tenets of Physiocracy History of EconomicTenets of Physiocracy History of Economic
Tenets of Physiocracy History of Economiccinemoviesu
 
letter-from-the-chair-to-the-fca-relating-to-british-steel-pensions-scheme-15...
letter-from-the-chair-to-the-fca-relating-to-british-steel-pensions-scheme-15...letter-from-the-chair-to-the-fca-relating-to-british-steel-pensions-scheme-15...
letter-from-the-chair-to-the-fca-relating-to-british-steel-pensions-scheme-15...Henry Tapper
 
原版1:1复刻温哥华岛大学毕业证Vancouver毕业证留信学历认证
原版1:1复刻温哥华岛大学毕业证Vancouver毕业证留信学历认证原版1:1复刻温哥华岛大学毕业证Vancouver毕业证留信学历认证
原版1:1复刻温哥华岛大学毕业证Vancouver毕业证留信学历认证rjrjkk
 
PMFBY , Pradhan Mantri Fasal bima yojna
PMFBY , Pradhan Mantri  Fasal bima yojnaPMFBY , Pradhan Mantri  Fasal bima yojna
PMFBY , Pradhan Mantri Fasal bima yojnaDharmendra Kumar
 

Dernier (20)

Call Girls Near Delhi Pride Hotel, New Delhi|9873777170
Call Girls Near Delhi Pride Hotel, New Delhi|9873777170Call Girls Near Delhi Pride Hotel, New Delhi|9873777170
Call Girls Near Delhi Pride Hotel, New Delhi|9873777170
 
SBP-Market-Operations and market managment
SBP-Market-Operations and market managmentSBP-Market-Operations and market managment
SBP-Market-Operations and market managment
 
fca-bsps-decision-letter-redacted (1).pdf
fca-bsps-decision-letter-redacted (1).pdffca-bsps-decision-letter-redacted (1).pdf
fca-bsps-decision-letter-redacted (1).pdf
 
NO1 WorldWide Genuine vashikaran specialist Vashikaran baba near Lahore Vashi...
NO1 WorldWide Genuine vashikaran specialist Vashikaran baba near Lahore Vashi...NO1 WorldWide Genuine vashikaran specialist Vashikaran baba near Lahore Vashi...
NO1 WorldWide Genuine vashikaran specialist Vashikaran baba near Lahore Vashi...
 
212MTAMount Durham University Bachelor's Diploma in Technology
212MTAMount Durham University Bachelor's Diploma in Technology212MTAMount Durham University Bachelor's Diploma in Technology
212MTAMount Durham University Bachelor's Diploma in Technology
 
Classical Theory of Macroeconomics by Adam Smith
Classical Theory of Macroeconomics by Adam SmithClassical Theory of Macroeconomics by Adam Smith
Classical Theory of Macroeconomics by Adam Smith
 
Stock Market Brief Deck FOR 4/17 video.pdf
Stock Market Brief Deck FOR 4/17 video.pdfStock Market Brief Deck FOR 4/17 video.pdf
Stock Market Brief Deck FOR 4/17 video.pdf
 
magnetic-pensions-a-new-blueprint-for-the-dc-landscape.pdf
magnetic-pensions-a-new-blueprint-for-the-dc-landscape.pdfmagnetic-pensions-a-new-blueprint-for-the-dc-landscape.pdf
magnetic-pensions-a-new-blueprint-for-the-dc-landscape.pdf
 
(办理学位证)美国加州州立大学东湾分校毕业证成绩单原版一比一
(办理学位证)美国加州州立大学东湾分校毕业证成绩单原版一比一(办理学位证)美国加州州立大学东湾分校毕业证成绩单原版一比一
(办理学位证)美国加州州立大学东湾分校毕业证成绩单原版一比一
 
(中央兰开夏大学毕业证学位证成绩单-案例)
(中央兰开夏大学毕业证学位证成绩单-案例)(中央兰开夏大学毕业证学位证成绩单-案例)
(中央兰开夏大学毕业证学位证成绩单-案例)
 
The Core Functions of the Bangko Sentral ng Pilipinas
The Core Functions of the Bangko Sentral ng PilipinasThe Core Functions of the Bangko Sentral ng Pilipinas
The Core Functions of the Bangko Sentral ng Pilipinas
 
原版1:1复刻堪萨斯大学毕业证KU毕业证留信学历认证
原版1:1复刻堪萨斯大学毕业证KU毕业证留信学历认证原版1:1复刻堪萨斯大学毕业证KU毕业证留信学历认证
原版1:1复刻堪萨斯大学毕业证KU毕业证留信学历认证
 
AfRESFullPaper22018EmpiricalPerformanceofRealEstateInvestmentTrustsandShareho...
AfRESFullPaper22018EmpiricalPerformanceofRealEstateInvestmentTrustsandShareho...AfRESFullPaper22018EmpiricalPerformanceofRealEstateInvestmentTrustsandShareho...
AfRESFullPaper22018EmpiricalPerformanceofRealEstateInvestmentTrustsandShareho...
 
NO1 WorldWide online istikhara for love marriage vashikaran specialist love p...
NO1 WorldWide online istikhara for love marriage vashikaran specialist love p...NO1 WorldWide online istikhara for love marriage vashikaran specialist love p...
NO1 WorldWide online istikhara for love marriage vashikaran specialist love p...
 
Financial Leverage Definition, Advantages, and Disadvantages
Financial Leverage Definition, Advantages, and DisadvantagesFinancial Leverage Definition, Advantages, and Disadvantages
Financial Leverage Definition, Advantages, and Disadvantages
 
Q1 2024 Newsletter | Financial Synergies Wealth Advisors
Q1 2024 Newsletter | Financial Synergies Wealth AdvisorsQ1 2024 Newsletter | Financial Synergies Wealth Advisors
Q1 2024 Newsletter | Financial Synergies Wealth Advisors
 
Tenets of Physiocracy History of Economic
Tenets of Physiocracy History of EconomicTenets of Physiocracy History of Economic
Tenets of Physiocracy History of Economic
 
letter-from-the-chair-to-the-fca-relating-to-british-steel-pensions-scheme-15...
letter-from-the-chair-to-the-fca-relating-to-british-steel-pensions-scheme-15...letter-from-the-chair-to-the-fca-relating-to-british-steel-pensions-scheme-15...
letter-from-the-chair-to-the-fca-relating-to-british-steel-pensions-scheme-15...
 
原版1:1复刻温哥华岛大学毕业证Vancouver毕业证留信学历认证
原版1:1复刻温哥华岛大学毕业证Vancouver毕业证留信学历认证原版1:1复刻温哥华岛大学毕业证Vancouver毕业证留信学历认证
原版1:1复刻温哥华岛大学毕业证Vancouver毕业证留信学历认证
 
PMFBY , Pradhan Mantri Fasal bima yojna
PMFBY , Pradhan Mantri  Fasal bima yojnaPMFBY , Pradhan Mantri  Fasal bima yojna
PMFBY , Pradhan Mantri Fasal bima yojna
 

009478419.pdf

  • 1. Some slides are in courtesy of J. Kurose and K. Ross Review of Previous Lecture • Principles of app layer protocols – clients and servers – app requirements • Web and HTTP
  • 2. Announcement • All got partners and IP addresses ? – One undergrad group can take an extra student • Should complete at least part I by the end of this week • Networking research projects available (preferably with OS background) – Quarter-long bonus project for undergrads – Extensible to 399, potential support available – Contact me after the class or in the OH
  • 3. FTP: the file transfer protocol • transfer file to/from remote host • client/server model – client: side that initiates transfer (either to/from remote) – server: remote host • ftp: RFC 959 • ftp server: port 21 file transfer FTP server FTP user interface FTP client local file system remote file system user at host
  • 4. FTP: separate control, data connections • FTP client contacts FTP server at port 21, specifying TCP as transport protocol • Client obtains authorization over control connection • Client browses remote directory by sending commands over control connection. • When server receives a command for a file transfer, the server opens a TCP data connection to client • After transferring one file, server closes connection. FTP client FTP server TCP control connection port 21 TCP data connection port 20 • Server opens a second TCP data connection to transfer another file. • Control connection: “out of band” • Stateful or stateless? – FTP server maintains “state”: current directory, earlier authentication
  • 5. Outline • Electronic Mail: SMTP, POP3, IMAP • DNS • Socket programming with TCP
  • 6. Electronic Mail Three major components: • user agents • mail servers • simple mail transfer protocol: SMTP User Agent • a.k.a. “mail reader” • composing, editing, reading mail messages • e.g., Eudora, Outlook, elm, Netscape Messenger • outgoing, incoming messages stored on server user mailbox outgoing message queue mail server user agent user agent user agent mail server user agent user agent mail server user agent SMTP SMTP SMTP
  • 7. Electronic Mail: mail servers Mail Servers • mailbox contains incoming messages for user • message queue of outgoing (to be sent) mail messages • SMTP protocol between mail servers to send email messages – client: sending mail server – “server”: receiving mail server mail server user agent user agent user agent mail server user agent user agent mail server user agent SMTP SMTP SMTP
  • 8. Electronic Mail: SMTP [RFC 2821] • uses TCP to reliably transfer email message from client to server, port 25 • direct transfer: sending server to receiving server • three phases of transfer – handshaking (greeting) – transfer of messages – closure • command/response interaction – commands: ASCII text – response: status code and phrase • messages must be in 7-bit ASCII
  • 9. Scenario: Alice sends message to Bob 1) Alice uses UA to compose message and “to” bob@someschool.edu 2) Alice’s UA sends message to her mail server; message placed in message queue 3) Client side of SMTP opens TCP connection with Bob’s mail server 4) SMTP client sends Alice’s message over the TCP connection 5) Bob’s mail server places the message in Bob’s mailbox 6) Bob invokes his user agent to read message user agent mail server mail server user agent 1 2 3 4 5 6
  • 10. SMTP: final words • SMTP uses persistent connections • SMTP requires message (header & body) to be in 7-bit ASCII Comparison with HTTP: • HTTP: pull • SMTP: push • both have ASCII command/response interaction, status codes
  • 11. Mail message format SMTP: protocol for exchanging email msgs RFC 822: standard for text message format: • header lines, e.g., – To: – From: – Subject: different from SMTP commands! • body – the “message”, ASCII characters only header body blank line
  • 12. Message format: multimedia extensions • MIME: multimedia mail extension, RFC 2045, 2056 • additional lines in msg header declare MIME content type From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data ..... ......................... ......base64 encoded data multimedia data type, subtype, parameter declaration method used to encode data MIME version encoded data
  • 13. MIME types Content-Type: type/subtype; parameters Seven top-level types defined Text • example subtypes: plain, html Image • example subtypes: jpeg, gif Application • other data that must be processed by reader before “viewable” • example subtypes: msword, octet-stream
  • 14. Mail access protocols • SMTP: delivery/storage to receiver’s server • Mail access protocol: retrieval from server – POP: Post Office Protocol [RFC 1939] • authorization (agent <-->server) and download – IMAP: Internet Mail Access Protocol [RFC 1730] • more features (more complex) • manipulation of stored msgs on server – HTTP: Hotmail , Yahoo! Mail, etc. user agent sender’s mail server user agent SMTP SMTP access protocol receiver’s mail server
  • 15. Outline • Electronic Mail: SMTP, POP3, IMAP • DNS • Socket programming with TCP
  • 16. DNS: Domain Name System People: many identifiers: – SSN, name, passport # Internet hosts, routers: – IP address (32 bit) - used for addressing datagrams – “name”, e.g., home1.cs.nwu.edu - used by humans Q: map between IP addresses and name ? Domain Name System: • distributed database implemented in hierarchy of many name servers • application-layer protocol host, routers, name servers to communicate to resolve names (address/name translation) – note: core Internet function, implemented as application- layer protocol – complexity at network’s “edge”
  • 17. DNS DNS services • Hostname to IP address translation • Host aliasing – Canonical and alias names • Mail server aliasing • Load distribution – Replicated Web servers: set of IP addresses for one canonical name Why not centralize DNS? • single point of failure • traffic volume • distant centralized database • maintenance doesn’t scale!
  • 18. Root DNS Servers com DNS servers org DNS servers edu DNS servers poly.edu DNS servers umass.edu DNS servers yahoo.com DNS servers amazon.com DNS servers pbs.org DNS servers Distributed, Hierarchical Database Client wants IP for www.amazon.com; 1st approx: • Client queries a root server to find com DNS server • Client queries com DNS server to get amazon.com DNS server • Client queries amazon.com DNS server to get IP address for www.amazon.com
  • 19. DNS: Root name servers • contacted by local name server that can not resolve name 13 root name servers worldwide b USC-ISI Marina del Rey, CA l ICANN Los Angeles, CA e NASA Mt View, CA f Internet Software C. Palo Alto, CA (and 17 other locations) i Autonomica, Stockholm (plus 3 other locations) k RIPE London (also Amsterdam, Frankfurt) m WIDE Tokyo a Verisign, Dulles, VA c Cogent, Herndon, VA (also Los Angeles) d U Maryland College Park, MD g US DoD Vienna, VA h ARL Aberdeen, MD j Verisign, ( 11 locations)
  • 20. TLD and Authoritative Servers • Top-level domain (TLD) servers: responsible for com, org, net, edu, etc, and all top-level country domains uk, fr, ca, jp. – Network solutions maintains servers for com TLD – Educause for edu TLD • Authoritative DNS servers: organization’s DNS servers, providing authoritative hostname to IP mappings for organization’s servers (e.g., Web and mail). – Can be maintained by organization or service provider
  • 21. Local Name Server • Does not strictly belong to hierarchy • Each ISP (residential ISP, company, university) has one. – Also called “default name server” • When a host makes a DNS query, query is sent to its local DNS server – Acts as a proxy, forwards query into hierarchy.
  • 22. requesting host cis.poly.edu gaia.cs.umass.edu root DNS server local DNS server dns.poly.edu 1 2 3 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server Example • Host at cis.poly.edu wants IP address for gaia.cs.umass.edu
  • 23. requesting host cis.poly.edu gaia.cs.umass.edu root DNS server local DNS server dns.poly.edu 1 2 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server 3 Recursive queries recursive query: • puts burden of name resolution on contacted name server • heavy load? iterated query: • contacted server replies with name of server to contact • “I don’t know this name, but ask this server”
  • 24. DNS: caching and updating records • once (any) name server learns mapping, it caches mapping – cache entries timeout (disappear) after some time – TLD servers typically cached in local name servers • Thus root name servers not often visited • update/notify mechanisms under design by IETF – RFC 2136 – http://www.ietf.org/html.charters/dnsind-charter.html
  • 25. DNS records DNS: distributed db storing resource records (RR) • Type=NS – name is domain (e.g. foo.com) – value is IP address of authoritative name server for this domain RR format: (name, value, type, ttl) • Type=A – name is hostname – value is IP address • Type=CNAME – name is alias name for some “cannonical” (the real) name www.ibm.com is really servereast.backup2.ibm.com – value is cannonical name • Type=MX – value is name of mailserver associated with name
  • 26. Outline • Electronic Mail: SMTP, POP3, IMAP • DNS • Socket programming with TCP
  • 27. Socket programming Socket API • introduced in BSD4.1 UNIX, 1981 • explicitly created, used, released by apps • two types of transport service via socket API: – unreliable datagram – reliable, byte stream a host-local, application-created, OS-controlled interface (a “door”) into which application process can both send and receive messages to/from another application process socket Goal: learn how to build client/server application that communicate using sockets
  • 28. Socket-programming using TCP Socket: a door between application process and end- end-transport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server process TCP with buffers, variables socket controlled by application developer controlled by operating system host or server internet
  • 29. Socket programming with TCP Client must contact server • server process must first be running • server must have created socket (door) that welcomes client’s contact Client contacts server by: • creating client-local TCP socket • specifying IP address, port number of server process • When client creates socket: client TCP establishes connection to server TCP • When contacted by client, server TCP creates new socket for server process to communicate with client – allows server to talk with multiple clients – source port numbers used to distinguish clients (more in Chap 3) TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint
  • 31. Client – high level view Create a socket Setup the server address Connect to the server Read/write data Shutdown connection
  • 32. Creating a Socket int socket(int family,int type,int proto); • Returns a socket descriptor • family specifies the protocol family. • type specifies the type of service (SOCK_STREAM, SOCK_DGRAM). • protocol specifies the specific protocol (usually 0, which means the default).
  • 33. Address and port byte-ordering • Address and port are stored as integers – u_short sin_port; (16 bit) – in_addr sin_addr; (32 bit) struct in_addr { u_long s_addr; };  Problem:  different machines / OS’s use different word orderings • little-endian: lower bytes first • big-endian: higher bytes first  these machines may communicate with one another over the network 128.119.40.12 128 119 40 12 12.40.119.128 128 119 40 12 Big-Endian machine Little-Endian machine
  • 34. Solution: Network Byte-Ordering • Defs: – Host Byte-Ordering: the byte ordering used by a host (big or little) – Network Byte-Ordering: the byte ordering used by the network – always big-endian • Any words sent through the network should be converted to Network Byte-Order prior to transmission (and back to Host Byte-Order once received)  Q: Given big-endian machines don’t need conversion routines and little-endian machines do, how do we avoid writing two versions of code?
  • 35. Network Byte Order Functions • u_long htonl(u_long x); • u_short htons(u_short x); • u_long ntohl(u_long x); • u_short ntohs(u_short x);  On big-endian machines, these routines do nothing  On little-endian machines, they reverse the byte order 128.119.40.12 128 119 40 12 128.119.40.12 128 119 40 12 Big-Endian machine Little-Endian machine ntohl 128 119 40 12 128 119 40 12
  • 36. Network Byte Order Functions ‘h’ : host byte order ‘n’ : network byte order ‘s’ : short (16bit) ‘l’ : long (32bit) uint16_t htons(uint16_t); uint16_t ntohs(uint_16_t); uint32_t htonl(uint32_t); uint32_t ntohl(uint32_t);
  • 37. connect() int connect( int sockfd, const struct sockaddr *server, socklen_t addrlen); sockfd is an already created TCP socket. server contains the address of the server (IP Address and TCP port number) connect() returns 0 if OK, -1 on error
  • 38. int connect_ socket( char *hostname, int port) { int sock; struct sockaddr_in sin; struct hostent *host; sock = socket( PF_ INET, SOCK_ STREAM, 0); if (sock == -1) return sock; host = gethostbyname( hostname); if (host == NULL) { close( sock); return -1; } memset (& sin, 0, sizeof( sin)); sin. sin_ family = AF_ INET; sin. sin_ port = htons( port); sin. sin_ addr. s_ addr = *( unsigned long *) host-> h_ addr_ list[ 0]; if (connect( sock, (struct sockaddr *) &sin, sizeof( sin)) != 0) { close (sock); return -1; } return sock; } Resolve the host struct hostent *gethostbyname( const char *hostname); /*Return nonnull pointer if OK, NULL on error */ Setup up the struct unit16_t htons(unit16_t host16bitvaule) /*Change the port number from host byte order to network byte order */ Connect connect(int socketfd, const struct sockaddr * servaddr, socket_t addrlen) /*Perform the TCP three way handshaking*/ Hostent structure struct hostent{ char * h_name /*official name of host*/ char ** h_aliases; /* pointer ot array of pointers to alias name*/ int h_addrtype /* host address type*/ int h_length /* length of address */ char ** h_addr_list /*prt to array of ptrs with IPv4 or IPv6 address*/ } Ipv4 socket address structure struct socketaddr_in{ uint8_t sin_len; /*length of the structure (16)*/ sa_falimily_t sin_family /* AF_INT*/ in_port_t sin_port /* 16 bit TCP or UDP port number*/ struct in_addr sin_addr /* 32 bit Ipv4 address */ char sin_zero(8)/* unused*/ } Make the socket Socket(int family , int type, in t protocol); return nonnegative value for OK, -1 for error
  • 39. Conclusions • Ftp • Electronic Mail: SMTP, POP3, IMAP • DNS • Socket programming with TCP