zeroconf is a cross-platform library that wraps underlying ZeroConf/mDNS implementations such as Bonjour or Avahi, providing an easy and idiomatic way to both register and browse services.
I have some problems with the service discovery using version 0.6.2 on macOS. It can be reproduced by running the browser example on macOS. I changed the search term to _googlecast._tcp (because I have one) and got the following result.
The resulting IP and Port are just wrong, and the IP even change from execution to execution. The correct and expected values are address: "192.168.178.51", port: 8009.
Environment
macOSBig Sur 11.1
rustcrustc 1.49.0 (e1884a8e3 2020-12-29)
toolchainstable-x86_64-apple-darwin
Solution in the PR
I debuged the code and found out that for the u32, which represents the IP, and the u16, which represent the Port, the endianess is messed up. The IP seem to use host byte order which is the reason why inet_ntoa is returning the wrong result. The Port is also just using the wrong byte order and a simple conversion to big endian is doing the trick.
As this solution is working for me I'm still not sure why this is happening. It seems like the bonjour implementation isn't compatible with libc and also the conversion from the u16 port value into rust isn't working. I also wasn't able to find something about it somewhere in the internet what gives this solution a bit of uncertainty.
Problem
I have some problems with the service discovery using version
0.6.2
on macOS. It can be reproduced by running the browser example on macOS. I changed the search term to_googlecast._tcp
(because I have one) and got the following result.The resulting IP and Port are just wrong, and the IP even change from execution to execution. The correct and expected values are
address: "192.168.178.51", port: 8009
.Environment
Solution in the PR
I debuged the code and found out that for the u32, which represents the IP, and the u16, which represent the Port, the endianess is messed up. The IP seem to use host byte order which is the reason why
inet_ntoa
is returning the wrong result. The Port is also just using the wrong byte order and a simple conversion to big endian is doing the trick.As this solution is working for me I'm still not sure why this is happening. It seems like the bonjour implementation isn't compatible with libc and also the conversion from the u16 port value into rust isn't working. I also wasn't able to find something about it somewhere in the internet what gives this solution a bit of uncertainty.