VIII Multicasting Options

48
Chaptere19 multicasting

description

Multicasting options in Networking

Transcript of VIII Multicasting Options

Page 1: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 1/48

Chaptere19

multicasting

Page 2: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 2/48

contents• multicast address

• multicasting versus broadcasting on a LAN

• multicasting on a WAN

• multicast socket option

• mcast_join and related function

• dg_cli function using multicasting

• receiving Mone session announcements

• sending and receiving

• !N"#

Page 3: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 3/48

M$L"%CA!"%N&

TCP/IP ProtocolSuite

3

Page 4: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 4/48

'ifference b() multicasting and multiple unicasting

• Multicasting starts )ith one single packet from the source that is duplicated b* the

routers+ "he destination address in each packet is the same for all duplicates

• %n multiple unicasting, several packets start from the source )ith different

destination address+ -or e.ample, )hen a person sends an e/mail message to a

group of people, this is multiple unicasting+ "he e/mail soft)are creates replicas of

the message, each )ith a different destination address, and sends them one b* one+

TCP/IP ProtocolSuite

4

Page 5: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 5/48

Applications of Multicasting

• "eleconferencing

• 'istance Learning

• 'issemination of Ne)s

• Access to distributed database

TCP/IP ProtocolSuite

5

Page 6: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 6/48

Multicast Address• A multicast address is a destination address for a group of hosts

that have 0oined a multicast group+

• A packet that uses a multicast address as a destination can reach

all members of the group unless there are some filtering

restriction b* the receiver+• Multicast Address used in IPV4: %n classful addressing,

multicast addresses occupied the onl* single block in class '+ %n

classless addressing the same block has been used for this

 purpose+

• %n other )ords, the block assigned for multicasting is 2+3+3+3(2+

"his means that the block has 45 6 75,28,27 addresses

:2+3+3+3 to 89,++;+

TCP/IP ProtocolSuite

6

Page 7: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 7/48

'eliver* of Multicast #ackets at 'ata Link La*er 

• ecause the %# packet has a multicast %# address, the A<# protocol cannot

find the corresponding MAC :ph*sical; address to for)ard the packet at

the data link la*er+

• What happens ne.t depends on )hether or not the underl*ing data link

la*er supports ph*sical multicast addresses+

• Most LANs support ph*sical multicast addressing+ =thernet is one of them+

• An =thernet ph*sical address :MAC address; is si. octets :25 bits; long+ %fthe first bits in an =thernet address are 33333331 33333333 31311113

3, this identifies a ph*sical multicast address for the "C#(%# protocol+

• "he remaining 8 bits can be used to define a group+

• "o convert an %# multicast address into an =thernet address, the multicast

router e.tracts the least significant 8 bits of a multicast %# address andinserts them into a multicast =thernet ph*sical address

TCP/IP ProtocolSuite

7

Page 8: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 8/48

TCP/IP ProtocolSuite

8

Figure 10.10   Mapping class D to Ethernet

 physical address

Page 9: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 9/48

TCP/IP ProtocolSuite

9

 An Ethernet multicast physical address

is in the range01:00:5E:00:00:00

to

01:00:5E:7F:FF:FF.

 Note> Note>

Page 10: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 10/48

TCP/IP ProtocolSuite

10

Change the multicast IP address 20.!.1!.7 to an Ethernet

multicast physical 

Example 2

"olution

#e can do this in t$o steps:a. #e $rite the rightmost 2 %its o& the IP address in he'adecimal. (his

can %e done %y changing the rightmost %ytes to he'adecimal and then

 su%tracting ) &rom the le&tmost digit i& it is greater than or e*ual to ). In

our e'ample+ the result is 2,:0E:07.

%. #e add the result o& part a to the starting Ethernet multicast address+

$hich is -01:00:5E:00:00:00. (he result is

31>33>=>>3=>3?

Page 11: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 11/48

TCP/IP ProtocolSuite

11

Change the multicast IP address 2).212.2!./ to an Ethernet

multicast address.

Example 3

"olution

a. (he rightmost three %ytes in he'adecimal are !:1):0/. #e need to

 su%tract ) &rom the le&tmost digit+ resulting in 5!:1):0/..

%. #e add the result o& part a to the Ethernet multicast starting address.

(he result is

01:00:5E:54:18:09

Page 12: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 12/48

• $nicast @ a single interface

•  broadcast

 @ multiple interfaces

 @ LAN• multicast

 @ a set of interfaces

 @ LAN or WAN

 @ Mbone @ five socket opetions

Page 13: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 13/48

multicast address• %#v2 class ' address

 @  2+3+3+3 89+++

 @  :2+3+3+1> all hosts group;, :2+3+3+> all/routers group;

Page 14: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 14/48

multicast address:;

• %#v7 multicast address

• special %#v7 multicast address :flags;

 @  ff3>>1 6B all/nodes group:all multicast/capable hosts on subnetmust 0oin this group on all multicast/capable interfaces;

 @  ff3>> 6B all/routers group:all multicast/capable routers on subnet

must 0oin this group on all multicast/capable interfaces;

Page 15: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 15/48

!cope of multicast addresses

• %#v7 multicast address have an e.plicit 4-bit scoe !ield

that seci!ies "o# !ar t"e $ulticast ac%et #ill tra&el+

 @   Node/local :1; @  link/local :;

 @  site/local :;

 @  organiation/local :5;

 @  global :12;

• remaining values are unassigned or reserved

Page 16: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 16/48

• DErganiation must set its boundar* routers not to for)ard

multicast packets outside net)ork 

Page 17: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 17/48

multicasting versus broadcasting on a

LAN• Ene host sends a multicast packet and an* interested host

receives the packet+

• enefit

 @  reducing the load on all the hosts not interested in the multicast

 packets

Page 18: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 18/48

Page 19: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 19/48

multicasting on a WAN

Page 20: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 20/48

A host sends the audio packets and the multicast receivers are

)aiting to receive

M<#> Multicast <outing #rotocol

Page 21: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 21/48

Page 22: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 22/48

multicast socket option

• "he A#% support for multicasting reFuires onl* five ne)

socket options+

• -igure 19+?

Page 23: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 23/48

multicast socket option:;

• %#_A''_M=M=<!G%#, %#H7_A''_M=M=<!G%#

 @  0oin a multicast group on s specified local

interface+

!truct ip_mreFI

struct in_addr imr_multiaddrJ

struct in_addr imr_interfaceJKJ

!truct ipv7_mreFI

struct in7_addr ipv7mr_multiaddrJ

struct int ipv7mr_interfaceJKJ

Page 24: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 24/48

multicast socket option:8;

• %#_'<E#_M=M=<!G%#, %#H7_'<E#_M=M=<!G%#

 @ leave a multicast group on a specified local

interface+ @ %f the local interface is not specified, the first

matching multicasting group membership is

dropped+

Page 25: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 25/48

multicast socket option:2;

• %#_M$L"%CA!"_%-, %#H7_M$L"%CA!"_%-

 @ specif* the interface for outgoing multicast

datagrams sent on this socket+ @ "his interface is specified as either an inaddr  

structure for %#v2 or an interface inde. for

%#v7+

Page 26: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 26/48

multicast socket option:;

• %#_M$L"%CA!"_""L, %#H7_M$L"%CA!"_""L

 @ set the %#v2 ""L or the %#v7 hop limit for

outgoing multicast datagrams+ @ %f this is not specified , both default to 1, )hich

restricts the datagram to the local subnet+

Page 27: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 27/48

multicast socket option:7;

• %#_M$L"%CA!"_LEE#, %#H7_M$L"%CA!"_LEE#

 @ enable or disable local loopback of multicast

datagrams+ @ 'efault loopback is enabled+

 @ "his is similar to broadcasting+

Page 28: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 28/48

mcast_join and related function

include unp+hint mcast_0oin:int sockfd, const struct sockaddr Daddr, socklen_t salen, const char

Difname, u_int ifinde.;J

int mcast_leave:int sockfd, const struct sockaddr Daddr, socklen_t salen;J

int mcast_set_if:int sockfd, const char Difname, u_int ifinde.;J

int mcast_set_loop:int sockfd, int flag;Jint mcast_set_ttl:int sockfd, int ttl;J

  All above return >3 if ok, /1 on error 

int mcast_get_if:int sockfd;J

return > nonnegative interface inde. if EO, /1 error 

int mcast_get_loop:int sockfd;Jreturn > current loopback flag if EO, /1 error 

int mcast_get_ttl:int sockfd;J

return > current ""L or hop limit if EO, /1 error 

Page 29: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 29/48

include Punp+hPinclude Qnet(if+hBint mcast_0oin:int sockfd, const !A Dsa, socklen_t salen, const char Difname, u_int ifinde.;I

s)itch :sa/Bsa_famil*; I

case A-_%N="> Istruct ip_mreF mreFJstruct ifreF ifreFJ

memcp*:RmreF+imr_multiaddr, R::struct sockaddr_in D; sa;/Bsin_addr,  sieof:struct in_addr;;J

if :ifinde. B 3; Iif :if_inde.toname:ifinde., ifreF+ifr_name; 66 N$LL; I

errno 6 =NS%EJ (D i(f inde. not found D(return:/1;JKgoto doioctlJK else if :ifname T6 N$LL; Istrncp*:ifreF+ifr_name, ifname, %-NAM!%U;J

doioctl>if :ioctl:sockfd, !%EC&%-A''<, RifreF; Q 3;return:/1;J

memcp*:RmreF+imr_interface,  R::struct sockaddr_in D; RifreF+ifr_addr;/Bsin_addr,  sieof:struct in_addr;;JK elsemreF+imr_interface+s_addr 6 htonl:%NA''<_ANV;J

return:setsockopt:sockfd, %##<E"E_%#, %#_A''_M=M=<!G%#, RmreF, sieof:mreF;;;JK

Page 30: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 30/48

ifdef %#H7

case A-_%N="7> I

struct ipv7_mreF mreF7J

memcp*:RmreF7+ipv7mr_multiaddr, R::struct sockaddr_in7 D; sa;/Bsin7_addr,

  sieof:struct in7_addr;;J

if :ifinde. B 3;

mreF7+ipv7mr_interface 6 ifinde.J

else if :ifname T6 N$LL;

if : :mreF7+ipv7mr_interface 6 if_nametoinde.:ifname;; 66 3; I

errno 6 =NS%EJ (D i(f name not found D(

return:/1;J

K

else

mreF7+ipv7mr_interface 6 3J

return:setsockopt:sockfd, %##<E"E_%#H7, %#H7_A''_M=M=<!G%#,

  RmreF7, sieof:mreF7;;;J

K

endif 

default>

errno 6 =#<E"ENE!$##E<"J

return:/1;J

K

K

Page 31: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 31/48

include Punp+hPint mcast_set_loop:int sockfd, int onoff;I

s)itch :sockfd_to_famil*:sockfd;; Icase A-_%N="> Iu_char flagJflag 6 onoffJreturn:setsockopt:sockfd, %##<E"E_%#, %#_M$L"%CA!"_LEE#,  Rflag, sieof:flag;;;JK

ifdef %#H7case A-_%N="7> Iu_int flagJflag 6 onoffJreturn:setsockopt:sockfd, %##<E"E_%#H7, %#H7_M$L"%CA!"_LEE#, Rflag,sieof:flag;;;JK

endif 

default>errno 6 =#<E"ENE!$##E<"Jreturn:/1;JK

K

Page 32: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 32/48

dg_cli function using multicasting

< i i M i t

Page 33: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 33/48

<eceiving Mone session announcements

• "o receive a multimedia conference on the Mone a

site needs to kno) onl* the multicast address of the

conference and the $'# ports for the conferences

data streams+:audio, video;

• !A#:!ession Announce #rotocol; @ describe the )a*

• !'#:!ession 'escription #rotocol;

 @ the contents of these announcements

Page 34: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 34/48

• A site )ishing to announce a session on the Mbone

 @   periodicall* sends a multicast packet containing a description of the session

to a )ell/kno)n multicast group and $'# port

• !ites on Mbone

 @  run sdr program

• receives these announcements

•  provides an interactive user interface that displa*s the information

• lets user send announcements

• A sample program

 @  onl* receives these session announcements to sho) an e.ample of a simple

multicast receiving program

Page 35: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 35/48

include Punp+hPdefine !A#_NAM= Psap+mcast+netP (D default group name and port D(

define !A#_#E<" P95?Pvoid loop:int, socklen_t;Jint main:int argc, char DDargv;I

int sockfdJconst int on 6 1Jsocklen_t salenJ

struct sockaddr DsaJ

if :argc 66 1;sockfd 6 $dp_client:!A#_NAM=, !A#_#E<", :void DD; Rsa, Rsalen;Jelse if :argc 66 2;sockfd 6 $dp_client:argvX1Y, argvXY, :void DD; Rsa, Rsalen;J

else err_Fuit:Pusage> m*sdr Qmcast/addrB QportB Qinterface/nameBP;J

!etsockopt:sockfd, !EL_!ECO=", !E_<=$!=A''<, Ron, sieof:on;;Jind:sockfd, sa, salen;JMcast_0oin:sockfd, sa, salen, :argc 66 2; Z argvX8Y > N$LL, 3;Jloop:sockfd, salen;J (D receive and print D(e.it:3;J

K

"he program receiving the periodic !A#(!'# announcements

Page 36: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 36/48

include Punp+hP

void loop:int sockfd, socklen_t salen;

I char bufXMASL%N=[1YJ

socklen_t lenJ

ssie_t nJstruct sockaddr DsaJ

struct sap_packet I

  uint8_t sap_headerJ

  uint8_t sap_srcJ

  char sap_dataX1YJ

K DsapptrJ

sa 6 Malloc:salen;J

for : J J ; I

len 6 salenJ

n 6 <ecvfrom:sockfd, buf, MASL%N=, 3, sa, Rlen;J

 bufXnY 6 3J (D null terminate D(

sapptr 6 :struct sap_packet D; bufJif : :n /6 D sieof:uint8_t;; Q6 3;

err_Fuit:Pn 6 \dP, n;J

 printf:P-rom \s]n\s]nP, !ock_ntop:sa, len;, sapptr/Bsap_data;J

K

K

Page 37: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 37/48

sending and receiving

• !ends and receives multicast datagrams• -irst part

 @ sends a multicast datagram to a specific group

ever* seconds and the datagram contains thesenders hostname and process %'

• !econd part

 @ an infinite loop that 0oins the multicast group to)hich the first part is sending and prints ever*

received datagrams

Page 38: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 38/48

include Punp+hPvoid recv_all:int, socklen_t;Jvoid send_all:int, !A D, socklen_t;J

int main:int argc, char DDargv;I

int sendfd, recvfdJconst int on 6 1Jsocklen_t salenJstruct sockaddr Dsasend, DsarecvJ

if :argc T6 8; err_Fuit:Pusage> sendrecv Q%#/multicast/addressB QportBP;J

sendfd 6 $dp_client:argvX1Y, argvXY, :void DD; Rsasend, Rsalen;Jrecvfd 6 !ocket:sasend/Bsa_famil*, !ECO_'&<AM, 3;J!etsockopt:recvfd, !EL_!ECO=", !E_<=$!=A''<, Ron, sieof:on;;Jsarecv 6 Malloc:salen;Jmemcp*:sarecv, sasend, salen;Jind:recvfd, sarecv, salen;J

Mcast_0oin:recvfd, sasend, salen, N$LL, 3;J

Mcast_set_loop:sendfd, 3;J

if :-ork:; 66 3;recv_all:recvfd, salen;J (D child /B receives D(

send_all:sendfd, sasend, salen;J (D parent /B sends D(K

Page 39: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 39/48

include Punp+hP

include Qs*s(utsname+hB

define !=N'<A"= (D send one datagram ever* seconds D(

void

send_all:int sendfd, !A Dsadest, socklen_t salen;

I

static char lineXMASL%N=YJ (D hostname and process %' D(

struct utsname m*nameJ

if :uname:Rm*name; Q 3;

err_s*s:Puname errorP;JJ

snprintf:line, sieof:line;, P\s, \d]nP, m*name+nodename, getpid:;;J

for : J J ; I

!endto:sendfd, line, strlen:line;, 3, sadest, salen;J

sleep:!=N'<A"=;J

K

K

Page 40: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 40/48

include Punp+hP

void

recv_all:int recvfd, socklen_t salen;

I

int nJ

char lineXMASL%N=[1YJ

socklen_t lenJ

struct sockaddr DsafromJ

safrom 6 Malloc:salen;J

for : J J ; I

len 6 salenJ

n 6 <ecvfrom:recvfd, line, MASL%N=, 3, safrom, Rlen;J

lineXnY 6 3J (D null terminate D(

 printf:Pfrom \s> \sP, !ock_ntop:safrom, len;, line;J

K

K

Page 41: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 41/48

!N"#

•  N"# 6B so sophisticated protocol

• !N"# 6B simplified version of N"#

 @ hosts do not need the comple.it* of a complete N"#

implementation+

 @ A client listening for N"# broadcast or multicasts onall attached net)orks and then prints the time

difference bet)een the N"# packet and the hosts

current time/of/da*

Page 42: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 42/48

define ^AN_19?3 35955533$L (D 19?3 / 1933 in seconds D(struct l'!i(edt ) *+ ,4-bit !i(ed-oint +*  uint8_t int_partJ  uint8_t fractionJ KJstruct s'!i(edt ) *+ -bit !i(ed-oint +*  u_short int_partJ  u_short fractionJ KJstruct ntdata ) *+ /P "eader +*  u_char statusJ  u_char stratumJ  u_char ppollJ  intprecision>5J  struct s_fi.edpt distanceJ

  struct s_fi.edpt dispersionJ  uint8_t refidJ  struct l_fi.edpt reftimeJ  struct l_fi.edpt orgJ  struct l_fi.edpt recJ  struct l_fi.edpt .mtJ KJ

define H=<!%EN_MA!O 3.85define ME'=_MA!O 3.3?

define ME'=_CL%=N" 8define ME'=_!=<H=< 2define ME'=_<EA'CA!"

Page 43: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 43/48

include Psntp+hP

int main:int argc, char DDargv;

I

int sockfdJchar bufXMASL%N=YJ

ssie_t nJ

socklen_t salen, lenJ

struct ifi_info DifiJ

struct sockaddr Dmcastsa, D)ild, DfromJ

struct timeval no)J

if :argc T6 ; err_Fuit:Pusage> ssntp Q%#addressBP;J

sockfd 6 $dp_client:argvX1Y, PntpP, :void DD; Rmcastsa, Rsalen;J

)ild 6 Malloc:salen;J

memcp*:)ild, mcastsa, salen;J (D cop* famil* and port D(

sock_set_)ild:)ild, salen;J

ind:sockfd, )ild, salen;J(D bind )ildcard D(

Page 44: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 44/48

ifdef MCA!"

(D 2obtain interface list and process each one D(

for :ifi 6 &et_ifi_info:mcastsa/Bsa_famil*, 1;J ifi T6 N$LLJ ifi 6 ifi/Bifi_ne.t; I

if :ifi/Bifi_flags R %--_M$L"%CA!";

Mcast_0oin:sockfd, mcastsa, salen, ifi/Bifi_name, 3;J

 printf:P0oined \s on \s]nP,

  !ock_ntop:mcastsa, salen;, ifi/Bifi_name;JK

endif 

from 6 Malloc:salen;J

for : J J ; I

len 6 salenJ

n 6 <ecvfrom:sockfd, buf, sieof:buf;, 3, from, Rlen;J

&ettimeofda*:Rno), N$LL;J

sntp_proc:buf, n, Rno);J

K

K

-igure 19+15 : ( ;

Page 45: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 45/48

include Psntp+h

void sntp_proc:char Dbuf, ssie_t n, struct timeval Dno)ptr;

I

int version, modeJ

uint8_t nsec, useciJ

double usecfJ

struct timeval curr, diffJ

struct ntpdata DntpJ

if :n Q sieof:struct ntpdata;; I

 printf:P]npacket too small> \d b*tes]nP, n;J

returnJ

K

ntp 6 :struct ntpdata D; bufJ

version 6 :ntp/Bstatus R H=<!%EN_MA!O; BB 8J

mode 6 ntp/Bstatus R ME'=_MA!OJ printf:P]nv\d, mode \d, strat \d, P, version, mode, ntp/Bstratum;J

if :mode 66 ME'=_CL%=N"; I

 printf:Pclient]nP;J

returnJ

K

Page 46: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 46/48

nsec 6 ntohl:ntp/B.mt+int_part; / ^AN_19?3J

useci 6 htonl:ntp/B.mt+fraction;J (D 8/bit integer fraction D(

usecf 6 useciJ (D integer fraction /B double D(usecf (6 29297?97+3J (D divide b* DD8 /B X3, 1+3; D(

useci 6 usecf D 1333333+3J (D fraction /B parts per million D(

curr 6 Dno)ptrJ (D make a cop* as )e might modif* it belo) D(

if : :diff+tv_usec 6 curr+tv_usec / useci; Q 3; I

diff+tv_usec [6 1333333J

curr+tv_sec//J

K

diff+tv_sec 6 curr+tv_sec / nsecJ

useci 6 :diff+tv_sec D 1333333; [ diff+tv_usecJ (D diff in microsec D(

 printf:Pclock difference 6 \d usec]nP, useci;J

K

Page 47: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 47/48

!N"#:;Ene socket per unicast address

Ene socket per broadcast addressEne socket per interface on )hich the multicast group is 0oined

Page 48: VIII Multicasting Options

7/17/2019 VIII Multicasting Options

http://slidepdf.com/reader/full/viii-multicasting-options 48/48