Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
, UIILI
ELEMENTARY TCP SOCIGT
SYLLABUS!
. Dupttoflon.onrmt
l6.What ls me.nt by s.gm.nt?
At the *ndhg and recetvlng end of the rransmtsston/ lcp dtvtds
long transmt$tons intosmatterdatE u;its and packages each into6 frame
clled a sesme.t.
lT,What is meantby s.gment flon?
When the srze ofthe data lntt re@ived from the upper tayer is too
long forthe netwo.k tayerdatagram ordata thk tayerfme to handte,
thetEnsport protocotdivides tr tnto smalerusabte btocks. The dividirg
pbce$ ts cfled segmentation,
la,wh.t a. heant by con.atE.adon?
The size of the data unit belongtng to stnqte *sstons are so smalr
that sevEl.an flt togerhr tnto a singte daragram or t6me, the t.ansport
proto@l combines them tnto a stngle data untt, The ombi.ing pMes is
called concatehation.
lg.What ar th. rypei of hlttiptextng?
The types of multiplexing arer
t upward muttiptex,ng
. Oownward nutiplexlng
2o.What are the two possible tr.n.porr serul.es?
Two basE ryp.sofnanspod seruices are,
o Coniection serui.e
o connectionle$ seNies
,l.lhe tran.port layr .EatB tfie conn..don b.tween .our.e .nd
destination. Wh.t .rc tft. thlB .v.nts lnvoked in tne @nnetior?
For senty, the thcDort lays may @.te a @nnectbn betwen
tfie two enil ports.
A @nnection is a slnqle logl6l path b.twen the eu@ and
destination that Is eseiated with all packets in . mesge. creting a
connectlon involve the <teps:
.connedlon establishment
.Data tcnsfer &Connectlon release.
22. Wh.t l. h6nt hy @rgestlon?
conqestio.ln a networkoccuB ifu*.sendsd.ta intd rhe
network ata rate greter than thatallowea by network rasou@'
23. Wh.t l. the purDos6 of Dom.ln ame Sy.tem?
Domaln Name System en h.p a host name to n IP .ddre$ and
lonveEely an IP addE$ro host name.
,4. Dl*u.. th. thr.. m.ln dMrion of th dom.ln..m..Da6.
Ddaln name space ls dlvlded into thre dl ferent ectrons:
senencdom9lE, country dom.hs & lnveEe domaln,
. G.n.ri. domrln: Define reglstered hosts adodlng to thelr genric
behavior, uses gene c sumxs.
! Courtry domalnr Uss two characteE to identify a @untry as the last
suffix.
.Irv.E. domaln: Fhds thedomain naheqiven the IP addre$,
25. What ll th p.Irclpl. dltteEnc6 b6twen .onn.ctionl.s
@mdunL.tlon and onnection orl.rted.ommurl.ation?
Network ls a (onnection onentd. Here user uses the @nnst;n
and then relea* the .onnectlon. Typl@lly one slde mak6 a propal
otherside @n aceDt lt. LcrleleDhone systems.
In cohnecnonls each mGsage crls the tull destinauon addB
and each one ls Euted thbugh the system independnt of all oties, The
fi6tonesend wlll bethe flEtone toairive. Eg:Postal system.
26. State fw adv:.tage. of IPvs over IPv4.
r t ilrsadd'B spae
. Beilr h..d.. f6mar
. Xd optioc
. A!l@n@ for dtension.
. Support for r6our.e allocation.
. Support for more securily.
27, Explain about connedton terhinarion.
Fouractionsare needed tc close the.onnections tn both d rections:
. Host A sends a segment anrou.ci.g its wlsh for .onnection
establlshhent.
r Hosr s sends a segmenr acJ<nowtedging the reqlest ofA, After this
the .onnection rs closed ii one dire.rion bLt not n ih. oth.r
dlrecton,
. when Host B has finished sendins its own data, it sends a segment
to indtere thar twantsto ctose the connecuon.
i Host A acknowtedses the requesr of B.
24. wh.t .6 th. TcP op.r.Uo..?
r Encap.ulationandDe,capsutation
r Budedag
. l,4ultiplexrngandDe-multtpJexlng
. PushinS DEra
. ursent Data
29. Wh.a l. .ph6m.ral Portnqmbr?
A cltent pEqram running on th to@t @mputer deftnG ttsetf wtd1 a
port number, choen Endomly by the TcP eftwa running on the toct hosr,
Tils is @lled EphemeEl port number.
30. wh.t i. so.ket .ddress?
The cohbination ofan Ip addrcss and a porr number ts clted
socket Addres.
31. What .rc .lement needed for conmonicauons?
. tocat host
! Loet client proSEm
programs?
Sone common APIS that slpports ro wrire ctient-seryer proqGms arc
,, Socker tnierf..e
t Transporr ayer Inter'ae
:1 stream Interfac
+ Thread rnreridce
+ Remote PEedureGtt
34, Spe.ify the Internet add,l$ .t uctlrc?
An IPV4 addBs is dehned as a sttu.tu.e G ed i. addr,
which ontains onty one fietd cled s addr if rype in addr r. The
stru.ture holdsan rP addrB as a 32 bitbinary number,
stru.t t._.ddr
t
in_.ddr_t s_.ddt
L-
..ize_t recvfrom(lnt .ockfdr .onst votd :but, .tze_t bfftenr int flag3,
struct.ock.ddre6s.rrcmaddr, so.tde._t *r.on.ddrten).
socKd is rhe s@ker dscnptor, buf ls the potnter to the
butrer wher the mesge wJtt be stored, buflen defines rhe tength of rhe
butrer, and tn flaqs fields specifies out of band data or lodkahead
m6*ges. Nonally it rs *tto zero. Fromaddr ls rhe pointer to the socket
addre$ of tne *nder, and fromaddrten is ihe tenqth of the seker
addB. Thls tunction Etums the ouhber of chaEcteu send tfrhere ts no
emr and 0 othBt*.
46. Exphln rc.d 6ysrch @tt?
A connecnon{riented prcc6 (oD@s using TCP) isues rhe Ead
system cll to @lve datagdms from a Enore po.e$,
sria_t rc..t(lnt .o.krd. 6n.t votd *b!t, sir6_t bufl.n),
sockfd ls the socket descitptor, buf ts rhe potnrer to tie b!trer
wherc the dara wlll be srored and buflen deffnes the te.grh ol the buffei
Thls tunctlon Eturns tie numbcr of bltes ecetved tf su@$fut,O lt end-
or-file @ndltron ls derecr.d,.nd -1tr rhere is a1errcr.
47. Explaln wrire .Ft.m ca[?
A con.ection oriented process (prccess ushg-rcP) tsslesrhewrlte
system callto send daraqramsto a Emote prc.ess,
$iz._t write(tnt .o.kfdr 6nst void *bofi size_r buften);
so.kfd is the socket descriptor/ buf ts the potnrer to the bufrer
where the dafd to be *nt is storedr buflen defln the tengrh of the bufier.
This tunctton returns the number or bytes *nt(wrttten) tf su@s.tut ,and
-1 if there ls an erbr.
44. How . TCPconndio. terhirard?
t3
The do$ tunction ls used by a proe$ to close a $cket and termlnate a
TCPconne.tton.
nt ct os(int .ocktd )
i
@ eq
"*.
{
length of th structurc */
addres famrly : Af_ XXX value
prcto@l speclfi. address */
),
/fr x(
(v oorine wen-rnown pon. (DEc 2orrl2or2)
The well-known port numbeE are the @t numbeE that are
resewed for asslanfrenr by the Iiternet corporaflon 60r Assigned Names
and Nombe6 GeAN) ror use by the appricrion end pohts rhat
ommunicate ushs rhe tnrerner,s rransmission connot protocol (fqe) or
the User DatasGm prctocot (Uqe). porr numbets o to 1024 are reserued
for pnvlleged serures ahd designated a3 welt-known ports. thrs lst of
rell-known po4 numbe4 speL'fre< rhe oo.r used oy the <eaFr p.oce$ cs
its @.tact port.
-6 Ddttr. $d..r.nd .t out tr. typ5.
The @hmunlcatlon stru.lure used for socket programminq is caled
so.ket, It is an end pornr of communi.aflon to which a name .an be
bound, Two processes need a socket at ea.h e.d to communi.ate with
each other. The socketvatuesare Ipaddress and port number,
TYps of So.ket:
The so.ket interfa@ defines three types of sockers, They are
stream socket, the datagram socketand rhe Ewsocket,
> Stre.n socket altows processes to communtcate using Tcp/tp. TCp
uses a palr of so.kets to connecr one appticrion prcqram to another
acoss the ln rernet.
> oatagEm scketallows proces*s to.ommu.i@re using llDp. uDp
uses a pair of daragEm sockets ro snd a messaqe from
.ppliotlon pogrm to another across rh. rnr-'neL.
> Raw ro.tct provtde a@$ ro tcMp or OSPF that direcfly use iie
serutes of Ip,
63. Dl.tlnggi.h betw.en Tcp so.&6tr .nd UDD s6.keb. (MAY 2011)
r unreliable dellv!ry
r h-orde.gua6nted I no ordersuacntees
! no notion oftconnecfloni - app
lndl@tes dest. for e.ch packet
i can send orre@ive
r srrucrure is soc( DGRAM
i PART - B
F
I 'kxetdtn tfi6 TcP lay.ring in details wirh neatsket.h.
FROT
knows how long to weit foran acknowteloemenr. TCp always specjfies rhe
no. of bytes to be*nr bythe peer. This is called advnsed winlow,
.} APPLICAIION IAYER
Appli.ation proto.ols are defined atthe top tEyer, whtch tfrp ement specific
user applieuons and other hlghlevet fundions, since they are at rhe top ofthe
stack, application Drotocots are ihe oniy ones that do not provide seruices ro 3
hiqher layeri thev make us cfserui.es provtded by the tayeE betow,
r FIP-FILE iRAI{SFER PROTOCOL: the TCpVp standard proro@ts tur a
transferring flte s from one machine to another machine.ftD dtffer fmm the
olher applieuons b*aus. ts use to .onnections to tra.sfer a fite: controt
conne.t on data connection,
2, SMTP-SIMPLE MAIL TMIISFER PROTOCOI.: T)]E TCP\IP StANdArd
prcto@l for transferins eledronic messaqe from one machine ro another
nachine. it spe.ify how ro mait systems inteEct and the form of controt
mssages they exchange to tBnsfer mait.
3. SNI'IP, SIMPIE NETWORK MAI{AGEIEI{T pROtOCoL! a protocot use ro
managethe devics such as hosrs, routerand pitnte6,
4. TELTIET-REMOTE LO6IN: rhe.rcp\rp standard proro6t for remote temhal
*ru|@ .TELiIET altows an tnteractive use6 and the ctie.t sysrem to srart a
Iogln s*ton on a remore system. Once a togtn syslem ts estabtished, the
.lte.t p@ces pas6 the u*rs keystrokes to the server pbces,
5. TFIP-TRWIA! Fr(E titANSFER PROTOCOa: it is a simpte f e transfer
potocol it ls not @mpld as fiP. trdoes not have much.ode consums te$
memory, lt.an be used smal machine .there is no securiry provisions. TFTP
is UDP not TCp.
6- DNS -DOMAIN NAME SERVTCET the ontine distributed database system
used to map host names Into IP addEss_
. TRA'{SPORT IAYER
7he trcheon taver (dlso &nown as the Host-to-Host Transport tayer) rs
rsponslble for provdl.q the Apptication tayer wtth sesston and dataqEm
@mhunlcatron servlces, Tie @re pbtocots of th Transport layer are
ta.sntssioh cohtrol Prctocol ltcP) and rhe uset Datasran protocot (UDp).
Either ol thes hvo protocots ere used by the appti.aton layer process, the chotce
depends on th appll6Uon! rEnsmisston re|abjlity requirements.
The mechanlshs used by theTEnspod ayerto determine whetherdata has been
.orectly delivered are:
. AckiowledsementresDonses
,lln.lud.<Ey!/Eocket.h>
int conn.ct(l.t ecldd,.onst 3trsct .eh.ddr .sMdd., sckle.-t
o ddnen-> iJengrh
BII{D FUI{CTION:
' The brnd funct on assigns a tocatprcrocol address to a socket . irternet protocot
addre$ is a comblnation ofeither 32 bit IF4/4.ddress or 123 bits tpv6 addBs atong
with a 16 brts TCP or UDp port number
lnt blnd(int .ockt t, .or.r 3truct s.kaddr *my!ddr, so.tden t .ddrter)i
. ,t returns 0 if OK & -1 on errcr
r so.kfd- sockct d6cnption
r !1y addr -the address ofa sttucture rhat spectfles an ip address.nd port number.
. Addrlen- The size oftne.ddr6r rtruc1ure r. bytes.
EcS!!-Eo!lg
Retum 0 tf sucstul &,1on ermr.
z. It spectRe ttre muinr. nuhber of @nEuon the *emel sh@ld queue ior thls
It @ntahs a. ent y ior each sYN that afilved fom a clrent for whrch the se er
ls awalting @mpletion of the three way handshake.
2. Completd connedlon oueue:
ft@ntains an ent y for eadr cllentwlt1 the Tcp three way handshake has
The accept is @lled by the TcP server to retum lh ndt completed onnectlon
trom the front of the .ompletd conn.tion quue, Accept .at6 a new socket and
Eturn the descrrptor of the nesectet to the.aller. The seruercan transfer dsta on
rhe new sdket afrer finlshlng ihe se er .los rt.
*lnclud. <3y./.ock t,h>
lnt .@pt (l.t sockfd, .lnct soct rldr *.la.ddr, .o.kln-t .ddilen),
+ Non neqative dscriptor it Ok
t Else"l on errcr
sockfd-> ecket des.rlptor
Clraddr> client IP addc*
A seruer is a pro.ess whi.n offe6 services. A setuer w5its for rads and
pEcesse a clients requet aor a se *.
INIERNET
t A $ruer cn handte huttipte .tienrs ar the sme Ume in paraflet, and this rype of
a s.Net ls @lle,J a fuhcurreht setueL
fte
equest cn be of any
@mplerity and duraiion.
Server software olst be
programmed explicity to handte seryeris locked whlle dealinq with a
t include <arpa/inet,h>
int iret aton(@Gr char* strptr, stru.t tn_addr .add rptr);
> Retums 1, if strinq was vaid,
ln_addr_t rneladd(consrchar*skptr),
> Returns 32 bit bi.ary nework by,te ordered rpv4 Addre$,
INADDR NONE ifan eror.
It.onverts 32 bits binary netwo.k byre orderd rPV4 address tnro rr5
corespondingdotteddecimal s$ng&rerurn poinrertodotred d*imal
G.n.6l R.pEed.tion
32-bit binary lPv4 address
10.23.14.6n be represented in
LSA
00001010 00010111 00001110
harclsizeo(shon)1,
) un;
un,s=0*0102; alol : c)'
pnntr C%s", CPU-VENDoLOS); c('::ol
r (sl@(sholt)-=2) -
{ WW\.,,
r (un.40l==1 && un..I1l- =2) c'-')'".
Dnn60brs endran");
el*lr (un.ciol==2 && un.ctll==1)
ulnt16_t hrons(uint16_thostl6bitvatue);
!int32 t htonl(uint32 t ho.t32bttvalue)i
returns value in networ& byle order
ntoh(uint32 t #32bitvarue),
- retoms value in h6t byte o.dr
. +----!-
I r6bir | | 3i bi, I
rffin
7. cralii. .bout $cket, 6nnG.t, bind, listen :nd aeept lun.tion. (DEc 2012)
> E9!!EMqEQXi
The tun.tion is.alled to create a socket to perform client seNer applictlo..
+in.lude<sys/sotket,h>
int socket(lnt famllv. int type,lnt prctocol);
t Retlrns non necative desc.iptor if OK.
> rrE-t9llEcrcAlE
aTcPclientto establish a @nnction wlth
The connect tunctlo. ls used by a TcP
*irclud6<sys/socket.h>
lrt @nnct(int so.tddr@rst struct so.haddr *s.dtddr, socklen-t
*
F
Not a valid socket descriptor
If the firet ar9umentrs notspe.ified.
lfthe socket is alr,aady conn.ted.
ETIi4EDOUT lf ihe mnne.tbn rs notestablished
Ifthe polt number specified is not waiung
#in.tude <.y./sock.r.h>
ht listen (lnr.o.tt4 i,tba.ktos);
t It eturn 0 ifoK, -1on eror.
The ke.nel malntains two q!eu6:
It @ntaiE an envy for ech s.rN th.t arived arofr a client for which rhe
erer rs aMiring @mplerion of tne tnE My handsh.ke.
2. Codolr.d dne.ri6n outu.:
It dEi6 4 6Ey for ech drent wiur dE TcP dle Ey handshake ha
@molt d.
s6*ff- $det deiptd
A..klog- stse of lli@mt,lg mnedion rEqueL
The connected socket is closed ach time wt.le the tisteninq socket
remai.sopen for the life ofthe se&er, This js suppc.ted onty i sneam.
Not a va d socketdescrpio.
If the nrstargument is not specified.
socket rs not a socKET STREAM.
5, Read
IISTEN(
socKET( )
crasE( )
READO
crosEo
> SoGIELEU!.SI!9!!
'I1le tunction is@l,ed to crate a socket to perform client *ryer appll.atlor,
*ln.lu.le<sys/so.ket.h>
int so.ket(int family, int typr intproto.ol),
. Returns non.eqative dscnotor lfoK,
The blnd tun tion l@l pbtocol address to a socket , intem.t pbtocol
6slqE a
addlE ls. Gmbhanon of elther 32 bit Iw4 addEs or 124 bts lPv6 addres.lonq
wrth d 16 blts TcP or UDP port number
I blnd(l $ctdd, 6tr.t st.u.t so.kaddr .my.ddr, .o.UrLt .ddrl.n),
ERRON CODE
NESUIT
4
!*;iia ay, v^ s a,tn".swa,r aPlrr, MEc .Pase32
I.4r. P. saravanor APl'T 14Ec
MTNG AI{D MAIVAGIT4EN T U TT.1
IEE4CeEerEUtggell
The accept iscalled by the TcP sere. to return the nertcompleted connedion
from th front of the omplted connection quele. Aaept crates a new socket ard
retlm the de*rlptor of the new $.ket to the @ller. The seruer can kansfer data on
the neh socker af,er finEhing the rede' rlotss lr,
*includc <.v./.o.kt.h>
t a.ept (irt s.kfd, strct so.k.ddr +.lladdr, socklen-t rddrl.n);
t Non neqative des.rrptor if oK
eloslEuqroli
it is used to d6e the scket and terminate a TCJ connedlon
*h.lude<uni.td.h>
int.los(int so.&efd),
. It return 0 ifOK
. -1on eror.
Else
. tt marks the $cket as closed and return to the
. The socket decriDtor ls no lonqer usable bv ihe
used as an argument to read orwdte.
. But TCP wlll try to send any data that isalreadv queued to be sent to the
'
socKEr(
tus;EN,l l
socKET( )
CoNNECT( )
Blocks unulconnction
WRITE( l
closE( )
CIOSE FUNCTION:
rt is used to close the socket a nd terminate a TcP corn4tion'
+i6.lude<unBtd.h>
intclo.e(ht sockerd);
. tt Ptlrn o if oK
p*
Alter
ln d.Lll th. ...*.t turcdont for .lem'nt'rv TcP lutctloB
wlth
Expt.In '
SCEIIARIO BETWEE fHE CllCI{T AIID SCRVER:
FEt the seNer' is sta.ted tne. sometin later a client is started that
the seler pro(e*
@nnects to a seru.r. fte client sends a reque* ro the seryer
lne client
the rcqu6t and tne *nd back a Eplv to the client' This dntinues until
to th
ct6es irs end of the connedion whlch *nds an end_of file .otifiGtton
then dos its end of the connectron and either tetminates
or
sder. The *Ner
(alt5 lor a ns client@nn4tlon.
socKET(
TISTEN(
SOCKIT( l
CoNNECT( )
wRlTl( )
ct osE{ )
ct osE( )
EIlLEUlgUalr
the bind tunctlon a$rgc a l@l pDtc.l addE5 to a sd*et . intemet pbto@l
add6 ls a @mbinEtion of nner 32 bt tPv4 addls or 123 bats lPv6 addlEs alonq
wlth a 16 b'ts ICP or UOP port numtcr
irt bind(irt $cldd, @n3t 3tr!d *kaddr .my.ddr, *.klen-t .ddrl.n);
o It Eturns 0 if OX & -1on e@r
o socnid- socket decnpnon
o My addr theaddre$ ofa structure that specifies an lp addr6sand port
> I!!-!EII!-c4!!r
It is 6led only byaTcPse erand it prforms twofunctions.
sin.lude <sys/so.kt.h>
ht ll.ten (int .o.kfd, htbacktoq);
, It retlrn 0 tfOK, -1on errcr.
The kernelmainteins two queues:
5, In@mplete 6nndion oueue:
It.ontains an entry for each sYN rhat artved lrom a ctient for which the
sererls awaltinq.ompletlon olthe three way handshake.
6. Completed 6nnedion oueuei
It @ntainsan entry for ea.h ctientwirh the TCp three way handshake has
o El*_1one or
. Sockfd-> so.kel des.dptot value.
. sewaddts pointer to ecket address structure the scket addls
- sttudure must @ntaln the tP addre* and port 'umber of the
ECONNREFI'SED If the port number spedned E not waiunq on tie *wer lor
ENETT'NREACT
when 6e d.din.tlon is unreach6ble ftum $me lntermedl'ie
{
./
/* length of the structle
s_fahlly_t sa_family; /r addB t mily : ,.F xlx value
/* pret@l specrfic addre$ r/
strud $ckaddr in
t
uint8t sln_lenj /r length ofthe structure */
*_fdmily,t siLfamfly; /* AF_aNET */
rn_irorlt sinJ)on; /* 16 blt pori'/
struct in_addr sln_addr; /, 32 btt lpv4 addres in aetwork order */
.hdrsh_zerol3l; /* thusedt/
j',
{
in_addr_t s_addr; /.32 bitlpv4 address tn netwoik byte orde.*/
1,
{
/* rensth or the structuB */
e_fanily t sin6-famlly;
/* TransDort Laver port in Net{oft Byte order
/*Pdonty &flow label in netwo.k btte ordered
strucr in6_addrl.6 addr i /* IPv6 address in network byte order
r/
);
12. Explain .ny tiB. .ddB. .onvcrsloD fun.tion. in det.ll. (riAY 2012)
RererQ. o.04
13. Expl.in in detall th.5o.ket functions lnvolv.d ln a ba.lc lcP .llni sry6r
(irAY2012)
Refer Q. No, r0
15. DEw . TcP .odct ltow dlagr.d .nd qplain thc functloB. (DEC 2O1t)
Rerer Q. o. 10
15. E)9Lb! ttE noflorlng ln .let ll:
(D n n rE *r.l
(fi) cdEllgt$rui (DEC 2011)
Refer Q. flo.3
_
r"po.a gy , uo, s, erth*rr p/rr, ltc Fage 44
Mr. P. sarcvdin APlfi, MK