Protocol Independence -Computers And Network Programming-Lecture Slides, Slides of Network Programming

This lecture was delivered by Dr. Ram Sai at Jaypee University of Engineering and Technology for Computers and Network Programming course. It includes: Network, Programming, Protocol, Socket, Addresses, Independence, Wrapper, Socket, User, Datagram, Tcp, Ip

Typology: Slides

2011/2012

Uploaded on 07/23/2012

gannesh
gannesh 🇮🇳

4.4

(12)

75 documents

1 / 32

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
NetworkProgramming
(Lecture5)
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download Protocol Independence -Computers And Network Programming-Lecture Slides and more Slides Network Programming in PDF only on Docsity!

Network

Programming

(Lecture

Protocol

Independence

The

program

was

dependent

on

IPv4.

We

allocate

and

initialize

a

sockaddr_in

structure. 

Set

the

family

of

this

structure

to

AF_INET

and

specify

the

first

argument

to

socket

as

AF_INET.

struct sockaddr_in6.

socket(AF_INET6,…..)

servaddr.sin6_family=AF_INET6.

servaddr.sin6_port=htons(13).

if(inet_pton(AF_INET6,argv[1],&sin6_addr)<=0)

Wrapper

functions

Essential

to

check

for

functions

for

error

return.

Check

for

errors

from

socket,

inet_pton,

connect

,^

read

and

fputs.

When

error

occur

we

call

functions

err_quit

and

err_sys. 

We

can

shorten

our

programs

using

wrapper

functions.

Wrapper

functions

Whenever

you

encounter

a^

function

name

in

the

text

that

begins

with

an

uppercase

letter,

that

is

one

of

our

wrapper

functions.

It^

calls

a^

function

whose

name

is

the

same

but

begins

with

the

lowercase

letter.

When

describing

the

source

code

that

is

presented

in

the

text,

we

always

refer

to

the

lowest

level

function

being

called

(e.g.,

socket),

not

the

wrapper

function

(e.g.,

Socket).

intSocket(int family, int type, int protocol){ int n;if ( (n = socket(family, type, protocol)) < 0)err_sys("socket error");return (n);}

UDP

User

Datagram

Protocol

-^

Provides

a^ connectionless

service

-^

Application

writes

a^ message

to

a^ UDP

socket,

which

is^

then

-^

Encapsulated

in^

a^ UDP

datagram

-^

Further

encapsulated

as^

an^

IP^ datagram

-^

Then

sent

to^

its^

destination

-^

There

is^

no

guarantee

that

-^

A^ UDP

datagram

will

ever

reach

its

final

destination

-^

Order

will

be

preserved

across

the

network

-^

A^ UDP

socket

can

send

a^ datagram

to

a^ given

server

and

then

immediately

send

next

datagram

to

another

from

the

same

socket

-^

A^ UDP

server

can

receive

five

datagrams

in^

a^ row

on

a^ single

UDP

socket,

each

from

five

different

clients

-^

UDP

lacks

reliability

,^ sequence

numbers,

RTT

estimation,

timeouts,

or

retransmissions

UDP

Header

Source

Port

Destination

Port

Length

Checksum

Bit^

0

16

31

TCP

Header

TCP

Connection

Establishment

Three

‐Way

Handshake

-^

Server

must

be

prepared

to

accept

connection

(passive

open)^ –

socket,

bind,

listen

-^

Client

calls

connect

(active

open)

–^

A^ SYN

segment

is^

sent

telling

the

server

the

initial

sequence

number

of

client

–^

Normally,

there

is^

no

data

sent

with

the

SYN;

it^

just

contains

an

IP

header,

a^ TCP

header,

and

possible

TCP

options

-^

Server

must

ACK

the

client’s

SYN

and

also

send

its

own

SYN

to

the

client

–^

Server

sends

its

SYN and

the

ACK of

the

client’s

SYN in

a^

single

statement

-^

Client

must

ACK

the

server’s

SYN

TCP

Options

•^

MSS

option

-^

With

this

option

the

TCP

sending

the

SYN

announces

its

maximum

segment

size

,^ the

maximum

amount

of

data

that

it^

is^

willing

to

accept

in

each

TCP

segment,

on

this

connection

-^

Can

be

set

with

TCP_MAXSEG

socket

option

•^

Timestamp

option

-^

Needed

to

avoid

possible

data

corruption

caused

by

old,

delayed,

or

duplicated

segments

TCP

Options

-^

Window

Scale

option

–^

Maximum

window

size

that

either

TCP

can

advertise

is

(because

of

bit

field

in

TCP

header)

–^

Larger

window

size

is^

required

to

obtain

the

maximum

throughput

in

high

speed

networks

or

in

long

delay

path

(satellite

links)

–^

Window

scale

option

specifies

that

advertise

window

in

the

TCP

header

must

be

scaled

(left

shifted)

by

bits,

providing

a^

maximum

window

of

almost

one

gigabyte

x^10

–^

Both

end

systems

must

support

this

option

for

the

window

scale

to

be

used

on

a^ connection

–^

SO_RCVBUF

socket

option

is^

used

to

effect

this

option

TCP

Connection

Termination

client

server

close

close (active close) connect

returns

(passive close)^ read

returns

0

FIN

M ack

N+ 1 ack

+M (^1)

Figure 2.

Packets exchanged when a TCP connection is closed.

FIN

N

TCP

Connection

Termination

•^

FIN

in

step

one

can

be

sent

with

data

•^

Normally

four

segments

are

required

for

closing

the

connection,

but

sometimes

it^

can

be

lesser

•^

Segments

in

step

and

are

both

from

the

end

performing

the

passive

close

and

could

be

combined

into

one

segment

•^

A^ FIN

occupies

byte

of

sequence

number

space

just

like

SYN,

therefore,

the

ACK

of

each

FIN

is^

the

sequence

number

of

the

FIN

plus

one

•^

Between

step

and

it^ is

possible

for

data

to

flow

from

the

end

doing

the

passive

close

to

the

end

doing

the

active

close

-^

This

is^

called

half

‐close

•^

Often

the

client

performs

the

active

close,

but

with

some

protocols

(HTTP),

the

server

performs

the

active

close

TCP

State

Transition^ Diagram

19

These

states

can

be

displayed

by

netstat

TCP

state

transition

Diagram

The

operation

of

TCP

with

regard

to

connection

establishment

and

connection

termination

can

be

specified

with

a^

state

transition

diagram.

There

are

11

different

states

defined

for

a^

connection

and

the

rules

of

TCP

dictate

the

transitions

from

one

state

to

another,

based

on

the

current

state

and

the

segment

received

in

that

state.

For

example,

if

an

application

performs

an

active

open

in

the

CLOSED

state,

TCP

sends

a^

SYN

and

the

new

state

is

SYN_SENT.

If

TCP

next

receives

a^

SYN

with

an

ACK,

it

sends

an

ACK

and

the

new

state

is

ESTABLISHED.

This

final

state

is

where

most

data

transfer

occurs.