Skip to content

Commit

Permalink
Force IPv4 for tunnel connection
Browse files Browse the repository at this point in the history
Port forwarding created by "adb reverse" only supports IPv4.

Therefore, use 127.0.0.1 instead of the value returned by
InetAddress.getLocalhost(), which is ::1 on some devices.

See <#42>.
  • Loading branch information
rom1v committed Sep 26, 2017
1 parent b3fff75 commit c2b0fc9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/com/genymobile/gnirehtet/Net.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.genymobile.gnirehtet;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

Expand Down Expand Up @@ -47,4 +48,9 @@ public static InetAddress toInetAddress(byte[] raw) {
throw new IllegalArgumentException(e);
}
}

public static Inet4Address getLocalhostIPv4() {
byte[] localhost = {127, 0, 0, 1};
return (Inet4Address) toInetAddress(localhost);
}
}
3 changes: 1 addition & 2 deletions app/src/main/java/com/genymobile/gnirehtet/RelayTunnel.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.util.Log;

import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
Expand All @@ -46,7 +45,7 @@ public static RelayTunnel open(VpnService vpnService) throws IOException {
}

public void connect() throws IOException {
channel.connect(new InetSocketAddress(Inet4Address.getLocalHost(), DEFAULT_PORT));
channel.connect(new InetSocketAddress(Net.getLocalhostIPv4(), DEFAULT_PORT));
readClientId(channel);
}

Expand Down

0 comments on commit c2b0fc9

Please sign in to comment.