Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions securetime/src/main/java/pl/tajchert/securetime/SecureTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import pl.tajchert.securetime.protocol.RtWire
import pl.tajchert.securetime.util.BytesUtil
import timber.log.Timber
import java.math.BigInteger
import java.net.Inet6Address
import java.net.InetSocketAddress
import java.net.StandardProtocolFamily
import java.nio.ByteBuffer
Expand Down Expand Up @@ -35,7 +36,13 @@ public class SecureTime(
fun getTime(): Triple<Instant, Int, Long> {
val addr = InetSocketAddress(host, port)

val channel = DatagramChannel.open(StandardProtocolFamily.INET)
val family = if (addr.address is Inet6Address) {
StandardProtocolFamily.INET6
} else {
StandardProtocolFamily.INET
}

val channel = DatagramChannel.open(family)
channel.configureBlocking(false)

// Create a request message
Expand Down Expand Up @@ -109,4 +116,4 @@ public class SecureTime(
val decoded = Base64.getDecoder().decode(valueBase64)
return String.format("%040x", BigInteger(1, decoded))
}
}
}