File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,14 @@ impl Interface {
105105 . start_vif ( ifindex, ifindex as u16 )
106106 . expect ( "TODO: panic message" ) ;
107107
108+ #[ cfg( not( feature = "testing" ) ) ]
109+ instance
110+ . state
111+ . net
112+ . socket_rx
113+ . get_ref ( )
114+ . join_multicast_ifindex_v4_raw ( & network:: ALL_ROUTERS , ifindex)
115+ . map_err ( IoError :: SocketError ) ?;
108116 // Create raw socket.
109117 let socket =
110118 network:: socket_tx ( & self . name ) . map_err ( IoError :: SocketError ) ?;
Original file line number Diff line number Diff line change @@ -413,6 +413,12 @@ pub trait RawSocketExt: SocketExt {
413413
414414 // Tell the kernel to create a vif for this ifindex.
415415 fn start_vif ( & self , ifindex : u32 , vifid : u16 ) -> Result < ( ) > ;
416+
417+ fn join_multicast_ifindex_v4_raw (
418+ & self ,
419+ multiaddr : & Ipv4Addr ,
420+ ifindex : u32 ,
421+ ) -> Result < ( ) > ;
416422}
417423
418424// Extension methods for LinkAddr.
@@ -595,6 +601,30 @@ impl RawSocketExt for Socket {
595601 std:: mem:: size_of_val ( & vif) as libc:: socklen_t ,
596602 )
597603 }
604+
605+ fn join_multicast_ifindex_v4_raw (
606+ & self ,
607+ multiaddr : & Ipv4Addr ,
608+ ifindex : u32 ,
609+ ) -> Result < ( ) > {
610+ let multiaddr: u32 = ( * multiaddr) . into ( ) ;
611+
612+ let optval = ip_mreqn {
613+ imr_multiaddr : libc:: in_addr {
614+ s_addr : multiaddr. to_be ( ) ,
615+ } ,
616+ imr_address : libc:: in_addr { s_addr : 0 } ,
617+ imr_ifindex : ifindex as c_int ,
618+ } ;
619+
620+ setsockopt (
621+ self ,
622+ libc:: IPPROTO_IP ,
623+ libc:: IP_ADD_MEMBERSHIP ,
624+ & optval as * const _ as * const c_void ,
625+ std:: mem:: size_of :: < ip_mreqn > ( ) as libc:: socklen_t ,
626+ )
627+ }
598628}
599629
600630// ===== Mock sockets for unit testing =====
You can’t perform that action at this time.
0 commit comments