@@ -2173,6 +2173,11 @@ fn broadcast_dns_on_intf(out: &DnsOutgoing, intf: &IntfSock) -> Vec<u8> {
2173
2173
2174
2174
/// Sends an outgoing broadcast packet, and returns the packet bytes.
2175
2175
fn broadcast_on_intf < ' a > ( packet : & ' a [ u8 ] , intf : & IntfSock ) -> & ' a [ u8 ] {
2176
+ if packet. len ( ) > MAX_MSG_ABSOLUTE {
2177
+ error ! ( "Drop over-sized packet ({})" , packet. len( ) ) ;
2178
+ return & [ ] ;
2179
+ }
2180
+
2176
2181
let sock: SocketAddr = match intf. intf . addr {
2177
2182
if_addrs:: IfAddr :: V4 ( _) => SocketAddrV4 :: new ( GROUP_ADDR_V4 , MDNS_PORT ) . into ( ) ,
2178
2183
if_addrs:: IfAddr :: V6 ( _) => {
@@ -2182,21 +2187,17 @@ fn broadcast_on_intf<'a>(packet: &'a [u8], intf: &IntfSock) -> &'a [u8] {
2182
2187
}
2183
2188
} ;
2184
2189
2185
- if packet. len ( ) > MAX_MSG_ABSOLUTE {
2186
- error ! ( "Drop over-sized packet ({})" , packet. len( ) ) ;
2187
- return & [ ] ;
2188
- }
2189
-
2190
- send_packet ( packet, & SockAddr :: from ( sock) , intf) ;
2190
+ send_packet ( packet, sock, intf) ;
2191
2191
packet
2192
2192
}
2193
2193
2194
2194
/// Sends out `packet` to `addr` on the socket in `intf_sock`.
2195
- fn send_packet ( packet : & [ u8 ] , addr : & SockAddr , intf_sock : & IntfSock ) {
2196
- match intf_sock. sock . send_to ( packet, addr) {
2195
+ fn send_packet ( packet : & [ u8 ] , addr : SocketAddr , intf_sock : & IntfSock ) {
2196
+ let sockaddr = SockAddr :: from ( addr) ;
2197
+ match intf_sock. sock . send_to ( packet, & sockaddr) {
2197
2198
Ok ( sz) => debug ! ( "sent out {} bytes on interface {:?}" , sz, & intf_sock. intf) ,
2198
2199
Err ( e) => error ! (
2199
- "send to {:? } via interface {:?} failed : {}" ,
2200
+ "Failed to send to {} via {:?}: {}" ,
2200
2201
addr, & intf_sock. intf, e
2201
2202
) ,
2202
2203
}
@@ -2213,12 +2214,19 @@ fn valid_instance_name(name: &str) -> bool {
2213
2214
mod tests {
2214
2215
use super :: {
2215
2216
broadcast_dns_on_intf, my_ip_interfaces, new_socket_bind, valid_instance_name, IntfSock ,
2216
- ServiceDaemon , ServiceEvent , ServiceInfo ,
2217
+ ServiceDaemon , ServiceEvent , ServiceInfo , GROUP_ADDR_V4 , MDNS_PORT ,
2217
2218
} ;
2218
2219
use crate :: dns_parser:: {
2219
2220
DnsOutgoing , DnsPointer , CLASS_IN , FLAGS_AA , FLAGS_QR_RESPONSE , TYPE_PTR ,
2220
2221
} ;
2221
- use std:: time:: Duration ;
2222
+ use std:: { net:: SocketAddr , net:: SocketAddrV4 , time:: Duration } ;
2223
+
2224
+ #[ test]
2225
+ fn test_socketaddr_print ( ) {
2226
+ let addr: SocketAddr = SocketAddrV4 :: new ( GROUP_ADDR_V4 , MDNS_PORT ) . into ( ) ;
2227
+ let print = format ! ( "{}" , addr) ;
2228
+ assert_eq ! ( print, "224.0.0.251:5353" ) ;
2229
+ }
2222
2230
2223
2231
#[ test]
2224
2232
fn test_instance_name ( ) {
0 commit comments