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
7
7
fun InetAddress.asSocketAddressText (port : Int ): String {
8
8
return when (this ) {
9
9
is Inet6Address ->
10
- " [${numericToTextFormat(this .address )} ]:$port "
10
+ " [${numericToTextFormat(this )} ]:$port "
11
11
is Inet4Address ->
12
12
" ${this .hostAddress} :$port "
13
13
else -> throw IllegalArgumentException (" Unsupported Inet type ${this .javaClass} " )
@@ -16,7 +16,8 @@ fun InetAddress.asSocketAddressText(port: Int): String {
16
16
17
17
private const val INT16SZ = 2
18
18
private const val INADDRSZ = 16
19
- private fun numericToTextFormat (src : ByteArray ): String {
19
+ private fun numericToTextFormat (address : Inet6Address ): String {
20
+ var src = address.getAddress()
20
21
val sb = StringBuilder (39 )
21
22
for (i in 0 until INADDRSZ / INT16SZ ) {
22
23
sb.append(
@@ -29,6 +30,14 @@ private fun numericToTextFormat(src: ByteArray): String {
29
30
sb.append(" :" )
30
31
}
31
32
}
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
+ }
32
41
return sb.toString()
33
42
}
34
43
You can’t perform that action at this time.
0 commit comments