|
@@ -5,7 +5,6 @@ import java.io.IOException;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.net.DatagramSocket;
|
|
|
import java.net.DatagramSocketImpl;
|
|
|
-import java.net.InetSocketAddress;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.system.Device;
|
|
|
import de.tudarmstadt.informatik.hostage.system.PrivilegedPort;
|
|
@@ -16,16 +15,13 @@ public class MyDatagramSocketFactory {
|
|
|
public DatagramSocket createDatagramSocket(int port) throws IOException {
|
|
|
DatagramSocket socket = null;
|
|
|
if (port > 1023) {
|
|
|
- socket = new DatagramSocket();
|
|
|
- socket.bind(new InetSocketAddress(port));
|
|
|
+ socket = new DatagramSocket(port);
|
|
|
} else if (Device.isPPInstalled()) {
|
|
|
FileDescriptor fd = new PrivilegedPort(TYPE.UDP, port).getFD();
|
|
|
socket = new DatagramSocket();
|
|
|
try {
|
|
|
DatagramSocketImpl impl = getImpl(socket);
|
|
|
injectFD(fd, impl);
|
|
|
- injectImpl(impl, socket);
|
|
|
- setBound(socket);
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
} catch (IllegalAccessException e) {
|
|
|
} catch (IllegalArgumentException e) {
|
|
@@ -48,16 +44,4 @@ public class MyDatagramSocketFactory {
|
|
|
fdField.set(impl, fd);
|
|
|
}
|
|
|
|
|
|
- private void injectImpl(DatagramSocketImpl impl, DatagramSocket socket) throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException {
|
|
|
- Field implField = socket.getClass().getDeclaredField("impl");
|
|
|
- implField.setAccessible(true);
|
|
|
- implField.set(socket, impl);
|
|
|
- }
|
|
|
-
|
|
|
- private void setBound(DatagramSocket socket) throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException {
|
|
|
- Field boundField = socket.getClass().getDeclaredField("isBound");
|
|
|
- boundField.setAccessible(true);
|
|
|
- boundField.set(socket, true);
|
|
|
- }
|
|
|
-
|
|
|
}
|