|
@@ -5,6 +5,7 @@ import java.io.IOException;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
import java.net.DatagramSocket;
|
|
import java.net.DatagramSocket;
|
|
import java.net.DatagramSocketImpl;
|
|
import java.net.DatagramSocketImpl;
|
|
|
|
+import java.util.NoSuchElementException;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.system.Device;
|
|
import de.tudarmstadt.informatik.hostage.system.Device;
|
|
import de.tudarmstadt.informatik.hostage.system.PrivilegedPort;
|
|
import de.tudarmstadt.informatik.hostage.system.PrivilegedPort;
|
|
@@ -14,6 +15,7 @@ public class MyDatagramSocketFactory {
|
|
|
|
|
|
public DatagramSocket createDatagramSocket(int port) throws IOException {
|
|
public DatagramSocket createDatagramSocket(int port) throws IOException {
|
|
DatagramSocket socket = null;
|
|
DatagramSocket socket = null;
|
|
|
|
+ //port = 1024;
|
|
if (port > 1023) {
|
|
if (port > 1023) {
|
|
socket = new DatagramSocket(port);
|
|
socket = new DatagramSocket(port);
|
|
} else if (Device.isPorthackInstalled()) {
|
|
} else if (Device.isPorthackInstalled()) {
|
|
@@ -22,6 +24,7 @@ public class MyDatagramSocketFactory {
|
|
try {
|
|
try {
|
|
DatagramSocketImpl impl = getImpl(socket);
|
|
DatagramSocketImpl impl = getImpl(socket);
|
|
injectFD(fd, impl);
|
|
injectFD(fd, impl);
|
|
|
|
+ injectLocalPort(port, impl);
|
|
setBound(socket);
|
|
setBound(socket);
|
|
} catch (NoSuchFieldException e) {
|
|
} catch (NoSuchFieldException e) {
|
|
} catch (IllegalAccessException e) {
|
|
} catch (IllegalAccessException e) {
|
|
@@ -45,6 +48,15 @@ public class MyDatagramSocketFactory {
|
|
fdField.set(impl, fd);
|
|
fdField.set(impl, fd);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void injectLocalPort(int port , DatagramSocketImpl impl)
|
|
|
|
+ throws NoSuchElementException, NoSuchFieldException, IllegalAccessException {
|
|
|
|
+ Class<?> plainDatagramSocketImplClazz = impl.getClass();
|
|
|
|
+ Class<?> datagramSocketImplClazz = plainDatagramSocketImplClazz.getSuperclass();
|
|
|
|
+ Field localPortField = datagramSocketImplClazz.getDeclaredField("localPort");
|
|
|
|
+ localPortField.setAccessible(true);
|
|
|
|
+ localPortField.set(impl, port);
|
|
|
|
+ }
|
|
|
|
+
|
|
private void setBound(DatagramSocket socket) throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException {
|
|
private void setBound(DatagramSocket socket) throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException {
|
|
Field boundField = socket.getClass().getDeclaredField("isBound");
|
|
Field boundField = socket.getClass().getDeclaredField("isBound");
|
|
boundField.setAccessible(true);
|
|
boundField.setAccessible(true);
|