11use crate :: IpAddr ;
22use embedded_nal:: AddrType ;
3- use heapless:: String ;
43
54/// This trait is an extension trait for [`TcpStack`] and [`UdpStack`] for dns
65/// resolutions. It does not handle every DNS record type, but is meant as an
@@ -24,13 +23,22 @@ pub trait Dns {
2423 addr_type : AddrType ,
2524 ) -> Result < IpAddr , Self :: Error > ;
2625
27- /// Resolve the hostname of a host, given its ip address
26+ /// Resolve the hostname of a host, given its ip address.
27+ ///
28+ /// The hostname is stored at the beginning of `result`, the length is returned.
29+ ///
30+ /// If the buffer is too small to hold the domain name, an error should be returned.
2831 ///
2932 /// **Note**: A fully qualified domain name (FQDN), has a maximum length of
30- /// 255 bytes [`rfc1035`]
33+ /// 255 bytes according to [`rfc1035`]. Therefore, you can pass a 255-byte long
34+ /// buffer to guarantee it'll always be large enough.
3135 ///
3236 /// [`rfc1035`]: https://tools.ietf.org/html/rfc1035
33- async fn get_host_by_address ( & self , addr : IpAddr ) -> Result < String < 256 > , Self :: Error > ;
37+ async fn get_host_by_address (
38+ & self ,
39+ addr : IpAddr ,
40+ result : & mut [ u8 ] ,
41+ ) -> Result < usize , Self :: Error > ;
3442}
3543
3644impl < T : Dns > Dns for & T {
@@ -44,7 +52,11 @@ impl<T: Dns> Dns for &T {
4452 T :: get_host_by_name ( self , host, addr_type) . await
4553 }
4654
47- async fn get_host_by_address ( & self , addr : IpAddr ) -> Result < String < 256 > , Self :: Error > {
48- T :: get_host_by_address ( self , addr) . await
55+ async fn get_host_by_address (
56+ & self ,
57+ addr : IpAddr ,
58+ result : & mut [ u8 ] ,
59+ ) -> Result < usize , Self :: Error > {
60+ T :: get_host_by_address ( self , addr, result) . await
4961 }
5062}
0 commit comments