|
@@ -10,6 +10,7 @@ import java.net.SocketImpl;
|
|
|
|
|
|
import javax.net.ServerSocketFactory;
|
|
|
|
|
|
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
import de.tudarmstadt.informatik.hostage.system.Device;
|
|
|
import de.tudarmstadt.informatik.hostage.system.PrivilegedPort;
|
|
|
import de.tudarmstadt.informatik.hostage.system.PrivilegedPort.TYPE;
|
|
@@ -24,16 +25,24 @@ public class MyServerSocketFactory extends ServerSocketFactory {
|
|
|
socket = new ServerSocket();
|
|
|
socket.setReuseAddress(true);
|
|
|
socket.bind(new InetSocketAddress(port));
|
|
|
- } else if (Device.isPorthackInstalled()) {
|
|
|
- FileDescriptor fd = new PrivilegedPort(TYPE.TCP, port).getFD();
|
|
|
- socket = new ServerSocket();
|
|
|
- try {
|
|
|
- SocketImpl impl = getImpl(socket);
|
|
|
- injectFD(fd, impl);
|
|
|
- setBound(socket);
|
|
|
- } catch (NoSuchFieldException e) {
|
|
|
- } catch (IllegalAccessException e) {
|
|
|
- } catch (IllegalArgumentException e) {
|
|
|
+ } else if (Device.isRooted()) {
|
|
|
+ if (Device.isPorthackInstalled()) {
|
|
|
+ FileDescriptor fd = new PrivilegedPort(TYPE.TCP, port).getFD();
|
|
|
+ socket = new ServerSocket();
|
|
|
+ try {
|
|
|
+ SocketImpl impl = getImpl(socket);
|
|
|
+ injectFD(fd, impl);
|
|
|
+ setBound(socket);
|
|
|
+ } catch (NoSuchFieldException e) {
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ }
|
|
|
+ } else { // use ip tables
|
|
|
+ int redirectedPort = port + 1024 + 27113;
|
|
|
+ HelperUtils.redirectPort("tcp", port, redirectedPort);
|
|
|
+ socket = new ServerSocket();
|
|
|
+ socket.setReuseAddress(true);
|
|
|
+ socket.bind(new InetSocketAddress(redirectedPort));
|
|
|
}
|
|
|
}
|
|
|
return socket;
|