File tree Expand file tree Collapse file tree
HMCLCore/src/main/java/org/jackhuang/hmcl/launch Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -190,6 +190,33 @@ private Command generateCommandLine(Path nativeFolder) throws IOException {
190190 }
191191 }
192192
193+ try {
194+ boolean hasIPv4 = false ;
195+ java .util .Enumeration <java .net .NetworkInterface > nets = java .net .NetworkInterface .getNetworkInterfaces ();
196+ while (nets != null && nets .hasMoreElements () && !hasIPv4 ) {
197+ java .net .NetworkInterface nif = nets .nextElement ();
198+ try {
199+ if (!nif .isUp () || nif .isLoopback ()) continue ;
200+ } catch (Throwable ignore ) {
201+ // ignore and continue checking other interfaces
202+ continue ;
203+ }
204+ java .util .Enumeration <java .net .InetAddress > addrs = nif .getInetAddresses ();
205+ while (addrs .hasMoreElements ()) {
206+ java .net .InetAddress addr = addrs .nextElement ();
207+ if (addr instanceof java .net .Inet4Address && !addr .isLoopbackAddress ()) {
208+ hasIPv4 = true ;
209+ break ;
210+ }
211+ }
212+ }
213+ if (hasIPv4 ) {
214+ res .addDefault ("-Djava.net.preferIPv4Stack=" , "true" );
215+ }
216+ } catch (java .net .SocketException e ) {
217+ LOG .warning ("Failed to detect IPv4 address" , e );
218+ }
219+
193220 final int javaVersion = options .getJava ().getParsedVersion ();
194221 final boolean is64bit = options .getJava ().getBits () == Bits .BIT_64 ;
195222
You can’t perform that action at this time.
0 commit comments