File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
service/src/main/java/com/github/kr328/clash/service/util Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import java.net.InetAddress
77fun InetAddress.asSocketAddressText (port : Int ): String {
88 return when (this ) {
99 is Inet6Address ->
10- " [${numericToTextFormat(this .address )} ]:$port "
10+ " [${numericToTextFormat(this )} ]:$port "
1111 is Inet4Address ->
1212 " ${this .hostAddress} :$port "
1313 else -> throw IllegalArgumentException (" Unsupported Inet type ${this .javaClass} " )
@@ -16,7 +16,8 @@ fun InetAddress.asSocketAddressText(port: Int): String {
1616
1717private const val INT16SZ = 2
1818private const val INADDRSZ = 16
19- private fun numericToTextFormat (src : ByteArray ): String {
19+ private fun numericToTextFormat (address : Inet6Address ): String {
20+ var src = address.getAddress()
2021 val sb = StringBuilder (39 )
2122 for (i in 0 until INADDRSZ / INT16SZ ) {
2223 sb.append(
@@ -29,6 +30,14 @@ private fun numericToTextFormat(src: ByteArray): String {
2930 sb.append(" :" )
3031 }
3132 }
33+ // handle [fe80::1%wlan0] like address from Inet6Address.getHostAddress()
34+ // For the Android system, a ScopeId must be carried when initiating a connection to an ipv6 link-local address
35+ // Note that the Scope must be returned as an int type, not a string format
36+ // Reference: https://github.com/golang/go/issues/68082
37+ if (address.getScopeId() > 0 ) {
38+ sb.append(" %" )
39+ sb.append(address.getScopeId())
40+ }
3241 return sb.toString()
3342}
3443
You can’t perform that action at this time.
0 commit comments