diff options
Diffstat (limited to 'libs/minidns/src/main/java/de/measite/minidns/record')
9 files changed, 395 insertions, 6 deletions
diff --git a/libs/minidns b/libs/minidns deleted file mode 160000 -Subproject 152be6eb1a22da8cebe24ac4ee05b487936c9f2 diff --git a/libs/minidns/src/main/java/de/measite/minidns/record/A.java b/libs/minidns/src/main/java/de/measite/minidns/record/A.java new file mode 100644 index 00000000..4311c651 --- /dev/null +++ b/libs/minidns/src/main/java/de/measite/minidns/record/A.java @@ -0,0 +1,43 @@ +package de.measite.minidns.record; + +import java.io.DataInputStream; +import java.io.IOException; + +import de.measite.minidns.Record.TYPE; + +/** + * A record payload (ip pointer). + */ +public class A implements Data { + + /** + * Target IP. + */ + private byte[] ip; + + @Override + public TYPE getType() { + return TYPE.A; + } + + @Override + public byte[] toByteArray() { + return ip; + } + + @Override + public void parse(DataInputStream dis, byte[] data, int length) + throws IOException { + ip = new byte[4]; + dis.readFully(ip); + } + + @Override + public String toString() { + return Integer.toString(ip[0] & 0xff) + "." + + Integer.toString(ip[1] & 0xff) + "." + + Integer.toString(ip[2] & 0xff) + "." + + Integer.toString(ip[3] & 0xff); + } + +} diff --git a/libs/minidns/src/main/java/de/measite/minidns/record/AAAA.java b/libs/minidns/src/main/java/de/measite/minidns/record/AAAA.java new file mode 100644 index 00000000..e4fd5ecf --- /dev/null +++ b/libs/minidns/src/main/java/de/measite/minidns/record/AAAA.java @@ -0,0 +1,49 @@ +package de.measite.minidns.record; + +import java.io.DataInputStream; +import java.io.IOException; + +import de.measite.minidns.Record.TYPE; + +/** + * AAAA payload (an ipv6 pointer). + */ +public class AAAA implements Data { + + /** + * The ipv6 address. + */ + private byte[] ip; + + @Override + public TYPE getType() { + return TYPE.AAAA; + } + + @Override + public byte[] toByteArray() { + return ip; + } + + @Override + public void parse(DataInputStream dis, byte[] data, int length) + throws IOException { + ip = new byte[16]; + dis.readFully(ip); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < ip.length; i += 2) { + if (i != 0) { + sb.append(':'); + } + sb.append(Integer.toHexString( + ((ip[i] & 0xff) << 8) + (ip[i + 1] & 0xff) + )); + } + return sb.toString(); + } + +} diff --git a/libs/minidns/src/main/java/de/measite/minidns/record/CNAME.java b/libs/minidns/src/main/java/de/measite/minidns/record/CNAME.java new file mode 100644 index 00000000..1ac27814 --- /dev/null +++ b/libs/minidns/src/main/java/de/measite/minidns/record/CNAME.java @@ -0,0 +1,46 @@ +package de.measite.minidns.record; + +import java.io.DataInputStream; +import java.io.IOException; + +import de.measite.minidns.Record.TYPE; +import de.measite.minidns.util.NameUtil; + +/** + * CNAME payload (pointer to another domain / address). + */ +public class CNAME implements Data { + + protected String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public byte[] toByteArray() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void parse(DataInputStream dis, byte[] data, int length) + throws IOException + { + this.name = NameUtil.parse(dis, data); + } + + @Override + public TYPE getType() { + return TYPE.CNAME; + } + + @Override + public String toString() { + return "to \"" + name + "\""; + } + +} diff --git a/libs/minidns/src/main/java/de/measite/minidns/record/Data.java b/libs/minidns/src/main/java/de/measite/minidns/record/Data.java new file mode 100644 index 00000000..7f2db03a --- /dev/null +++ b/libs/minidns/src/main/java/de/measite/minidns/record/Data.java @@ -0,0 +1,34 @@ +package de.measite.minidns.record; + +import java.io.DataInputStream; +import java.io.IOException; + +import de.measite.minidns.Record.TYPE; + +/** + * Generic payload class. + */ +public interface Data { + + /** + * The payload type. + * @return The payload type. + */ + TYPE getType(); + + /** + * Binary representation of this payload. + * @return The binary representation of this payload. + */ + byte[] toByteArray(); + + /** + * Parse this payload. + * @param dis The input stream. + * @param data The plain data (needed for name cross references). + * @param length The payload length. + * @throws IOException on io error (read past paket boundary). + */ + void parse(DataInputStream dis, byte data[], int length) throws IOException; + +} diff --git a/libs/minidns/src/main/java/de/measite/minidns/record/NS.java b/libs/minidns/src/main/java/de/measite/minidns/record/NS.java new file mode 100644 index 00000000..8ac2d4c3 --- /dev/null +++ b/libs/minidns/src/main/java/de/measite/minidns/record/NS.java @@ -0,0 +1,15 @@ +package de.measite.minidns.record; + +import de.measite.minidns.Record.TYPE; + +/** + * Nameserver record. + */ +public class NS extends CNAME { + + @Override + public TYPE getType() { + return TYPE.NS; + } + +} diff --git a/libs/minidns/src/main/java/de/measite/minidns/record/PTR.java b/libs/minidns/src/main/java/de/measite/minidns/record/PTR.java new file mode 100644 index 00000000..6e200655 --- /dev/null +++ b/libs/minidns/src/main/java/de/measite/minidns/record/PTR.java @@ -0,0 +1,19 @@ +package de.measite.minidns.record; + +import java.io.DataInputStream; +import java.io.IOException; + +import de.measite.minidns.Record.TYPE; +import de.measite.minidns.util.NameUtil; + +/** + * A PTR record is handled like a CNAME + */ +public class PTR extends CNAME { + + @Override + public TYPE getType() { + return TYPE.PTR; + } + +} diff --git a/libs/minidns/src/main/java/de/measite/minidns/record/SRV.java b/libs/minidns/src/main/java/de/measite/minidns/record/SRV.java new file mode 100644 index 00000000..707bf3f5 --- /dev/null +++ b/libs/minidns/src/main/java/de/measite/minidns/record/SRV.java @@ -0,0 +1,124 @@ +package de.measite.minidns.record; + +import java.io.DataInputStream; +import java.io.IOException; + +import de.measite.minidns.Record.TYPE; +import de.measite.minidns.util.NameUtil; + +/** + * SRV record payload (service pointer). + */ +public class SRV implements Data { + + /** + * The priority of this service. + */ + protected int priority; + + /** + * The weight of this service. + */ + protected int weight; + + /** + * The target port. + */ + protected int port; + + /** + * The target server. + */ + protected String name; + + /** + * The priority of this service. Lower values mean higher priority. + * @return The priority. + */ + public int getPriority() { + return priority; + } + + /** + * Set the priority of this service entry. Lower values have higher priority. + * @param priority The new priority. + */ + public void setPriority(int priority) { + this.priority = priority; + } + + /** + * The weight of this service. Services with the same priority should be + * balanced based on weight. + * @return The weight of this service. + */ + public int getWeight() { + return weight; + } + + /** + * Set the weight of this service. + * @param weight The new weight of this service. + */ + public void setWeight(int weight) { + this.weight = weight; + } + + /** + * The target port of this service. + * @return The target port of this service. + */ + public int getPort() { + return port; + } + + /** + * Set the target port of this service. + * @param port The new target port. + */ + public void setPort(int port) { + this.port = port; + } + + /** + * The name of the target server. + * @return The target servers name. + */ + public String getName() { + return name; + } + + /** + * Set the name of the target server. + * @param name The new target servers name. + */ + public void setName(String name) { + this.name = name; + } + + @Override + public byte[] toByteArray() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void parse(DataInputStream dis, byte[] data, int length) + throws IOException + { + this.priority = dis.readUnsignedShort(); + this.weight = dis.readUnsignedShort(); + this.port = dis.readUnsignedShort(); + this.name = NameUtil.parse(dis, data); + } + + @Override + public String toString() { + return "SRV " + name + ":" + port + " p:" + priority + " w:" + weight; + } + + @Override + public TYPE getType() { + return TYPE.SRV; + } + +} diff --git a/libs/minidns/src/main/java/de/measite/minidns/record/TXT.java b/libs/minidns/src/main/java/de/measite/minidns/record/TXT.java new file mode 100644 index 00000000..03e73040 --- /dev/null +++ b/libs/minidns/src/main/java/de/measite/minidns/record/TXT.java @@ -0,0 +1,65 @@ +package de.measite.minidns.record; + +import java.io.DataInputStream; +import java.io.IOException; + +import de.measite.minidns.Record.TYPE; +import de.measite.minidns.util.NameUtil; + +/** + * TXT record (actually a binary blob with wrappers for text content). + */ +public class TXT implements Data { + + protected byte[] blob; + + public byte[] getBlob() { + return blob; + } + + public void setBlob(byte[] blob) { + this.blob = blob; + } + + public String getText() { + try { + return (new String(blob, "UTF-8")).intern(); + } catch (Exception e) { + /* Can't happen for UTF-8 unless it's really a blob */ + return null; + } + } + + public void setText(String text) { + try { + this.blob = text.getBytes("UTF-8"); + } catch (Exception e) { + /* Can't happen, UTF-8 IS supported */ + throw new RuntimeException("UTF-8 not supported", e); + } + } + + @Override + public byte[] toByteArray() { + throw new UnsupportedOperationException("Not implemented yet"); + } + + @Override + public void parse(DataInputStream dis, byte[] data, int length) + throws IOException + { + blob = new byte[length]; + dis.readFully(blob); + } + + @Override + public TYPE getType() { + return TYPE.TXT; + } + + @Override + public String toString() { + return "\"" + getText() + "\""; + } + +} |