@@ -272,7 +272,7 @@ impl LinkManagerMulticastUdp {
272
272
. map_err ( |e| zerror ! ( "{}: {}" , mcast_addr, e) ) ?;
273
273
}
274
274
275
- // Bind the socket: let's bing to the unspecified address so we can join and read
275
+ // Bind the socket: let's bind to the unspecified address so we can join and read
276
276
// from multiple multicast groups.
277
277
let bind_mcast_addr = match mcast_addr. ip ( ) {
278
278
IpAddr :: V4 ( _) => IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) ,
@@ -321,6 +321,31 @@ impl LinkManagerMulticastUdp {
321
321
// https://docs.rs/tokio/latest/tokio/net/struct.UdpSocket.html#notes
322
322
mcast_sock. set_nonblocking ( true ) ?;
323
323
324
+ // If TTL is specified, add set the socket's TTL
325
+ if let Some ( ttl_str) = config. get ( UDP_MULTICAST_TTL ) {
326
+ let ttl = match ttl_str. parse :: < u32 > ( ) {
327
+ Ok ( ttl) => ttl,
328
+ Err ( e) => bail ! ( "Can not parse TTL '{}' to a u32: {}" , ttl_str, e)
329
+ } ;
330
+
331
+ match & local_addr {
332
+ IpAddr :: V4 ( _) => {
333
+ ucast_sock
334
+ . set_multicast_ttl_v4 ( ttl)
335
+ . map_err ( |e| zerror ! ( "{}: {}" , mcast_addr, e) ) ?;
336
+ }
337
+ IpAddr :: V6 ( _) => match zenoh_util:: net:: get_index_of_interface ( local_addr) {
338
+ Ok ( _) => {
339
+ tracing:: warn!( "set_multicast_ttl_v4 on v6 socket (may have no effect): {}" , mcast_addr) ;
340
+ ucast_sock
341
+ . set_multicast_ttl_v4 ( ttl)
342
+ . map_err ( |e| zerror ! ( "{}: {}" , mcast_addr, e) ) ?
343
+ } ,
344
+ Err ( e) => bail ! ( "{}: {}" , mcast_addr, e) ,
345
+ } ,
346
+ }
347
+ }
348
+
324
349
// Build the tokio multicast UdpSocket
325
350
let mcast_sock = UdpSocket :: from_std ( mcast_sock. into ( ) ) ?;
326
351
0 commit comments