aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/measite/minidns/record
diff options
context:
space:
mode:
authorRene Treffer <treffer@measite.de>2014-04-02 22:00:32 +0200
committerRene Treffer <treffer@measite.de>2014-04-02 22:00:32 +0200
commit32b27c53e03d3e1f25230efc48610efeab31f9a2 (patch)
tree89b60b17670b098cbb476b855c8fbe430a2edb80 /src/de/measite/minidns/record
Initial commit
Diffstat (limited to 'src/de/measite/minidns/record')
-rw-r--r--src/de/measite/minidns/record/A.java37
-rw-r--r--src/de/measite/minidns/record/AAAA.java43
-rw-r--r--src/de/measite/minidns/record/CNAME.java44
-rw-r--r--src/de/measite/minidns/record/Data.java16
-rw-r--r--src/de/measite/minidns/record/NS.java12
-rw-r--r--src/de/measite/minidns/record/SRV.java74
6 files changed, 226 insertions, 0 deletions
diff --git a/src/de/measite/minidns/record/A.java b/src/de/measite/minidns/record/A.java
new file mode 100644
index 000000000..a85a7af0d
--- /dev/null
+++ b/src/de/measite/minidns/record/A.java
@@ -0,0 +1,37 @@
+package de.measite.minidns.record;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+
+import de.measite.minidns.Record.TYPE;
+
+public class A implements Data {
+
+ 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/src/de/measite/minidns/record/AAAA.java b/src/de/measite/minidns/record/AAAA.java
new file mode 100644
index 000000000..d89147b2c
--- /dev/null
+++ b/src/de/measite/minidns/record/AAAA.java
@@ -0,0 +1,43 @@
+package de.measite.minidns.record;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+
+import de.measite.minidns.Record.TYPE;
+
+public class AAAA implements Data {
+
+ 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/src/de/measite/minidns/record/CNAME.java b/src/de/measite/minidns/record/CNAME.java
new file mode 100644
index 000000000..4657b4a51
--- /dev/null
+++ b/src/de/measite/minidns/record/CNAME.java
@@ -0,0 +1,44 @@
+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;
+
+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() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @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/src/de/measite/minidns/record/Data.java b/src/de/measite/minidns/record/Data.java
new file mode 100644
index 000000000..9cb803742
--- /dev/null
+++ b/src/de/measite/minidns/record/Data.java
@@ -0,0 +1,16 @@
+package de.measite.minidns.record;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+
+import de.measite.minidns.Record.TYPE;
+
+public interface Data {
+
+ TYPE getType();
+
+ byte[] toByteArray();
+
+ void parse(DataInputStream dis, byte data[], int length) throws IOException;
+
+}
diff --git a/src/de/measite/minidns/record/NS.java b/src/de/measite/minidns/record/NS.java
new file mode 100644
index 000000000..bf07e8c41
--- /dev/null
+++ b/src/de/measite/minidns/record/NS.java
@@ -0,0 +1,12 @@
+package de.measite.minidns.record;
+
+import de.measite.minidns.Record.TYPE;
+
+public class NS extends CNAME {
+
+ @Override
+ public TYPE getType() {
+ return TYPE.NS;
+ }
+
+}
diff --git a/src/de/measite/minidns/record/SRV.java b/src/de/measite/minidns/record/SRV.java
new file mode 100644
index 000000000..32b70c4d3
--- /dev/null
+++ b/src/de/measite/minidns/record/SRV.java
@@ -0,0 +1,74 @@
+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;
+
+public class SRV implements Data {
+
+ protected int priority;
+ protected int weight;
+ protected int port;
+ protected String name;
+
+ public int getPriority() {
+ return priority;
+ }
+
+ public void setPriority(int priority) {
+ this.priority = priority;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public void setWeight(int weight) {
+ this.weight = weight;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public byte[] toByteArray() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @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;
+ }
+
+}