Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java UDP标头是否有其他数据?_Java_Header_Udp_Extra - Fatal编程技术网

Java UDP标头是否有其他数据?

Java UDP标头是否有其他数据?,java,header,udp,extra,Java,Header,Udp,Extra,为什么UDP数据包在报头中有额外的数据 我知道Java正在自动设置UDP头,我不能修改它,但它应该是8字节长,而不是40字节0x69 0x82 0xDB 0xAE 0x00 0x2D 0xFE 0x40通常它应该是标题。这32字节的额外数据是什么 该数据包是通过环回(在我的本地主机上)上的wireshark捕获的。这就是问题所在 这是我发送数据包的方式: byte[] responseHeader = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x

为什么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;
}
byte[]responseHeader={(字节)0xFF,(字节)0xFF,(字节)0xFF,(字节)0xFF,(字节)0xFF,0x66,(字节)0x0A};
LinkedList服务器_数组=新建LinkedList();
int server_array_length=0;
字节[]temp_ip=getByteIp(“89.40.233.17:27015”);//0x59 0x28 0xE9 0x11 0x69 0x87
服务器阵列。添加(临时ip);
服务器阵列长度+=临时ip.length;
temp_ip=getByteIp(“89.40.233.38:27015”);//0x59 0x28 0xE9 0x26 0x69 0x87
服务器阵列。添加(临时ip);
服务器阵列长度+=临时ip.length;
temp_ip=getByteIp(“89.40.233.5:27015”);//0x59 0x28 0xE9 0x05 0x69 0x87
服务器阵列。添加(临时ip);
服务器阵列长度+=临时ip.length;
temp_ip=getByteIp(“89.40.233.10:27015”);//0x59 0x28 0xE9 0x0A 0x69 0x87
服务器阵列。添加(临时ip);
服务器阵列长度+=临时ip.length;
字节[]数组\服务器=新字节[服务器\数组\长度];
int lastIndex=0;
for(字节[]b:服务器\阵列){
System.arraycopy(b,0,阵列服务器,lastIndex,b.length);
lastIndex+=b.长度;
}
byte[]response=新字节[responseHeader.length+array_servers.length+6];
System.arraycopy(responseHeader,0,response,0,responseHeader.length);
System.arraycopy(阵列服务器,0,响应,响应头.length,阵列服务器.length);
字节[]页脚=新字节[6];
页脚=getByteIp(“0.0.0.0:0”);//0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
System.arraycopy(页脚,0,响应,响应.length-6,页脚.length);
socket.send(响应);
System.out.println(“发送:“+response.length+”字节数据”);//发送:37字节数据
专用字节[]getByteIp(字符串fullData){
String[]data=fullData.split(“:”);
字节[]返回数组=新字节[6];
字节[]ip=新字节[4];
试一试{
ip=InetAddress.getByName(数据[0]).getAddress();
}捕获(未知后异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
字节[]端口=新字节[2];
port=ByteBuffer.allocate(2).putShort((short)Integer.parseInt(数据[1]).array();
System.arraycopy(ip,0,returnArray,0,ip.length);
System.arraycopy(端口,0,返回数组,ip.length,端口.length);
返回数组;
}

如果您查看标题数据,它表示长度为
0x2d
,即45字节(包括标题)。然后在标题后面计算数据字节,共有37个字节。37+8等于45。Ergo是一个完整的UDP包



或者您是指UDP头之前的字节?这是以太网和IP报头。

是的,我用红线标记了它。在那里是正常的吗?@ZbarceaChristian好吧,如果你使用的是以太网IP,那么当然可以。我不明白。。。我正在尝试复制UDP响应。目前,我正在观看最初的响应(由游戏生成-用C编写)和我的(用我的Java应用程序生成)用wireshark捕获的数据包。最初的响应它只包含8字节的报头,而我的响应包含IP和以太网报头(额外数据)。为什么?