Skip to content

Commit

Permalink
AddressUtils: add stripHost() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarning committed Aug 26, 2024
1 parent f8c95e5 commit 4e84cc4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions app/src/main/kotlin/d/d/meshenger/AddressUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal object AddressUtils
}

// remove interface from link local address
// fe80::1%wlan0 => fe80::1
fun stripInterface(address: String): String {
val pc = address.indexOf('%')
return if (pc == -1) {
Expand All @@ -38,6 +39,15 @@ internal object AddressUtils
}
}

// strip first entry, e.g.:
// /1.2.3.4 => 1.2.3.4
// google.com/1.2.3.4 => 1.2.3.4
// google.com => google.com
fun stripHost(address: String): String {
val pos = address.indexOf('/')
return address.substring(pos + 1)
}

// coarse address type distinction
enum class AddressType {
GLOBAL_IP, LOCAL_IP, MULTICAST_IP, DOMAIN
Expand Down Expand Up @@ -186,10 +196,10 @@ internal object AddressUtils
return null
}
} else if (address is Inet6Address) {
val str = address.toString().trimStart('/')
val str = stripHost(address.toString())
return "[$str]:$port"
} else {
val str = address.toString().trimStart('/')
val str = stripHost(address.toString())
return "$str:$port"
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/d/d/meshenger/call/RTCUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal object RTCUtils
}

// 192.168.1.45, 2a02:8109::7cc5, fe80::1234%wlan0 (WebRTC does not accept link local addresses..)
val remoteAddressString = AddressUtils.stripHost(remoteAddress)
val remoteAddressString = AddressUtils.stripHost(remoteAddress.toString())

//a=candidate:<foundation> <component> <protocol> <priority> <public-ip-here> <port> typ host
val iceUdp = "a=candidate:3333333333 1 udp 2222222222 $remoteAddressString ${MainService.serverPort + 1} typ host"
Expand Down

0 comments on commit 4e84cc4

Please sign in to comment.