1

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.

Rick de Water
  • 2,388
  • 3
  • 19
  • 37
  • Can you add more detail like what is Bonjour (link) because they are a lot of thing call "bonjour", add some code ? – Stargateur Oct 27 '16 at 09:46
  • The [doc](https://developer.apple.com/reference/dnssd/1804733-dnsserviceregister) says that it take the host name. How do you test the connection ? What is your host name ? Have you try 0.0.0.0 (accept all ip carefull with that) ? Have you try to connect with localhost or host name ? – Stargateur Oct 27 '16 at 10:06

0 Answers0