为什么 UDP 数据包在标头中有附加数据?
我知道 Java 正在自动设置 UDP 标头,我无法修改它,但它应该是 8 个字节长,而不是 40 个!0x69 0x82 0xDB 0xAE 0x00 0x2D 0xFE 0x40
通常它应该是标题。那 32 字节的额外数据是怎么回事?
该数据包是在环回上使用wireshark(在我的本地主机上)捕获的。这会是问题吗?
这就是我发送数据包的方式:
byte[] responseHeader = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, 0x66, (byte)0x0A };
LinkedList<byte[]> server_array = new LinkedList<byte[]>();
int server_array_length = 0;
byte[] temp_ip = getByteIp("89.40.233.17:27015"); // 0x59 0x28 0xE9 0x11 0x69 0x87
server_array.add(temp_ip);
server_array_length += temp_ip.length;
temp_ip = getByteIp("89.40.233.38:27015"); // 0x59 0x28 0xE9 0x26 0x69 0x87
server_array.add(temp_ip);
server_array_length += temp_ip.length;
temp_ip = getByteIp("89.40.233.5:27015"); // 0x59 0x28 0xE9 0x05 0x69 0x87
server_array.add(temp_ip);
server_array_length += temp_ip.length;
temp_ip = getByteIp("89.40.233.10:27015"); // 0x59 0x28 0xE9 0x0A 0x69 0x87
server_array.add(temp_ip);
server_array_length += temp_ip.length;
byte[] array_servers = new byte[server_array_length];
int lastIndex = 0;
for(byte[] b : server_array){
System.arraycopy(b, 0, array_servers, lastIndex, b.length);
lastIndex += b.length;
}
byte[] response = new byte[responseHeader.length + array_servers.length + 6];
System.arraycopy(responseHeader, 0, response, 0, responseHeader.length);
System.arraycopy(array_servers, 0, response, responseHeader.length, array_servers.length);
byte[] footer = new byte[6];
footer = getByteIp("0.0.0.0:0"); // 0x00 0x00 0x00 0x00 0x00 0x00
System.arraycopy(footer, 0, response, response.length - 6, footer.length);
socket.send(response);
System.out.println("SENT: " + response.length + " bytes of data"); // SENT: 37 bytes of data
private byte[] getByteIp(String fullData){
String[] data = fullData.split(":");
byte[] returnArray = new byte[6];
byte[] ip = new byte[4];
try {
ip = InetAddress.getByName(data[0]).getAddress();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] port = new byte[2];
port = ByteBuffer.allocate(2).putShort((short)Integer.parseInt(data[1])).array();
System.arraycopy(ip, 0, returnArray, 0, ip.length);
System.arraycopy(port, 0, returnArray, ip.length, port.length);
return returnArray;
}