aboutsummaryrefslogtreecommitdiff
path: root/dns.c
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-08-16 15:40:25 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-08-16 15:40:25 +0300
commit6b286788c724b12da99661eec1d9a40cf82a046b (patch)
tree3f51f43d05ee58d4e2f1c12e8bcc43a397b79314 /dns.c
parentacf41993d4d699ff12238e943d7112dfdd5ace12 (diff)
downloadvsdns-6b286788c724b12da99661eec1d9a40cf82a046b.tar
vsdns-6b286788c724b12da99661eec1d9a40cf82a046b.tar.xz
vsdns-6b286788c724b12da99661eec1d9a40cf82a046b.zip
SRV parsing added.
Diffstat (limited to 'dns.c')
-rw-r--r--dns.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/dns.c b/dns.c
index 53be937..4dd219d 100644
--- a/dns.c
+++ b/dns.c
@@ -174,6 +174,24 @@ static struct dns_answers *get_answers(char **reader, char *packet, int num)
*((unsigned short *) res->data) = pref;
memcpy(res->data + 2, name, strlen(name) + 1);
free(name);
+ } else if (res->type == dns_type_srv) {
+ char *name;
+ unsigned short priority;
+ unsigned short weight;
+ unsigned short port;
+ priority = ntohs(*((unsigned short *) *reader));
+ *reader += 2;
+ weight = ntohs(*((unsigned short *) *reader));
+ *reader += 2;
+ port = ntohs(*((unsigned short *) *reader));
+ *reader += 2;
+ name = read_name(reader, packet);
+ res->data = malloc(7 + strlen(name));
+ ((unsigned short *) res->data)[0] = priority;
+ ((unsigned short *) res->data)[1] = weight;
+ ((unsigned short *) res->data)[2] = port;
+ memcpy(res->data + 6, name, strlen(name) + 1);
+ free(name);
} else {
if (res->type == dns_type_txt) {
res->size--;
@@ -208,14 +226,35 @@ static struct dns_answers *get(int sock, struct sockaddr_in *a)
}
+char *dns_mx_server(void *data)
+{
+ return ((char *) data) + 2;
+}
+
int dns_mx_preference(void *data)
{
return *((unsigned short *) data);
}
-char *dns_mx_server(void *data)
+
+char *dns_srv_server(void *data)
{
- return ((char *) data) + 2;
+ return ((char *) data) + 6;
+}
+
+int dns_srv_port(void *data)
+{
+ return ((unsigned short *) data)[2];
+}
+
+int dns_srv_priority(void *data)
+{
+ return *((unsigned short *) data);
+}
+
+int dns_srv_weight(void *data)
+{
+ return ((unsigned short *) data)[1];
}