0

I need to get ipaddress by hostname for zeroconf devices. Its working perfectly in windows but in linux it gives below error

Here is the Windows code, but it does not work Linux with avahi

ILookup<string, string> domains = await ZeroconfResolver.BrowseDomainsAsync();
var responses = await ZeroconfResolver.ResolveAsync(domains.Select(g => g.Key));

Here is the Linux error.

System.Net.Sockets.SocketException (98): Address already in use
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at Zeroconf.NetworkInterface.NetworkRequestAsync(Byte[] requestBytes, TimeSpan scanTime, Int32 retries, Int32 retryDelayMilliseconds, Action`2 onResponse, NetworkInterface adapter, CancellationToken cancellationToken) in D:\a\1\s\Zeroconf\NetworkInterface.cs:line 107
   at Zeroconf.NetworkInterface.NetworkRequestAsync(Byte[] requestBytes, TimeSpan scanTime, Int32 retries, Int32 retryDelayMilliseconds, Action`2 onResponse, NetworkInterface adapter, CancellationToken cancellationToken) in D:\a\1\s\Zeroconf\NetworkInterface.cs:line 170
   at Zeroconf.NetworkInterface.NetworkRequestAsync(Byte[] requestBytes, TimeSpan scanTime, Int32 retries, Int32 retryDelayMilliseconds, Action`2 onResponse, CancellationToken cancellationToken) in D:\a\1\s\Zeroconf\NetworkInterface.cs:line 34
   at Zeroconf.ZeroconfResolver.ResolveInternal(ZeroconfOptions options, Action`2 callback, CancellationToken cancellationToken) in D:\a\1\s\Zeroconf\ZeroconfResolver.cs:line 87
   at Zeroconf.ZeroconfResolver.BrowseDomainsAsync(BrowseDomainsOptions options, Action`2 callback, CancellationToken cancellationToken) in D:\a\1\s\Zeroconf\ZeroconfResolver.Async.cs:line 164
   at Zeroconf.ZeroconfResolver.BrowseDomainsAsync(TimeSpan scanTime, Int32 retries, Int32 retryDelayMilliseconds, Action`2 callback, CancellationToken cancellationToken) in D:\a\1\s\Zeroconf\ZeroconfResolver.Async.cs:line 136

So I am not understanding how to proceed from here.I have used zeroconf in dotnet core

jww
  • 97,681
  • 90
  • 411
  • 885
Quick
  • 21
  • 4
  • *`Address already in use`* seems significant. You probably should investigate it further. You should also state the Linux distro you are using. – jww Apr 01 '19 at 09:40
  • I am using centos 7. I tried stopping avahi-daemon then i was not getting any error but I donno how to create custom dns with my own name and try to get the ipaddress of it. And I donno whether it will show up the created hostnmae if I stop avahi daemon. And When i searched ,i found that it uses some port and this zeroconf resolver in dotnet core tries to use it to get ipaddress via hostname(port is 5353) and I used this code in linux terminal to know whther port 5353 is busy or not. Code goes here – Quick Apr 01 '19 at 09:57
  • function is_port_free { netstat -ntpl | grep [0-9]:${1:-5353} -q ; if [ $? -eq 1 ] then echo yes else echo no fi } – Quick Apr 01 '19 at 10:01
  • 1
    I believe systemd listens on the socket in case the service is started or available. If the service is not available, then the socket is listening but requests are not serviced. If this is the case, then you have to stop systemd listening socket, too (in addition to the service). See, for example, [Why systemd is listening on port 631?](https://ask.fedoraproject.org/en/question/9468/why-systemd-is-listening-on-port-631/) (Different protocol, same problem). – jww Apr 01 '19 at 10:31
  • The problem is if I stop avahi then I cannot discover DNS as it is provider of dns-sd i guess. I just want to create DNS-SD hostname and I need to get its ipaddress by using the above code which I mentioned in description. If you got this please guide me through this way. – Quick Apr 02 '19 at 06:32

0 Answers0