2020import java .io .DataInputStream ;
2121import java .io .IOException ;
2222import java .io .OutputStream ;
23- import java .net .InetAddress ;
24- import java .net .ServerSocket ;
25- import java .net .Socket ;
26- import java .net .URLDecoder ;
23+ import java .net .*;
2724import java .security .GeneralSecurityException ;
2825import java .security .MessageDigest ;
2926import java .util .*;
@@ -72,12 +69,25 @@ public class ZeroconfAuthenticator implements Closeable {
7269
7370 int port = session .random .nextInt ((MAX_PORT - MIN_PORT ) + 1 ) + MIN_PORT ;
7471 new Thread (this .runner = new HttpRunner (port )).start ();
75-
76- ServiceInstance service = new ServiceInstance (new ServiceName ("librespot._spotify-connect._tcp.local." ), 0 , 0 , port , Name .fromString ("local." ), InetAddress .getAllByName ("localhost" ), "VERSION=1.0" , "CPath=/" );
72+ ArrayList <InetAddress > addressArrayList = new ArrayList <>();
73+ Enumeration <NetworkInterface > networkInterfaces = NetworkInterface .getNetworkInterfaces ();
74+ while (networkInterfaces .hasMoreElements ()){
75+ NetworkInterface networkInterface = networkInterfaces .nextElement ();
76+ Enumeration <InetAddress > interfaceAddresses = networkInterface .getInetAddresses ();
77+ if (!networkInterface .isLoopback ()) {
78+ while (interfaceAddresses .hasMoreElements ()) {
79+ InetAddress address = interfaceAddresses .nextElement ();
80+ if (!address .isLoopbackAddress ())
81+ addressArrayList .add (address );
82+ }
83+ }
84+ }
85+ InetAddress [] addressArray = addressArrayList .toArray (new InetAddress [addressArrayList .size ()]);
86+ addressArrayList .add (InetAddress .getByName (InetAddress .getLocalHost ().getCanonicalHostName ()));
87+ ServiceInstance service = new ServiceInstance (new ServiceName ("librespot._spotify-connect._tcp.local." ), 0 , 0 , port , Name .fromString ("local." ), addressArray , "VERSION=1.0" , "CPath=/" );
7788 spotifyConnectService = mDnsService .register (service );
7889 if (spotifyConnectService == null )
7990 throw new IOException ("Failed registering SpotifyConnect service!" );
80-
8191 LOGGER .info ("SpotifyConnect service registered successfully!" );
8292 }
8393
@@ -297,4 +307,4 @@ public void close() throws IOException {
297307 serverSocket .close ();
298308 }
299309 }
300- }
310+ }
0 commit comments