@@ -90,7 +90,14 @@ struct PendingQuery {
9090 delay : Duration ,
9191
9292 server_idx : usize ,
93- mdns : bool ,
93+ mdns : MulticastDns ,
94+ }
95+
96+ #[ derive( Debug ) ]
97+ pub enum MulticastDns {
98+ Disabled ,
99+ #[ cfg( feature = "socket-mdns" ) ]
100+ Enabled ,
94101}
95102
96103#[ derive( Debug ) ]
@@ -211,10 +218,11 @@ impl<'a> Socket<'a> {
211218
212219 let mut raw_name: Vec < u8 , MAX_NAME_LEN > = Vec :: new ( ) ;
213220
214- let mut mdns = false ;
221+ let mut mdns = MulticastDns :: Disabled ;
222+ #[ cfg( feature = "socket-mdns" ) ]
215223 if name. split ( |& c| c == b'.' ) . last ( ) . unwrap ( ) == b"local" {
216224 net_trace ! ( "Starting a mDNS query" ) ;
217- mdns = true ;
225+ mdns = MulticastDns :: Enabled ;
218226 }
219227
220228 for s in name. split ( |& c| c == b'.' ) {
@@ -253,7 +261,7 @@ impl<'a> Socket<'a> {
253261 cx : & mut Context ,
254262 raw_name : & [ u8 ] ,
255263 query_type : Type ,
256- mdns : bool ,
264+ mdns : MulticastDns ,
257265 ) -> Result < QueryHandle , StartQueryError > {
258266 let handle = self . find_free_query ( ) . ok_or ( StartQueryError :: NoFreeSlot ) ?;
259267
@@ -506,16 +514,17 @@ impl<'a> Socket<'a> {
506514 // As per RFC 6762 any DNS query ending in .local. MUST be sent as mdns
507515 // so we internally overwrite the servers for any of those queries
508516 // in this function.
509- let servers = if pq. mdns {
510- & [
517+ let servers = match pq. mdns {
518+ #[ cfg( feature = "socket-mdns" ) ]
519+ MulticastDns :: Enabled => & [
511520 #[ cfg( feature = "proto-ipv6" ) ]
512521 MDNS_IPV6_ADDR ,
513522 #[ cfg( feature = "proto-ipv4" ) ]
514523 MDNS_IPV4_ADDR ,
515- ]
516- } else {
517- self . servers . as_slice ( )
524+ ] ,
525+ MulticastDns :: Disabled => self . servers . as_slice ( ) ,
518526 } ;
527+
519528 let timeout = if let Some ( timeout) = pq. timeout_at {
520529 timeout
521530 } else {
@@ -567,7 +576,11 @@ impl<'a> Socket<'a> {
567576 let payload = & mut payload[ ..repr. buffer_len ( ) ] ;
568577 repr. emit ( & mut Packet :: new_unchecked ( payload) ) ;
569578
570- let dst_port = if pq. mdns { MDNS_DNS_PORT } else { DNS_PORT } ;
579+ let dst_port = match pq. mdns {
580+ #[ cfg( feature = "socket-mdns" ) ]
581+ MulticastDns :: Enabled => MDNS_DNS_PORT ,
582+ MulticastDns :: Disabled => DNS_PORT ,
583+ } ;
571584
572585 let udp_repr = UdpRepr {
573586 src_port : pq. port ,
0 commit comments