I have a TCP socket bound to 127.0.0.1
, and I want to make it available as a service on the local machine. The problem however is that Bonjour uses the DHCP address instead of localhost, even with kDNSServiceInterfaceIndexLocalOnly
set as the interface. This prevents me from actually connecting to the socket.
So how do I make it so that the service resolves to 127.0.0.1
rather than 192.168.xxx.xxx
?
I am using the latest bonjour SDK for windows in C++, although it should work the same on all operating systems.
Currently I am only using the following function call to register the service:
DNSServiceRef ref = m_Impl->m_ConnectionRef.get();
DNSServiceRegister(&ref, kDNSServiceFlagsShareConnection, // Handles and flags
kDNSServiceInterfaceIndexLocalOnly, a_Name.c_str(), a_Service.GetServiceType().c_str(), nullptr, // Service name and type
nullptr, HostToBigEndian(a_Service.GetPort()), // Host address
static_cast<uint16>(a_Service.GetTXTRecord().GetRecord().length()), a_Service.GetTXTRecord().GetRecord().c_str(), // TXT record
&MDNSServiceManagerImpl::StaticDNSServiceRegisterReply, service.get()); // Callback
I tried passing "127.0.0.1"
as the host name instead of nullptr
, but as the API comments say, you will then have to manually add the records, and this is where I get lost.