Skip to content

Commit a902227

Browse files
committed
try handle scopeId
1 parent 5816076 commit a902227

File tree

1 file changed

+7
-2
lines changed
  • service/src/main/java/com/github/kr328/clash/service/util

1 file changed

+7
-2
lines changed

service/src/main/java/com/github/kr328/clash/service/util/Address.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import java.net.InetAddress
77
fun 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

1717
private const val INT16SZ = 2
1818
private 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,10 @@ private fun numericToTextFormat(src: ByteArray): String {
2930
sb.append(":")
3031
}
3132
}
33+
if (address.getScopeId() > 0){
34+
sb.append("%")
35+
sb.append(address.getScopeId())
36+
}
3237
return sb.toString()
3338
}
3439

0 commit comments

Comments
 (0)