Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection.inetAddress() fails for IPv6 addresses #30

Closed
angusholder opened this issue Oct 19, 2023 · 3 comments · Fixed by #31
Closed

Connection.inetAddress() fails for IPv6 addresses #30

angusholder opened this issue Oct 19, 2023 · 3 comments · Fixed by #31

Comments

@angusholder
Copy link

Here's a minimal repro

package com.example

import com.ngrok.Connection
import com.ngrok.Listener
import com.ngrok.Session

fun main() {
    val session: Session = Session.withAuthtoken("...").connect()

    session.use {
        val listener: Listener.Edge = session.edge()
            .label("edge", "...")
            .listen()

        listener.use {
            while (true) {
                // Accept a new connection
                val conn: Connection.Edge = listener.accept()

                println("conn.getRemoteAddr() = ${conn.remoteAddr}")
                println("conn.inetAddress() = ${conn.inetAddress()}") // Crashes
            }
        }
    }
}

And the log output from running it

conn.getRemoteAddr() = [2a00:23c8:a8dd:e501:b02c:ea1a:83cf:395e]:64440
Exception in thread "main" java.lang.NumberFormatException: For input string: "23c8"
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
	at java.base/java.lang.Integer.parseInt(Integer.java:668)
	at java.base/java.lang.Integer.parseInt(Integer.java:786)
	at com.ngrok.Connection.inetAddress(Connection.java:25)
	at com.example.NgrokIPV6ReproKt.main(NgrokIPV6Repro.kt:21)
	at com.example.NgrokIPV6ReproKt.main(NgrokIPV6Repro.kt)
@nikolay-ngrok
Copy link
Contributor

nikolay-ngrok commented Oct 19, 2023

Hi @angusholder ,

Thanks for using ngrok-java and reporting this issue. Indeed, we should be using the last column : as a divider between the host and the port of an address, before passing it to InetAddress to create one. Therefore, I've created a PR #31 that amends the logic to do so. Don't hesitate to reach out if you have any other issues or comments with our library.

@angusholder
Copy link
Author

Thanks!

@nikolay-ngrok
Copy link
Contributor

@angusholder - we've released v0.4.1 which contains the above fix. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants