@@ -90,7 +90,14 @@ struct PendingQuery {
90
90
delay : Duration ,
91
91
92
92
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 ,
94
101
}
95
102
96
103
#[ derive( Debug ) ]
@@ -211,10 +218,11 @@ impl<'a> Socket<'a> {
211
218
212
219
let mut raw_name: Vec < u8 , MAX_NAME_LEN > = Vec :: new ( ) ;
213
220
214
- let mut mdns = false ;
221
+ let mut mdns = MulticastDns :: Disabled ;
222
+ #[ cfg( feature = "socket-mdns" ) ]
215
223
if name. split ( |& c| c == b'.' ) . last ( ) . unwrap ( ) == b"local" {
216
224
net_trace ! ( "Starting a mDNS query" ) ;
217
- mdns = true ;
225
+ mdns = MulticastDns :: Enabled ;
218
226
}
219
227
220
228
for s in name. split ( |& c| c == b'.' ) {
@@ -253,7 +261,7 @@ impl<'a> Socket<'a> {
253
261
cx : & mut Context ,
254
262
raw_name : & [ u8 ] ,
255
263
query_type : Type ,
256
- mdns : bool ,
264
+ mdns : MulticastDns ,
257
265
) -> Result < QueryHandle , StartQueryError > {
258
266
let handle = self . find_free_query ( ) . ok_or ( StartQueryError :: NoFreeSlot ) ?;
259
267
@@ -506,16 +514,17 @@ impl<'a> Socket<'a> {
506
514
// As per RFC 6762 any DNS query ending in .local. MUST be sent as mdns
507
515
// so we internally overwrite the servers for any of those queries
508
516
// in this function.
509
- let servers = if pq. mdns {
510
- & [
517
+ let servers = match pq. mdns {
518
+ #[ cfg( feature = "socket-mdns" ) ]
519
+ MulticastDns :: Enabled => & [
511
520
#[ cfg( feature = "proto-ipv6" ) ]
512
521
MDNS_IPV6_ADDR ,
513
522
#[ cfg( feature = "proto-ipv4" ) ]
514
523
MDNS_IPV4_ADDR ,
515
- ]
516
- } else {
517
- self . servers . as_slice ( )
524
+ ] ,
525
+ MulticastDns :: Disabled => self . servers . as_slice ( ) ,
518
526
} ;
527
+
519
528
let timeout = if let Some ( timeout) = pq. timeout_at {
520
529
timeout
521
530
} else {
@@ -567,7 +576,11 @@ impl<'a> Socket<'a> {
567
576
let payload = & mut payload[ ..repr. buffer_len ( ) ] ;
568
577
repr. emit ( & mut Packet :: new_unchecked ( payload) ) ;
569
578
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
+ } ;
571
584
572
585
let udp_repr = UdpRepr {
573
586
src_port : pq. port ,
0 commit comments