lecture 2 overview - university of otago · • local socket address: local ip address and port...
TRANSCRIPT
![Page 1: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/1.jpg)
Lecture 2 Overview!• This Lecture!– Protocol layering!– Source: Comer’s book (Chapter 10)!– TCP and UDP!– Source: Chapter 2 of Stevens� book!– Sockets introduction!– Source: Chapter 3 of Stevens� book!
• Next Lecture!– Elementary TCP sockets!– Source: Chapter 4 of Stevens� book!– TCP Client-Server example!– Source: Chapter 5 of Stevens� book!
TELE402 2012 Lecture 2 Introduction of TCP/IP 1
![Page 2: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/2.jpg)
Protocol Layering (1)!• Why do we need communication protocols?!!
!Allow one to specify or understand communication without knowing the ! details of the network hardware!
• What problems might arise when machines communicate over a network?!– Hardware failure – Network congestion – Packet delay or loss – Data corruption – Data duplication or inverted arrivals
TELE402 2012 Lecture 2 Introduction of TCP/IP 2
![Page 3: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/3.jpg)
Protocol Layering (2)!• Is it possible to design a single protocol which handles
all problems occurred during data communication? ! might be possible, but very difficult !• Layered design approach!– Not new to communication protocol design
TELE402 2012 Lecture 2 Introduction of TCP/IP 3
Computer system!
hardware'
operating system!
application software!
Programming languages!
Unstructured (COBOL) !
structured (C) !
Object-oriented (C++)!
Component-based (NesC)!
![Page 4: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/4.jpg)
Layered Models for Communication Systems !
TELE402 2012 Lecture 2 Introduction of TCP/IP 4
OSI Model!
Physical'
Presenta0on'
Session'
Transport'
Network'
Data'Link'
Applica0on'
TCP/IP Model!
Hardware'
Transport'
Internet'
Network'Interface'
Applica0on'
![Page 5: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/5.jpg)
The Protocol Layering Principle!
!
!
• Pros and Cons!– Modularity, simplicity, interoperability, robustness, security,
cost effective – Complexity, process time, memory usage, prevention from
optimization
TELE402 2012 Lecture 2 Introduction of TCP/IP 5
Layered protocols are designed so that layer n at the destination receives exactly the same object sent by layer n at the source
![Page 6: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/6.jpg)
Multiplexing/Demultiplexing!• Multiplexing and demultiplexing occur at almost every
protocol layer!
• Example: multiplexing and demultiplexing at the transport layer
TELE402 2012 Lecture 2 Introduction of TCP/IP 6
multiplexer! demultiplexer!
IP! IP!
processes! processes!
![Page 7: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/7.jpg)
TELE402 2012! Lecture 2 Introduction of TCP/IP! 7!
The TCP/IP Protocol Suit! (The Internet Protocol Suite)!
![Page 8: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/8.jpg)
Example: Client and Server (1)!• Simple model!– One server, multiple clients!
• How to make applications robust?!
TELE402 2012 Lecture 2 Introduction of TCP/IP 8
client' server'link!
protocol!
client'
server'client'
client'
…!
…!
![Page 9: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/9.jpg)
Example: Client and Server (2)!• Local Area Network (LAN) Scenario!
TELE402 2012 Lecture 2 Introduction of TCP/IP 9
![Page 10: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/10.jpg)
Example: Client and Server (3)!• Wide Area Network (WAN) Scenario!
TELE402 2012 Lecture 2 Introduction of TCP/IP 10
![Page 11: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/11.jpg)
How to Develop the Program?!• Socket Programming!• What is a socket?!
– Sockets represent endpoints in a line of communication.!– A socket is a software component characterized by a unique
combination of !• Local socket address: local IP address and port number!• Remote socket address: only for TCP sockets!• Protocol: TCP, UDP!
TELE402 2012 Lecture 2 Introduction of TCP/IP 11
telephone'
network'
Without the telephone network, each endpoint of a telephone line is nothing more than a plastic box.!
![Page 12: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/12.jpg)
Socket Programming!
TELE402 2012 Lecture 2 Introduction of TCP/IP 12
• Socket Address: the combination of an IP address and a port number (a 16-bit unsigned integer, ranging from 0 to 65535).!
• Socket API: an application programming interface, usually provided by the operating system.
![Page 13: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/13.jpg)
A Simple TCP Daytime Client!
TELE402 2012! Lecture 2 Introduction of TCP/IP! 13!
�include "unp.h”! int! main(int argc, char **argv)! {! int sockfd, n;! struct sockaddr_in6 servaddr;! char recvline[MAXLINE + 1];! if (argc != 2)! err_quit("usage: a.out <IPaddress>");! if ( (sockfd = socket(AF_INET6, SOCK_STREAM, 0)) < 0) err_sys("socket error");! bzero(&servaddr, sizeof(servaddr));! servaddr.sin6_family = AF_INET6;! servaddr.sin6_port = htons(13);/* daytime server */! if (inet_pton(AF_INET6, argv[1], &servaddr.sin6_addr) <= 0)! err_quit("inet_pton error for %s", argv[1]);! if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0) err_sys("connect error");! while ( (n = read(sockfd, recvline, MAXLINE)) > 0) {! recvline[n] = 0; /* null terminate */! if (fputs(recvline, stdout) == EOF)! err_sys("fputs error");! }! if (n < 0) err_sys("read error");! exit(0);!}!!!
Create'a'TCP'socket'(socket)'
Specify server’s IP address and port !
Connect to the server (connect)!
Send request or receive reply!(send & recv)!
Terminate program (close socket) !
![Page 14: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/14.jpg)
A Simple TCP Server!
TELE402 2012! Lecture 2 Introduction of TCP/IP! 14!
�include"unp.h"!#include<time.h>!int main(int argc, char **argv)!{! intlistenfd, connfd;! struct sockaddr_inservaddr;! charbuff[MAXLINE];! time_tticks;! listenfd = Socket(AF_INET, SOCK_STREAM, 0);! bzero(&servaddr, sizeof(servaddr));! servaddr.sin_family= AF_INET;! servaddr.sin_addr.s_addr = htonl(INADDR_ANY);! servaddr.sin_port= htons(13); /* daytime server */!! Bind(listenfd, (SA *) &servaddr, sizeof(servaddr));! Listen(listenfd, LISTENQ);! for ( ; ; ) {! connfd = Accept(listenfd, (SA *) NULL, NULL);! ticks = time(NULL);! snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));! Write(connfd, buff, strlen(buff));! Close(connfd);! }!}!!!
Create'a'TCP'socket'(socket)'
Specify server’s IP address and port !
Bind socket with local port (Bind)!
Receive or reply (send & recv)!Terminate connection (Close) !
Convert the socket to listening socket (Listen)!
Accept client connection (Accept)!
![Page 15: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/15.jpg)
Discovering Details of Your Local Network!
TELE402 2012 Lecture 2 Introduction of TCP/IP 15
• To find out interfaces: netstat -ni • To find out routing table: netstat -rn • To find out details of an interface: ifconfig • To discover hosts on a LAN: ping
![Page 16: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/16.jpg)
TCP/IP vs OSI!
TELE402 2012 Lecture 2 Introduction of TCP/IP 16
![Page 17: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/17.jpg)
Unix standards!• Unix has different standards, which have different
networking APIs!• POSIX!– Portable Operating System Interface!– Developed by IEEE!– Linux follows this standard!
• BSD!– Berkeley Software Distribution!– Socket API originated from BSD!
• We won’t pay much attention to the differences, but will mention them when necessary.!
TELE402 2012 Lecture 2 Introduction of TCP/IP 17
![Page 18: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/18.jpg)
TCP/IP Protocol Suite!
TELE402 2012! Lecture 2 Introduction of TCP/IP! 18!
![Page 19: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/19.jpg)
IP Packet Format !
TELE402 2012! Lecture 2 Introduction of TCP/IP! 19!
![Page 20: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/20.jpg)
User Datagram Protocol (UDP)!• A simple transport-layer protocol!– RFC 786!
• UDP datagram is encapsulated into an IP packet!• A connection-less service!• No reliability guaranteed!– Datagram may get lost!– Once delivered to applications, data in the datagram is error-
free (Why?)!• UDP data can be considered as records which have
boundaries according to datagram!
TELE402 2012 Lecture 2 Introduction of TCP/IP 20
![Page 21: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/21.jpg)
Format of UDP messages!• Each UDP message is called a user datagram
• Why does UDP have checksum in addition to IP checksum?!
• The UDP checksum is optional; a value of zero means the checksum is not computed. !
• Why is UDP created in addition to IP?!
!!
TELE402 2012 Lecture 2 Introduction of TCP/IP 21
UDP'SOURCE'PORT' UDP'DESTINATION'PORT'
UDP'MESSAGE'LENGTH' UDP'CHECKSUM'
DATA'
…'
0! 16! 31!
Header!
![Page 22: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/22.jpg)
UDP Pseudo-Header!
• UDP checksum covers both the pseudo-header and the UPD datagram. Why?!
• The PROTO field contains the IP protocol type code (17 for UDP)!• The ZERO field is an octet of zeros for padding, not transmitted.!• Name registration for UDP ports!– Use program name id to find the local port?!– Use process id to replace the local port?!
TELE402 2012 Lecture 2 Introduction of TCP/IP 22
ZERO' UDP'CHECKSUM'
SOURCE'IP'ADDRESS'
0! 16! 31!
DESTINATION'IP'ADDRESS'
PROTO'
![Page 23: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/23.jpg)
Reliable Delivery Service!• Stream oriented!– In order delivery!
• Virtual circuit connection!– Both parties should be ready and responsive to loss of
data!
• Buffered transfer!– For retransmission!
• Unstructured stream!• Full duplex!• Acknowledgment and retransmission!
TELE402 2012 Lecture 2 Introduction of TCP/IP 23
![Page 24: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/24.jpg)
Transmission Control Protocol (TCP)!• RFC 793!• A connection-oriented service!– A connection is established before exchanging data!
• Reliability is guaranteed (?)!– Acknowledgment is used to confirm the reception of data;
Round Trip Time (RTT) is used for retransmission!– Data are sequenced byte by byte!
• Flow control is used to adapt to the speed difference between the sender and receiver.!– The sliding window mechanism !
• A TCP connection is full-duplex just like UDP!
TELE402 2012 Lecture 2 Introduction of TCP/IP 24
![Page 25: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/25.jpg)
Connection establishment!• Three-way handshake!
TELE402 2012 Lecture 2 Introduction of TCP/IP 25
![Page 26: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/26.jpg)
TCP options!• MSS option: Maximum Segment Size!– With this option the TCP sending the SYN announces the
maximum amount of data that it is willing to accept in each TCP segment!
• Window scale option!– The maximum window that either TCP can advertise to the
other TCP is 65535 (16 bits for window size)!• Timestamp option!– New option needed for high-speed connections to prevent
possible data corruption caused by lost packets that then reappear. No worries for network programmers.!
TELE402 2012 Lecture 2 Introduction of TCP/IP 26
![Page 27: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/27.jpg)
Connection termination!
TELE402 2012 Lecture 2 Introduction of TCP/IP 27
![Page 28: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/28.jpg)
TCP state transition!
TELE402 2012! Lecture 2 Introduction of TCP/IP! 28!
![Page 29: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/29.jpg)
Packet exchange!
TELE402 2012! Lecture 2 Introduction of TCP/IP! 29!
![Page 30: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/30.jpg)
TIME_WAIT state!• Why need TIME_WAIT state?!– To implement TCP’s full-duplex connection termination
reliably!– To allow old duplicate segments to expire in the network!
• The time to remain in this state is 2*MSL!– MSL is Maximum Segment Lifetime (the maximum amount
of time that any given IP datagram can live in an Internet)!– The recommended value for MSL is 2 minutes in RFC 1122,
though BSD used a value of 30 seconds!– So the time for TIME_WAIT state is between 1 and 4
minutes!
TELE402 2012 Lecture 2 Introduction of TCP/IP 30
![Page 31: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/31.jpg)
Port numbers!• Well-known ports!– 0-1024!– Controlled and assigned by IANA (Internet Assigned
Number Authority)!• Registered ports!– 1024-49151!– Not controlled by IANA, but IANA registers and lists the
uses of these ports as a convenience to the community!• Dynamic (or private) ports!– 49152-65535, also called ephemeral ports!
• Reserved (privileged) ports in Unix, 0-1024!
TELE402 2012 Lecture 2 Introduction of TCP/IP 31
![Page 32: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/32.jpg)
Concurrent servers and port!• Socket pair!– A 4-tuple for a TCP connection, which uniquely identifies
the TCP connection!– local IP address, local TCP port, foreign IP address, and
foreign TCP port!
TELE402 2012 Lecture 2 Introduction of TCP/IP 32
![Page 33: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/33.jpg)
Concurrent servers and port (cont.)!
TELE402 2012 Lecture 2 Introduction of TCP/IP 33
![Page 34: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/34.jpg)
Concurrent servers and port (cont.)!
TELE402 2012 Lecture 2 Introduction of TCP/IP 34
![Page 35: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/35.jpg)
IP Limitations!• Maximum size of IP datagrams!– IPv4, 65535 bytes, including IPv4 header!– IPv6, 65575 bytes, including the 40-byte IPv6 header!
• Many networks have an MTU (Maximum Transmission Unit)!– Ethernet 1500 bytes!
• Path MTU!– the smallest MTU in the path between two hosts!
• Fragmentation is needed if an IP datagram exceeds the link MTU!
TELE402 2012 Lecture 2 Introduction of TCP/IP 35
![Page 36: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/36.jpg)
IP Limitations (cont.)!• The DF (Don’t fragment) bit can be set for non-
fragmentation!• Minimum reassembly buffer size!– the minimum datagram size that we are guaranteed any
implementation must support!– IPv4, 576 bytes; IPv6, 1500 bytes!
• Maximum Segment Size (MSS) for TCP!– Announce to the peer TCP the maximum amount of TCP data
that the peer can send per segment!– MSS is normally set to the interface MTU minus the fixed
sizes of the IP and TCP headers!
TELE402 2012 Lecture 2 Introduction of TCP/IP 36
![Page 37: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/37.jpg)
TCP Output!
TELE402 2012 Lecture 2 Introduction of TCP/IP 37
![Page 38: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/38.jpg)
UDP Output!
TELE402 2012 Lecture 2 Introduction of TCP/IP 38
![Page 39: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/39.jpg)
Socket Introduction!• Socket API is the popular fundamental
networking API in Unix/Linux!• BSD socket released in 1983.!• POSIX socket API!– POSIX.1g, approved in 2000.!
TELE402 2012 Lecture 2 Introduction of TCP/IP 39
![Page 40: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/40.jpg)
Socket Address Structure!
• Posix.1g definition!
TELE402 2012 Lecture 2 Introduction of TCP/IP 40
![Page 41: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/41.jpg)
Posix.1g Data Types!
TELE402 2012 Lecture 2 Introduction of TCP/IP 41
![Page 42: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/42.jpg)
Generic Socket Address!• Generic socket address structure is proposed to deal
with addresses of supported protocol families!– Defined in the <sys/socket.h> header!
TELE402 2012 Lecture 2 Introduction of TCP/IP 42
![Page 43: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/43.jpg)
Using the generic socket address!
Function prototype:! int bind(int, struct sockaddr *, socklen_t)!!Using bind:! struct sockaddr_in serv;! /* fill in serv{} */! bind(sockdf, (struct sockaddr *) &serv, sizeof(serv));!
TELE402 2012 Lecture 2 Introduction of TCP/IP 43
![Page 44: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/44.jpg)
IPv6 Socket Address!
TELE402 2012 Lecture 2 Introduction of TCP/IP 44
![Page 45: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/45.jpg)
Various socket addresses!
TELE402 2012 Lecture 2 Introduction of TCP/IP 45
![Page 46: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/46.jpg)
Value-Result Arguments!
• connect(sockfd, &serv, sizeof(serv));!
TELE402 2012 Lecture 2 Introduction of TCP/IP 46
![Page 47: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/47.jpg)
Value-Result arguments (cont.)!
• accept(sockfd, &from, &len);!
TELE402 2012 Lecture 2 Introduction of TCP/IP 47
![Page 48: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/48.jpg)
Byte order!• Little-endian and big-endian!
TELE402 2012 Lecture 2 Introduction of TCP/IP 48
![Page 49: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/49.jpg)
Byte ordering functions!
• uint16_t htons(uint16_t host16bitvalue);!• uint32_t htonl(uint32_t host32bitvalue);!• uint16_t ntohs(uint16_t net16bitvalue);!• uint32_t ntohl(uint32_t net32bitvalue);!
TELE402 2012 Lecture 2 Introduction of TCP/IP 49
![Page 50: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/50.jpg)
Byte manipulation functions!
• Berkeley-derived!– void bzero(void *dest, size_t nbytes);!– void bcopy(const void *src, void *dest, !! !size_t nbytes);!– int bcmp(const void &ptr1, const void *ptr2, !! !size_t nbytes);!
TELE402 2012 Lecture 2 Introduction of TCP/IP 50
![Page 51: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/51.jpg)
Byte manipulation functions (cont)!• ANSI C!– void *memset(void *dest, int c, size_t len);!– void *memcpy(void *dest, const void *src, !! !size_t nbytes);!– int memcmp(const void *ptr1, const void *ptr2, !! !size_t nbytes);!
TELE402 2012 Lecture 2 Introduction of TCP/IP 51
![Page 52: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/52.jpg)
Address conversion functions!
• Traditional functions!– int inet_aton(const char *strptr, !! !struct in_addr *addrptr);!– char *inet_ntoa(struct in_addr inaddr);!
– inet_addr (deprecated)!
TELE402 2012 Lecture 2 Introduction of TCP/IP 52
![Page 53: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/53.jpg)
Address conversion functions (continued)!
• int inet_pton(int family, const char *strptr,!!!void *addrptr);!• const char *inet_ntop(int family, !!!const void *addrptr, !!!char *strptr, size_t len);!• #define INET_ADDRSTRLEN 16!• #define INET6_ADDRSTRLEN 46!
TELE402 2012 Lecture 2 Introduction of TCP/IP 53
![Page 54: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/54.jpg)
Address conversion functions!• How to make functions independent of protocols?!
TELE402 2012 Lecture 2 Introduction of TCP/IP 54
![Page 55: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/55.jpg)
More functions!
TELE402 2012 Lecture 2 Introduction of TCP/IP 55
![Page 56: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/56.jpg)
More functions (cont.)!
TELE402 2012 Lecture 2 Introduction of TCP/IP 56
![Page 57: Lecture 2 Overview - University of Otago · • Local socket address: local IP address and port number! • Remote socket address: only for TCP sockets! • Protocol: TCP, UDP! TELE402](https://reader034.vdocuments.us/reader034/viewer/2022042221/5ec7445433c6bc10b545647c/html5/thumbnails/57.jpg)
Questions!• What is the Protocol Layering Principle? What are the
advantages and disadvantages of protocol layering?!• What defines a TCP connection?!• What is the difference between TCP segment size and TCP
window size?!• How can the delay, bandwidth, load, and packet loss affect TCP
retransmission?!• Explain the relationship between RTT, bandwidth, and window
size. !• What are passive open connection and active open connection?!
TELE402 2012 Lecture 2 Introduction of TCP/IP 57