Documente Academic
Documente Profesional
Documente Cultură
to Network Programming in
UNIX & LINUX
Daniel Zinchin
Tel-Ran Ltd 2008-2009
D.Zinchin [zinchin@gmail.com]
Instead of
Rabbi Avraham Yaakov 100 years ago taught his Chassids:"
Preamble
- It is possible to learn from anything. Everythinginthis
world exists to edify us.
Not only whatthe Lord has made, but also whatpeople have
made, makes us wise.
-What, for example, do we learn from a railway? - one
Chassid asked in doubt
- That, having been late for an instant, it is possible to miss
entirely.
- And telegraph?
- That each word is taken into account.
- And phone?
- That everything told by you here, is audible there.
1-2
Course Contents
Network Primes
Inter-Process
INTERNET
Independent Network
Communication (IPC)
Inter-Host
Host
Process
Communication (IHC)
Thread
Multi-Threading and
Synchronization
D.Zinchin [zinchin@gmail.com]
1-3
W. Richard Stevens
personal site:
www.kohala.com
2. W. Richard Stevens.
UNIX Network Programming, 2nd Edition,
Prentice Hall, 1998-99.
Vol.1 Networking APIs
Vol.2 Interprocess Communications
3. W. Richard Stevens.
TCP/IP Illustrated.
Addison-Wesley, 1994-1996
Vol.1 The Protocols
Vol.2 The Implementation
Vol.3 TCP for Transactions, HTTP, NNTP,
and the UNIX Domain Protocols
4. Douglas E. Cormer.
Internetworking with TCP/IP
D.Zinchin [zinchin@gmail.com]
Kolman Shkolnik.
Introduction to Internetworking in UNIX.
Tel-Ran 1995
1-4
The History
<1960
1960
1965
1969
1971-75
1976
1978
1980
1983
1983
1984-86
1986
1988
End 80s
1988
1989
1991
1992
1994
2000
>2000
D.Zinchin [zinchin@gmail.com]
1-5
Basic Terms
Computer Network
Communication system for connecting end-systems. Enables to
share data, programs and resources (distributed systems).
There are physical networks and logical networks.
Host
Single computer, end-system. Could be personal computer, dedicated
system (print or file server) or time-sharing system.
Process
Any program which is executed by computers operation system.
Thread
Separate part of process, providing its specific working flow,
and sharing the process data and resources with other threads.
Inter-Process Communication
Sharing of information and resources by two or more different processes.
Inter-Host Communication
Communication between two or more processes, running on different
hosts in the network.
Communication Protocol
Set of rules and conventions that communication participants must
follow.
D.Zinchin [zinchin@gmail.com]
1-6
What is Internet
Internet
Set of interconnected independent computer networks.
Uses common suite of protocols called TCP/IP.
Managed by groups of representatives:
IAB
-Internet Activity Board
NIC
-National Information Center
FNC
-Federal Network Center
RFC - Request For Comments
Internet Services
Transport Level:
Unreliable packet delivery
Reliable stream transport
Application Level:
File Transfer (FTP, TFTP)
Electronic Mail (SMTP)
Remote Login (TELNET)
Network File System (NFS)
Remote Program Execution
Shared peripheral devices
D.Zinchin [zinchin@gmail.com]
1-7
D.Zinchin [zinchin@gmail.com]
Knowledge
Knowledge
Concepts
Concepts
Speech
Speech
Voice
Voice
Transmitter
Receiver
Sound Waves
1-8
messages
6 Presentation
messages
(kinds of compression)
5 Session
messages
OSI Model
Open System Interconnection Model
ISO
International Standard Organization
(dialog management)
4 Transport
datagrams
(inter-process level)
3 Network
packets
(inter-host level)
2 Data Link
(network topology)
1 Physical
D.Zinchin [zinchin@gmail.com]
frames
bits
1-9
7 Application
6 Presentation
messages
(kinds of compression)
5 Session
Application
(communication
end-point)
(dialog management)
4 Transport
datagrams
(inter-process level)
3 Network
packets
(inter-host level)
2 Data Link
(network topology)
1 Physical
D.Zinchin [zinchin@gmail.com]
frames
bits
Transport
(inter-process level)
Network
(inter-host level)
Data Link
(network topology &
physical connection)
1-10
Network
Data Link
Application
messages
Transport
datagrams
Network
packets
Data Link
frames
physical connection
bits
D.Zinchin [zinchin@gmail.com]
end-point communication
inter-process communication
inter-host communication
topology-specific interface with physical network
1-11
Application 1
user application
Application 0
TFTP
Provided by
kernel of OS
UNIX
messages/
stream
Internet Protocol
ICMP
Transport
UDP
TCP
IP
ICMP
Network
Data Link
ARP
RARP
Ethernet
Token Ring
datagrams
packets
frames
Ethernet
A local area network architecture
with broadcast bus topology
physical connection
bits
IP Address + Port
UDP
Physical Address
Token Ring
A local area network architecture
with ring topology and token
passing scheme
D.Zinchin [zinchin@gmail.com]
1-12
Network
LAN
MAN
Network
Type
Speed
LAN
Coaxial cable,
fiber optics,
Wi-Fi (wireless
technology)
MAN
Coaxial cable,
microwave link
56 Kbit/s
155 Mbit/s
WAN
Telephone lines,
microwave link,
satellite channels
9.6 Kbit/s
45 Mbit/s
WAN
Technology
4 Mbit/s
2 Gbit/s
D.Zinchin [zinchin@gmail.com]
1-13
Communication Activities
Data Transmission
Communication Networks can be divided into two basic types by method of data
transmission: circuit-switched and packet-switched.
Encapsulation
Encapsulation is hiding of object data from rest of the world. For protocol suite this
means adding of control information to data when going one layer down.
Multiplexing and Demultiplexing
Multiplexing means to combine many into one. For network this means combining of
data accepted from different functionalities of neighbor layer.
Demultiplexing is reverse of multiplexing.
Routing
Routing is making decision, what route the packet should take.
Static Routing is based on precomputed information.
Dynamic Routing is depends on state of network configuration in the specific moment of
time.
Fragmentation and Reassembling
Fragmentation (or segmentation) is breaking up of a packet into smaller pieces
(MTU maximal transmission unit)
Reassembling is reverse of fragmentation, it is restoring of original packet from smaller
pieces used for transmission.
D.Zinchin [zinchin@gmail.com]
1-14
circuit
hop
hop
hop
hop
hop
1-15
very
Data
Application
data
Data
TFTP
message
UDP TFTP
header header
Data
UDP
datagram
IP
UDP TFTP
header header header
Data
IP
packet
Ethernet
IP
UDP TFTP
header header header header
Data
Ethernet
trailer
400
TFTP
header
Bytes: 22
20
D.Zinchin [zinchin@gmail.com]
interes
ti
ng
letter
address
ss
dre
ad
s
dre
ad
Ethernet
frame
1-16
Process 2
Process 3
Process 4
Process 5
Multiplexing
UDP
TCP
IP
Ethernet
interface
TCP/IP Suite
XNS Suite
Ethernet
interface
Demultiplexing
Ethernet cable 2
Ethernet cable 1
D.Zinchin [zinchin@gmail.com]
1-17
Routing
Router is intelligent gateway, making a decision, what route (path) the packet should take.
Remote packet
is sent to Router
Application
Local packet
is sent to Recipient
TCP
TCP
hop 1
IP
Data Link
Host 1
Application
LAN1
IP
(router)
Data Link
hop 2
LAN2
IP
(router)
Data Link
Gateway 1
hop 3
IP
LAN3
Gateway 2
Data Link
Host 2
In TCP/IP routing is made on IP Layer. Each packet could have its own route.
The TCP/IP Internet uses Distributed Dynamic Routing.
D.Zinchin [zinchin@gmail.com]
1-18
MTU=128 b
MTU=2 Kb
Packet
1 Kb
LAN 1
IP (router)
fragmentation
Data Link
128
b
128
b
128
b
...
MTU=2 Kb
128
b
128
b
128
b
WAN connection
Gateway 1
IP (router)
reassembling
Data Link
Packet
1 Kb
LAN 2
Gateway 2
D.Zinchin [zinchin@gmail.com]
1-19
Client-Server Model
Service
requests
provides
is
described
by
Client
uses
Server
uses
Protocol
D.Zinchin [zinchin@gmail.com]
1-20
hop-by-hop
Connection-Oriented Service
end-to-end
The dedicated circuit is called virtual, because it could be provided even on network with packet-switched data
transmission.
A connection-oriented service is often used when more than one message is to be exchanged between the two
peer entities.
D.Zinchin [zinchin@gmail.com]
1-21
Byte Stream
Does not provide record boundaries.
Full-duplex - connection allows data to be transferred in both directions in the same time.
Half-duplex - connection allows data to be transferred in both direction,
but only one side to transfer at a time
Simplex
Reliability
Service is Reliable if it provides Sequencing and Error Control.
Most of reliable services provide also Flow Control.
Sequencing
Means that the data is received by the receiver in the same order as it is transmitted by the sender.
In a packet-switched network, it is possible for two consecutive packets to take different routes, and thus
arrive at their destination in a different order from the order in which they were sent.
Error Control
Guarantees that error-free data is received at the destination.
There are two conditions that can generate errors:
- the data gets corrupted (modified during transmission),
- the data gets lost.
The network implementation has to provide for recovery from both these situations.
1-22
Application
Protocol
Data
Multiplexing/
Encapsulation
Routing
Transmission
Demultiplexing
application
protocols
(applicationdepended)
TCP
hide
Application
layer data
Transport
UDP
Packet
hide
-switched
Transport
(hop-by-hop) layer data
Network
IP
Data Link
frame
Ethernet/
hide Network
transmission
Token Ring
layer data
in LAN
D.Zinchin [zinchin@gmail.com]
combine/split
of data from
different
Transport
(south)
protocols
combine/split
of data from
different
Application
(north)
processes
(applicationdepended)
brake up
(/recompose)
stream into
(from) IP
packets
full-duplex
connection- (bioriented
directional)
byte stream
reliable
(sequencing,
error control,
flow control)
connection- datagram
less
delivery
unreliable
combine/split of
brake up
data from
distributed (/recompose)
connection- packet
different
dynamic
packet into
less
delivery
Transport
routing
(/from)
(north) and Data
transition units
Link (south)
protocols
unreliable
combine/split
of data from
different
Network (north)
protocols
1-23
Communication Services
Provided by TCP/IP Protocol Suite
Network Layer
IP Internet Protocol
Provides unreliable connectionless packet delivery service, containing:
Routing,
Fragmentation / Reassembling,
Multiplexing / Demultiplexing.
Works with different Data Link protocols and topologies, hiding the
technological differences between the networks.
Transport Layer
UDP User Datagram Protocol
Provides unreliable connectionless datagram delivery service.
TCP Transmission Control Protocol
Provides reliable connection-oriented full-duplex byte stream service
over unreliable connectionless packet-switched IP Network.
D.Zinchin [zinchin@gmail.com]
1-24
Host Interface
Transceiver
Coaxial cable (ether)
Host Interface
It provides physical address associated with interface
hardware and filters incoming packets
Bus Topology
The main characteristic of this topology is that it is a
passive structure: when a node is down, the
network is not affected.
Ring Topology
This kind of topology is less efficient and reliable
but it is quite cheap. As soon as two lines are cut
the network no longer works.
Star Topology
This topology is quite efficient and cheap. Most
small local networks is built on this model by using
a central Hub that connects computers together.
A hub can imitate different network topology
configurations.
D.Zinchin [zinchin@gmail.com]
1-25
A to B
A to C
Local frames
are filtered out
Repeater
Bridge
D.Zinchin [zinchin@gmail.com]
Buss
Imitation
Ring
Imitation
Hub
Hub
O
O
O
O
1-26
Technology description:
Each host interface has preset unique 48 bit physical address.
Transceiver senses when ether is in use and detects collisions.
When data is transmitted, all hosts connected to the bus can hear
the transmission.
In case of collision both hosts wait for a random amount of time, before
sending the information again.
P
Bytes: 8
DA
6
Ethernet Frame
Collision
SA
6
L/T
2
Data
46-1500
CRC
4
DA
Destination Address
SA
Source Address
L/T
D.Zinchin [zinchin@gmail.com]
1-27
Begin
Frame Sending
1. Prepare Frame
2. Trial Counter = 0
CSMA/CD
Carrier Sense Multiple
Access with Collision
Detection
Wait
Random Delay Time
Is other node
transmitting ?
NO
Calculate
Random Delay Time
IPG
Inter-Packet Gap
JAM
32 bit frame for collision
signaling
NO
YES
Is IPG interval
Passed ?
Is Trial Counter
Greater then 16 ?
Recovery
After Collision
YES
Delay
Wait until
IPG is passed
Waiting
Is Collision
detected ?
NO
YES
D.Zinchin [zinchin@gmail.com]
NO
NO
Is Last bit
sent ?
Is other node
transmission
finished ?
YES
YES
Trial Counter ++
YES
NO
Transmission
Frame is Sent
Successfully
1-28
Multiple
Access
Unit
Technology description:
This is not continuous wire, consists of connections among host
interfaces, connecting to Ring by means of Multiple Access Units
(MAU). (No more than 8 hosts per MAU).
Physical address is configurable by means of switches.
Control frame named Token is passed from one host to another,
allowing to this host (and only this) to send the packet.
To send the frame, host performs the following steps:
waits for the arriving Token
In Token Ring collisions never
converts it to data frame and copies to the next host in the Ring occur.
waits for the frame to return after delivery
This ensures good performance
deletes the frame and sends out a new Token
of network under big loads (30% Each moment of time no more than 1 host sends the data,
40%)
all other hosts copy the data by chain.
Host interface could be in following modes:
transmit mode sending host
copying mode all other hosts in ring
recovery mode recovery in case of token loss
When copying host recognizes its destination address, it cleans refuse bit.
Sender, accepting the original frame, detects if frame was delivered, checking the refuse bit.
Fist connected to Ring host accepts the status of Active Monitor. It responsible for:
Token creation and recovery
Check frame delivery timeout
Deletion of frames not deleted by other hosts.
Notification of other hosts about its presence in Ring (sends Active Monitor Present frame)
In case of Active Monitor problem, other hosts compete to accept its status.
D.Zinchin [zinchin@gmail.com]
1-29
SD
AC
FC
DA
SA
Bytes: 1
Data
CRC
0..4096
ED
FS
SD
AC
ED
SD
- Start Delimiter
AC
FC
- Frame Control
DA
- Destination Address
SA
- Source Address
- End Delimiter - contains 1 bit Last Packet bit, Error flag bit
FS
D.Zinchin [zinchin@gmail.com]
1-30
Application
application
application
Transport
TCP/UDP
TCP/UDP
Network
IP
address
IP
(host)
Data Link
Physical
address
Ethernet
hop 1
hop 2
IP
(router)
Ether Token
net Ring
Ether Ether
net
net
LAN
D.Zinchin [zinchin@gmail.com]
IP
(router)
LAN
IP
(host)
hop 3
TokenRing
LAN
1-31
Version IP Version
Header length IP Header total length in 32bit words (max = 15*4=60 bytes)
DSCP, ECN type of service fields, used by upper protocols
Total Length total packet length (header + data).
Identification, DF (don't fragment),
MF (more fragments), Fragment Offset used for fragmentation and reassembly.
TTL - time-to-live maximal number of hops, set by the sender, decremented by each router.
Protocol - upper layer protocol (1=ICMP, 2=IGMP, 6=TCP, 17=UDP).
Header Checksum - calculated over just the IP header including any options.
Source IP address (32 bit)
Destination IP address (32-bit)
Options (<=40 bytes) , used by upper protocols
D.Zinchin [zinchin@gmail.com]
1-32
Class A
Bits:
Class B
Bits:
Class C
24
Network ID
1
14
1 0
1
Host ID
16
Network ID
1
21
1 1 0
1
Class D
1 1 0
Bits:
Class E
1 1 1 0
Class
0.0.0.0
Host ID
28
Multicast address
1
27
Range
Network ID
Bits:
Host ID
2^7 2 = 126
2^24 2 = 16,777,214
128.0.0.0 to 191.255.255.255
2^14 2 = 16,382
2^16 2 = 65,534
192.0.0.0 to 223.255.255.255
2^21 2 = 2,097,150
2^8 2 = 254
224.0.0.0 to 239.255.255.255
N/A
N/A
240.0.0.0 to 247.255.255.255
N/A
N/A
D.Zinchin [zinchin@gmail.com]
to 127.255.255.255
*Note:
The 2 types of bit
sequences:
All Bits equal 1
All Bits equal 0
are not used as
Network IDs and
Host IDs
1-33
Netmask
Gateways, to locate the network, need only Network ID part of IP Address and dont need to know the location
of every host. This is important concept of routing.
To calculate Network ID from IP Address, Gateways use Netmask.
Example.
Class
Network ID
Netmask
1 byte
255.
0.
0.
2 bytes
255. 255.
0.
3 bytes
class B
1 0
0x
0 1 0 0 0 1 0 0 0 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 1 0 0 1 1
IP Address
Host ID
145.
11.
99.
3
243
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x
Netmask
of Class B
255.
255.
0.
1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x
Network ID
1
145.
D.Zinchin [zinchin@gmail.com]
B
11.
0
0.
0
0
1-34
Example.
Subnetting of Network with Class B address, using 8 bit Subnet ID.
Bits:
1 1
Class B
1 0
Network mask:
14
Network ID
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
255.
Bits:
1 1
Class B
1 0
Subnet mask:
16
255.
14
Network ID
1 1 1 1 1 1 1 1
255.
Host ID
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0.
Subnet ID
Host ID
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
255.
255.
=0xFFFF0000
=0xFFFFFF00
In the example above local gateway needs only 8 bits of Subnet ID for routing. Adding new host to existing
sub-network will not require any changes to the internal gateways.
D.Zinchin [zinchin@gmail.com]
1-35
multicast
group
Broadcasting and
Multicasting needs support by
hardware (Data Link layer).
1-36
Unspecified Address
The address consisting of 32 zero bits is Unspecified Address.
It is only permitted to appear as the source address in packets sent by a node that is bootstrapping before
the node learns its IP address.
(This address is known as INADDR_ANY).
Private Addresses
Three address ranges are set aside for Private Internets.
These are the networks that do not connect directly to the public Internet.
Small sites use these private addresses and Network Address Translation (NAT) to a single public IP address
visible to the Internet.
NAT - Network Address Translation
Also known as Network Masquerading or
Number of
IP-masquerading is a technique in which
Class Range
addresses
the source and/or destination addresses
of IP packets are rewritten as they pass
A
10.0.0.0
to 10.255.255.255
16,777,216
through a router or firewall.
B
172.16.0.0 to 172.31.255.255
1,048,576
C
192.168.0.0 to 192.168.255.255
D.Zinchin [zinchin@gmail.com]
65,536
1-37
Multihomed Network
This is a network that has multiple connections to the Internet.
For example, some sites have two connections to the Internet instead of one, providing a backup capability.
ifconfig
UNIX/LINUX utility for
configuring network
interface parameters
D.Zinchin [zinchin@gmail.com]
$ ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:11:25:0C:DE:88
inet addr:145.9.228.95 Bcast:145.9.228.255 Mask:255.255.255.0
inet6 addr: fe80::211:25ff:fe0c:de88/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2295264 errors:0 dropped:0 overruns:0 frame:0
TX packets:783513 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:319104166 (304.3 MiB) TX bytes:75720636 (72.2 MiB)
Base address:0x2000 Memory:e8100000-e8120000
lo
1-38
nslookup
UNIX utility for
DNS information
access
$nslookup gate88.mot.com
Server: abcde.mot.com
Address: 145.19.17.68
Name: gate88.mot.com
Address: 145.19.238.87
D.Zinchin [zinchin@gmail.com]
1-39
Address Resolution
Address Resolution is translation between Network Layer logical address and Data Link physical address.
Host A
IP Address
(logical)
Ethernet Address
(physical)
Host B
IPA
Network
IP
IP packet
Network
IP
IPB
PHA
Data Link
Ethernet
Ethernet
frame
Data Link
Ethernet
PHB
physical connection
Address Resolution Problem
I want to send IP packet to another host with known IP Address. What is Physical Address of that host?
Known: IPA, PHA, IPB.
Unknown: PHB
D.Zinchin [zinchin@gmail.com]
1-40
ARP
ARP Address Resolution Protocol
ARP Request
ARP Reply
Proxy ARP
Lets to Router to answer ARP requests,
addressed to another physical network,
substituting routers physical address instead of
target foreign host address.
arp
UNIX utility for
ARP Cache
access
$arp a
sun (140.252.13.33) at 8:0:20:3:f6:42
svr4 (140.252.13.34) at 0:0:c0:c2:9b:26
1-41
RARP Protocols
RARP Reverse Address Resolution Protocol
RARP Request
( [ ? , PHA ] )
RARP
Server
( [ IPA , PHA ] )
RARP Reply
RARP
Server
1-42
ICMP
ICMP - Internet Control Message Protocol .
ICMP handles Error and Control information messages
between routers and hosts.
These messages are normally generated by and
processed by the TCP/IP networking software.
ICMP Message
IP Header
Description
Query
Error
destination unreachable
10
11
12
13
14
17
16
D.Zinchin [zinchin@gmail.com]
1-43
IP Routing
IP Routing is distributed. Each hop of the specific packet is calculated separately.
Remote packet
is sent to
Router
application
Local packet
is sent to
Recipient
application
TCP/UDP
TCP/UDP
IP
(host)
IP
(router)
hop 1
hop 2
LAN
hop 3
IP
Token
Ether net
Ring
Ether
Ether net
net
Ethernet
IP
(router)
LAN
(host)
TokenRing
LAN
traceroute
hop1
hop3
G
hop2
D.Zinchin [zinchin@gmail.com]
1-44
UNIX Utilities:
route
- Utility for manual manipulation with Routing Table
netstat - Utility, showing network status
interface
Host
Gateway
Destination
# netstat -nr
Routing Table: IPv4
Destination
Gateway
Interface
127.0.0.1
UH
298
default
175.16.12.1
UG
50360
175.16.12.0
175.16.12.2
40
111379
175.16.2.0
175.16.12.3
UG
1179
175.16.1.0
175.16.12.3
UG
10
1113
175.16.3.0
175.16.12.3
UG
1379
175.10.4.3
175.16.12.5
UGH
1119
D.Zinchin [zinchin@gmail.com]
lo0
bge0
1-45
IP Routing Algorithm
Single IP Routing algorithm for Host an Router
Most multi-user systems today (almost every Unix system),
can be configured to act as a Router. This means, that Host
and Router could have the same routing algorithm.
Note: Unlike Router, the Host never forwards packets
from one of its interfaces to another.
no
Extract Network ID
Is Local Network ?
no
yes
Is Subnet Mask Specified ?
no
yes
Extract Sub-Network ID
Is Sub-Network ID Found ?
yes
no
Is Network ID Found ?
yes
no
no
no
yes
Get Interface
Discard IP Packet.
Send ICMP Error.
Send IP Packet
D.Zinchin [zinchin@gmail.com]
1-46
D.Zinchin [zinchin@gmail.com]
1-47
IP Routing Schema
IP Input
Routing
Daemon
Updates from
adjacent
Routers
route
netstat
command
command
IP Output
Routing Table write
Manual
updates
by Sysadmin
ICMP
Redirect
UDP
TCP
ICMP
IGMP
Deliver Message
yes
yes
Routing
Table
Is IP Forwarding
Enabled ?
no
IP output: Calculate Next Hop
(to Destination Host or Hop Router)
Is Hop
Calculated ?
yes
Send IP Packet.
IP Layer
no
Is this My Packet ?
(Destined to my IP Address
or Broadcast Address)
no
yes
Process IP options.
Is this Source Routing
(prescribed by sender) ?
no
Discard IP Packet.
Send ICMP Error.
Receive IP Packet.
Put it to IP Input Queue
1-48
File /etc/services
on most Unix systems
the well-known port
numbers are contained
in this file.
D.Zinchin [zinchin@gmail.com]
application
Application
Transport
Port
number
TCP/UDP
Network
IP
address
IP
Data Link
Physical
address
Ethernet/
TokenRing
Port 2
Port 3
Transport Protocol
(UDP/TCP)
IP
1-49
Process B
application
application
UDP
Foreign IP Address
Foreign Port
IP
Transport Address (or Socket)
is half-Association:
Transport Protocol (UDP / TCP)
Local IP Address
Port
A
IP Addr
A
data link
Port
B
UDP
IP Addr
B
IP
data link
Local Port
D.Zinchin [zinchin@gmail.com]
1-50
- the length of the UDP header and the UDP data in bytes.
(it is redundant, because could be calculated from IP header)
UDP checksum
- covers the UDP Pseudo-Header (see below) and the UDP data.
To let UDP double-check that the data has arrived at the correct destination, the UDP checksum is calculated on
UDP Pseudo-Header, containing:
UDP header itself
IP Header fields: Source IP Address, Destination IP Address, Protocol type.
DATA field may be empty
D.Zinchin [zinchin@gmail.com]
1-51
SYN
SYN
m
CK
n, A
1
ACK m+
+1
data m
+1
CK m+2
data n, A
ACK
n+1
ACK n+
1
active
side
passive
side
D.Zinchin [zinchin@gmail.com]
ACK n
FIN n
ACK n+
1
1-52
Source and Destination port numbers - identify the sending process and the receiving process.
Sequence Number unique identifier of TCP Segment, equal to the sequence number of segment 1 st data byte in
stream between TCP sender and TCP receiver. Byte numeration begins from ISN (initial sequence number)
chosen by TCP sender. Wraps back around to 0 after reaching 2^32 - 1.
Acknowledgement Number used with ACK flag. The number of next byte, which TCP receiver is ready to receive.
Header Length - the length of the header in 32-bit words.
Flags: URG urgent data (used with Urgent Pointer),
PSH - flush receiver data from its cache to process, RST reset the connection (port unreachable reply)
SYN connect (used with Sequence Number = ISN), FIN finalize the connection
Window Size number of bytes, which receiver is ready to accept (flow control)
TCP Checksum - covers TCP Pseudo-Header (TCP Header + IP Addresses and Protocol fields) + TCP Data
Urgent Pointer used with URG flag. Offset from Sequence Number to last byte of urgent data.
Options (<=40 bytes). Maximal Segment Size (MSS) announcement, Timestamp, Window scale, etc.
D.Zinchin [zinchin@gmail.com]
1-53
TCP Receiver
Receive Window
TCP Segments
ACKed,
accepted
by application
ACKed,
NOT accepted
by application
Sliding
direction
Send Buffer
Send Window
TCP Sender
TCP Segments
Sent,
ACKed
Sent,
NOT ACKed
10
Can Sent
immediately
11
Receive Window consists of any space in Receive Buffer that is not occupied by data.
Data remains in Receive buffer until target application will accept it.
The size of Receive Window is advertised by TCP Receiver to TCP Sender.
Send Buffer
- begins from first un-acknowledged segment. Has the size of advertised Receive Window Size.
Send Window
D.Zinchin [zinchin@gmail.com]
1-54
recv:
send:
TIME_WAIT State
The endpoint that initiates termination of
connection, goes through TIME_WAIT
state and remains there for the period:
2 * MSL (maximum segment lifetime)
MSL is configurable life time of IP packet
in the network. The actual duration of
2MSL varies from 30 sec up to 4 min.
The TIME_WAIT state has two reasons:
1.Reliable termination of TCP connection
(ability to reply ACK for resent FIN)
2.To allow old duplicate segments to
expire in the network
(1MSL for original duplicate segments
+ 1 MSL for replies
to be lost from network)
1-55
D.Zinchin [zinchin@gmail.com]
1-56
D.Zinchin [zinchin@gmail.com]
1-57
TCP/IP Summary
IPv4
Internet Protocol version 4.
IPv4 Applications
IPv6
Internet Protocol version 6.
tcpdump
TCP
mrouted
ping
traceroute
appl.
appl.
IPv6 Applications
appl.
appl.
appl.
appl.
traceroute
ping
API
UDP
User Datagram Protocol.
TCP
SCTP
Stream Control Transmission Protocol.
SCTP
UDP
ICMP
ICMP
Internet Control Message Protocol
(version 4).
IPv4
IGMP
128-bit
address
32-bit
address
IPv6
ICMP
v6
v6
ARP
RARP
IGMP
Internet Group Management Protocol.
ARP
BPF
DLPI
datalink
1-58