]> git.meshlink.io Git - catta/blobdiff - iface.c
make the daemon response to queries
[catta] / iface.c
diff --git a/iface.c b/iface.c
index 8c31d8f32253aa26bd7792696bb54de74baef660..9acef47806d1aa9ea6dbc79e7a93069e43e44a5f 100644 (file)
--- a/iface.c
+++ b/iface.c
@@ -344,20 +344,10 @@ int flx_address_is_relevant(flxInterfaceAddress *a) {
         flx_interface_is_relevant(a->interface);
 }
 
-void flx_interface_send_query(flxInterface *i, guchar protocol, flxKey *k) {
-    flxDnsPacket *p;
+void flx_interface_send_packet(flxInterface *i, guchar protocol, flxDnsPacket *p) {
     g_assert(i);
-    g_assert(k);
-
-    p = flx_dns_packet_new();
-    flx_dns_packet_set_field(p, DNS_FIELD_FLAGS, DNS_FLAGS(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
-
-    flx_dns_packet_append_name(p, k->name);
-    flx_dns_packet_append_uint16(p, k->type);
-    flx_dns_packet_append_uint16(p, k->class);
-
-    flx_dns_packet_set_field(p, DNS_FIELD_QDCOUNT, 1);
-
+    g_assert(p);
+    
     if ((protocol == AF_INET || protocol == AF_UNSPEC) && i->n_ipv4_addrs > 0 && flx_interface_is_relevant(i)) {
         g_message("sending on '%s':IPv4", i->name);
         flx_send_dns_packet_ipv4(i->monitor->server->fd_ipv4, i->index, p);
@@ -367,27 +357,36 @@ void flx_interface_send_query(flxInterface *i, guchar protocol, flxKey *k) {
         g_message("sending on '%s':IPv6", i->name);
         flx_send_dns_packet_ipv6(i->monitor->server->fd_ipv6, i->index, p);
     }
+}
+
+void flx_interface_send_query(flxInterface *i, guchar protocol, flxKey *k) {
+    flxDnsPacket *p;
     
+    g_assert(i);
+    g_assert(k);
+
+    p = flx_dns_packet_new();
+    flx_dns_packet_set_field(p, DNS_FIELD_FLAGS, DNS_FLAGS(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
+    flx_dns_packet_append_key(p, k);
+    flx_dns_packet_set_field(p, DNS_FIELD_QDCOUNT, 1);
+    flx_interface_send_packet(i, protocol, p);
     flx_dns_packet_free(p);
 }
 
-void flx_interface_send_response(flxinterface *i, guchar protocol, flxRecord *rr) {
-    flxDnsPacket+p;
+void flx_interface_send_response(flxInterface *i, guchar protocol, flxRecord *rr) {
+    flxDnsPacket *p;
     
     g_assert(i);
     g_assert(rr);
 
     p = flx_dns_packet_new();
     flx_dns_packet_set_field(p, DNS_FIELD_FLAGS, DNS_FLAGS(1, 0, 0, 0, 0, 0, 0, 0, 0, 0));
-
-    flx_dns_packet_append_name(p, rr->key->name);
-    flx_dns_packet_append_uint16(p, rr->key->type);
-    flx_dns_packet_append_uint16(p, rr->key->class);
-    flx_dns_packet_append_uint16
+    flx_dns_packet_append_record(p, rr, FALSE);
+    flx_dns_packet_set_field(p, DNS_FIELD_ANCOUNT, 1);
+    flx_interface_send_packet(i, protocol, p);
+    flx_dns_packet_free(p);
 }
 
-
-
 void flx_dump_caches(flxServer *s, FILE *f) {
     flxInterface *i;
     g_assert(s);