You are on page 1of 75

Workshop on

Network Programming
By
Dr.LOGANATHAN V & Team
Organised By

Premier Embedded Training Institute in India

Network Essentials
What is a Network
Why Network
How Network

Network Essentials
Types of Network
Centralised
Peer to peer ( WorkGroup )
Domain (client-Server based)

Topologies

Media
Coaxial cable
UTP & STP cable
Fibre optic cable

Networking Devices
MODEM

HUB

REPEATER

BRIDGE

NIC
CSU/DSU

ROUTER

SWITCH

Protocols
Routable & Non Routable

Packet Encapsulation
The data is sent down the protocol stack
Each layer adds to the data by prepending headers

22Bytes 20Bytes 20Bytes


64 to 1500 Bytes

4Bytes

TCP/IP Model
Network Interface Layer:The Network Interface Layer contains the protocols that enable
the TCP/IP to communicate with physical network.
TCP/IP System
Network Interface Layer

Physical Network

ETHERNET

IP
Packaging
Addressing
Routing

IP Addressing
Physical Address:-

What is a Physical Address?

IP Addressing

00-43-95-e0-5d-c9

00-43-95-e0-5d-c9

00-43-95-e0-5d-c9

00-43-95-e0-5d-c9

First the system which wants to communicate with another device in


network has to know the printer address. This address is known as IP
address or Physical address or MAC address.

IP Addressing
Ethernet Adapter:Ethernet adapter card uses 48 bit MAC address for communication in a
network.
MAC address
Vendor ID
Product ID

MAC Address
Vendor ID is a unique ID assigned for that particular vendor.
Product ID is a serial number of that product produced by that
vendor.
MAC Address
00-40-95
Vendor ID

e0-5d-c7
Device ID

IP Address and Classes


What is an IP address?
In IPv4 Ip address is 32 bit in length , it is divided into 8 bit octects
and octects are seperated by a period (.)
Ex: 180.124.09.16
An IP address consist of two parts
Net id

Host id

IP Address and Classes


IP Address
Class A
Class B

Class C
Class D
Class E

IP Address and Classes


Class

Purpose

Class A, B, C

Commercial

Class D

Multicasting

Class E

Experimental

IP Address and classes


Class

IP Address

W.X.Y.Z

X.Y.Z

W.X.Y.Z

W.X

Y.Z

W.X.Y.Z

W.X.Y

Network ID

Host ID

IP Address and classes


Class

Domain Configuration

Class A

Large number of Hosts/ Network & fewer number


of Networks.

Class B

Moderate number of Hosts/Network & Networks

Class C

More number of networks but fewer number of


Hosts/Network.

IP Address and classes

IP Address and classes


Class

First Octet Range

Class A

1-126.X.Y.Z

Class B

128-191.X.Y.Z

Class C

192-223.X.Y.Z

IP Address and classes

127.x.y.z

Reserved for Loop back Address

IP Address and classes


Class

No of
Networks

Class A

126

Class B

16,384

65,534

Class C

2,097,152

254

No of Hosts/Network
16,777,214

IP Address and classes


Valid IP Address Range
Class

Beginning
Range

Ending Range

Class A

1.0.0.1

126.255.255.254

Class B

128.0.0.1

191.255.255.254

Class C

192.0.0.1

223.255.255.254

Subnet Mask
What is a Subnet Mask?
Assume a Network with two hosts

Host 1
Host 2
The above hosts use the subnet mask to identify which part of the IP
and which is host ID.
Whereas TCP/IP protocol uses the subnet mask to determine
destination host address is located on local subnet or remote subnet.

Subnet Mask
The IP (Class B)

171.100.250.72
Net ID

The Subnet Mask

Host ID

255.255.0.0

Subnet Mask
Table Showing various subnet mask for various classes
Class

IP

Net ID

Host ID

Subnet Mask

Class A

W.X.Y.Z

X.Y.Z

255.0.0.0

Class B W.X.Y.Z

W.X

Y.Z

255.255.0.0

Class C W.X.Y.Z

W.X.Y

255.255.255.0

Subnet Mask
To find sub-Network address in an IP
Logical AND

IP Address
= sub-Net ID
Subnet Mask

Subnet Mask
IP Address

171.100.250.72

10101011.01100100.11111010.01001000

Subnet Mask 255.255.0.0

11111111.11111111.00000000.00000000

Net ID

171.100.0.0

10101011.01100100.00000000.00000000

Host ID

250.72

00000000.00000000

Subneting
Using few bits of Host id to address subnet

Routing

Routing
Static routing
Dynamic Routing

Routing Protocols : RIP , OSPF

IP Datagram

Vers

16

Len

TOS

24

31

Total Length

Identification
TTL

19

Flags

Protocol

Fragment Offset
Header Checksum

Source Internet Address


Destination Internet Address
Options...

Padding
Data...

Field
Vers
Len
TOS
T. Length
Ident.
Flags
Frag Off

Purpose
IP version number
Length of IP header (4 octet units)
Type of Service
Length of entire datagram (octets)
IP datagram ID (for frag/reassembly)
Dont/More fragments
Fragment Offset

Field
TTL
Protocol

Purpose
Time To Live - Max # of hops
Higher level protocol (1=ICMP,
6=TCP, 17=UDP)
Checksum Checksum for the IP header
Source IA Originators Internet Address
Dest. IA
Final Destination Internet Address
Options
Source route, time stamp, etc.
Data...
Higher level protocol data

ARP/RARP Header

TCP

Transmission Control Protocol (TCP)


One-to-one and connection-oriented reliable protocol
Used in the accurate transmission of large amount of data
Connection-oriented
Stream Data Transfer
Reliable
Flow-Control
Full-Duplex
Slower compared to UDP because of additional error
checking being performed
Suited for critical data transfer applications

UDP
User Datagram Protocol (UDP)
One-to-one or one-to-many,connectionless and unreliable protocol
Used for the transmission of small amount of data
Accuracy is not of prime concern
The overhead of establishing a TCP connection is not warranted

Used in video and audio casting


Multicasting
Broadcasting

Also used for multimedia transmission


Faster compared to TCP
Application Interface to IP - Packet Oriented
Establishes a port, which allows IP to distinguish among processes
running on the same host
Features resemble IP semantics
Connectionless
Unreliable
Checksums (optional)

TCP Segment
10

16

Source Port

19

24

31

Destination Port

Sequence Number
Acknowledgment Number
Len

Reserved

Flags

Window

Checksum

Urgent Pointer

Options...

Padding
Data...

Field
Source Port
Destination Port
Sequence Number
Acknowledgment #
Len
Flags
Window
Checksum
Urgent Pointer
Options

Purpose
Identifies originating application
Identifies destination application
Sequence number of first octet in the segment
Sequence number of the next expected octet (if ACK flag set)
Length of TCP header in 4 octet units
TCP flags: SYN, FIN, RST, PSH, ACK, URG
Number of octets from ACK that sender will accept
Checksum of IP pseudo-header + TCP header + data
Pointer to end of urgent data
Special TCP options such as MSS and Window Scale

UDP datagram
0

16

31

Source Port

Destination Port

Length

Checksum
Application data

Field
Source Port
Destination Port
Length
Checksum

Purpose
16-bit port number identifying originating application
16-bit port number identifying destination application
Length of UDP datagram (UDP header + data)
Checksum of IP pseudo header, UDP header, and data

APPLICATION LAYER PROTOCOLS

TELNET
FTP
HTTP
DHCP
DNS
SMTP
SNMP
LPD

TCP/IP COMMANDS

PING
FTP
ARP
IPCONFIG
NSLOOKUP
ROUTE
TRACERT

Berkley Sockets

Sockets

Sockets

Client-Server Communication

Socket Procedures

Client Server Communication

Socket()

Close()

Bind()

Listen()

Connect()

Accept()

Send() & recv() for stream socket

Sendto() & recvfrom() for datagram Socket

THANK YOU

TCP Header
Source
portport
address
Source
address

Destination port address

Sequence Number
Acknowledgement Number
H Len

reserved
Checksum

CONTROL

Window Size

Urgent pointer

Options and Padding

IP Header
Version IHL

TOS

Identification
TTL

Protocol

Total Length
Flags

Fragment Offset

Header Checksum

Source IP Address
Destination IP Address
Options and Padding

You might also like