Added DNS message compression, it does not handle it right now
This commit is contained in:
parent
e69ab31dd2
commit
e8e3deb056
5 changed files with 174 additions and 9 deletions
|
|
@ -128,8 +128,9 @@ public class Converter {
|
|||
*
|
||||
* @param hex is the hex value
|
||||
* @return a byte that corresponds to the hex
|
||||
* @throws IllegalArgumentException if hex is not a valid hex character
|
||||
*/
|
||||
public static byte hexToByte( char hex ){
|
||||
public static byte hexToByte( char hex ) throws IllegalArgumentException{
|
||||
switch( Character.toLowerCase(hex) ){
|
||||
case '0': return 0x00;
|
||||
case '1': return 0x01;
|
||||
|
|
@ -147,8 +148,9 @@ public class Converter {
|
|||
case 'd': return 0x0d;
|
||||
case 'e': return 0x0e;
|
||||
case 'f': return 0x0f;
|
||||
default:
|
||||
throw new IllegalArgumentException("'"+hex+"' is an illegal hex character only 0-9 and a-f characters allowed");
|
||||
}
|
||||
return (byte)0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ import java.util.List;
|
|||
/**
|
||||
* This class is a general wrapper for a whole DNS packet.
|
||||
*
|
||||
* Created by Ziver on 2016-04-11.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc1035">rfc1035</a>
|
||||
* @author Ziver on 2016-04-11.
|
||||
*/
|
||||
public class DNSPacket {
|
||||
private DNSPacketHeader header;
|
||||
|
|
|
|||
|
|
@ -151,13 +151,22 @@ public class DNSPacketQuestion implements BinaryStruct {
|
|||
public String read(InputStream in, BinaryFieldData field) throws IOException {
|
||||
StringBuilder str = new StringBuilder();
|
||||
int c = in.read();
|
||||
while (c > 0){
|
||||
for (int i=0; i<c; ++i){
|
||||
str.append((char)in.read());
|
||||
// Is this a pointer
|
||||
if ((c & 0b1100_0000) == 0b1100_0000 ){
|
||||
int offset = (c & 0b0011_1111) << 8;
|
||||
offset |= in.read() & 0b1111_1111;
|
||||
str.append(offset);
|
||||
}
|
||||
// Normal Domain String
|
||||
else {
|
||||
while (c > 0) {
|
||||
for (int i = 0; i < c; ++i) {
|
||||
str.append((char) in.read());
|
||||
}
|
||||
c = in.read();
|
||||
if (c > 0)
|
||||
str.append('.');
|
||||
}
|
||||
c = in.read();
|
||||
if (c > 0)
|
||||
str.append('.');
|
||||
}
|
||||
return str.toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,4 +156,18 @@ public class BinaryFieldData {
|
|||
public BinaryFieldSerializer getSerializer(){
|
||||
return serializer;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return field.getDeclaringClass().getSimpleName() + "::" + field.getName() +
|
||||
" (" +
|
||||
(lengthField != null ?
|
||||
"LengthField: " + lengthField +", LengthMultiplier: "+lengthMultiplier :
|
||||
length+" bits") +
|
||||
(serializer != null ?
|
||||
", Serializer: " + serializer.getClass().getName() : "") +
|
||||
")";
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue