Small fix
This commit is contained in:
parent
1a6edff347
commit
e69ab31dd2
3 changed files with 18 additions and 10 deletions
|
|
@ -197,11 +197,21 @@ public class ByteUtil {
|
||||||
* @return A multiline String with human readable HEX and ASCII
|
* @return A multiline String with human readable HEX and ASCII
|
||||||
*/
|
*/
|
||||||
public static String toFormattedString(byte[] data){
|
public static String toFormattedString(byte[] data){
|
||||||
|
return toFormattedString(data, 0, data.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Presents a binary array in HEX and ASCII
|
||||||
|
*
|
||||||
|
* @param data The source binary data to format
|
||||||
|
* @return A multiline String with human readable HEX and ASCII
|
||||||
|
*/
|
||||||
|
public static String toFormattedString(byte[] data, int offset, int length){
|
||||||
StringBuffer output = new StringBuffer();
|
StringBuffer output = new StringBuffer();
|
||||||
|
|
||||||
//000 XX XX XX XX XX XX XX XX '........'
|
//000 XX XX XX XX XX XX XX XX '........'
|
||||||
int maxOffset = (""+data.length).length();
|
int maxOffset = (""+length).length();
|
||||||
for(int offset=0; offset<data.length; offset+=8){
|
for(; offset<length; offset+=8){
|
||||||
if(offset != 0)
|
if(offset != 0)
|
||||||
output.append('\n');
|
output.append('\n');
|
||||||
|
|
||||||
|
|
@ -215,7 +225,7 @@ public class ByteUtil {
|
||||||
|
|
||||||
// HEX
|
// HEX
|
||||||
for(int i=0; i<8; ++i){
|
for(int i=0; i<8; ++i){
|
||||||
if(offset+i < data.length)
|
if(offset+i < length)
|
||||||
output.append(Converter.toHexString(data[offset+i]));
|
output.append(Converter.toHexString(data[offset+i]));
|
||||||
else
|
else
|
||||||
output.append(" ");
|
output.append(" ");
|
||||||
|
|
@ -226,7 +236,7 @@ public class ByteUtil {
|
||||||
// ACII
|
// ACII
|
||||||
output.append('\'');
|
output.append('\'');
|
||||||
for(int i=0; i<8; ++i){
|
for(int i=0; i<8; ++i){
|
||||||
if(offset+i < data.length)
|
if(offset+i < length)
|
||||||
if( 32 <= data[offset+i] && data[offset+i] <= 126 )
|
if( 32 <= data[offset+i] && data[offset+i] <= 126 )
|
||||||
output.append((char)data[offset+i]);
|
output.append((char)data[offset+i]);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ public class MulticastDNSClient extends ThreadedUDPNetwork implements ThreadedUD
|
||||||
MDNS_MULTICAST_PORT );
|
MDNS_MULTICAST_PORT );
|
||||||
|
|
||||||
System.out.println("#### Sending Request");
|
System.out.println("#### Sending Request");
|
||||||
System.out.println(ByteUtil.toFormattedString(udpPacket.getData()));
|
System.out.println(ByteUtil.toFormattedString(udpPacket.getData(), udpPacket.getOffset(), udpPacket.getLength()));
|
||||||
MultiPrintStream.out.dump(dnsPacket,3);
|
MultiPrintStream.out.dump(dnsPacket,3);
|
||||||
|
|
||||||
//send(udpPacket);
|
//send(udpPacket);
|
||||||
|
|
@ -91,7 +91,7 @@ public class MulticastDNSClient extends ThreadedUDPNetwork implements ThreadedUD
|
||||||
BinaryStructInputStream in = new BinaryStructInputStream(buffer);
|
BinaryStructInputStream in = new BinaryStructInputStream(buffer);
|
||||||
DNSPacket dnsPacket = DNSPacket.read(in);
|
DNSPacket dnsPacket = DNSPacket.read(in);
|
||||||
System.out.println("#### Received response from "+packet.getAddress());
|
System.out.println("#### Received response from "+packet.getAddress());
|
||||||
System.out.println(ByteUtil.toFormattedString(packet.getData()));
|
System.out.println(ByteUtil.toFormattedString(packet.getData(), packet.getOffset(), packet.getLength()));
|
||||||
MultiPrintStream.out.dump(dnsPacket,3);
|
MultiPrintStream.out.dump(dnsPacket,3);
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
logger.log(Level.WARNING, null, e);
|
logger.log(Level.WARNING, null, e);
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,8 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static zutil.net.dns.DNSPacketQuestion.QCLASS_IN;
|
import static zutil.net.dns.DNSPacketQuestion.*;
|
||||||
import static zutil.net.dns.DNSPacketQuestion.QTYPE_A;
|
import static zutil.net.dns.DNSPacketResource.*;
|
||||||
import static zutil.net.dns.DNSPacketResource.CLASS_IN;
|
|
||||||
import static zutil.net.dns.DNSPacketResource.TYPE_A;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver
|
* Created by Ziver
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue