IPv4 vs IPv6
This commit is contained in:
parent
303042078c
commit
a3466c121d
@ -1,6 +1,9 @@
|
||||
package peer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
@ -83,8 +86,17 @@ public class Node {
|
||||
private byte[] addrToByte(SocketAddress addr) {
|
||||
// TODO Wäre cool, die IP nicht einfach als String zu schicken.
|
||||
// Was machen mit IPV4 vs IPV6?
|
||||
String s = addr.toString();
|
||||
return s.getBytes();
|
||||
InetSocketAddress a = (InetSocketAddress) addr;
|
||||
|
||||
if (a.getAddress() instanceof Inet6Address) {
|
||||
// seems to be IPv6
|
||||
} else if (a.getAddress() instanceof Inet4Address) {
|
||||
// seems to be IPv4
|
||||
} else {
|
||||
// invalid ip address
|
||||
}
|
||||
|
||||
return a.getAddress().getAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user