… | |
… | |
25 | |
25 | |
26 | // dns processing is EXTREMELY ugly. For obvious(?) reasons. |
26 | // dns processing is EXTREMELY ugly. For obvious(?) reasons. |
27 | // it's a hack, use only in emergency situations please. |
27 | // it's a hack, use only in emergency situations please. |
28 | |
28 | |
29 | #include <cstring> |
29 | #include <cstring> |
|
|
30 | #include <cassert> |
30 | |
31 | |
31 | #include <sys/types.h> |
32 | #include <sys/types.h> |
32 | #include <sys/socket.h> |
33 | #include <sys/socket.h> |
33 | #include <sys/wait.h> |
34 | #include <sys/wait.h> |
34 | #include <sys/uio.h> |
35 | #include <sys/uio.h> |
… | |
… | |
622 | |
623 | |
623 | pkt->flags = htons (DEFAULT_CLIENT_FLAGS); |
624 | pkt->flags = htons (DEFAULT_CLIENT_FLAGS); |
624 | pkt->qdcount = htons (1); |
625 | pkt->qdcount = htons (1); |
625 | |
626 | |
626 | int offs = 6*2; |
627 | int offs = 6*2; |
627 | int dlen = MAX_DOMAIN_SIZE - (strlen (THISNODE->domain) + 2); |
628 | int dlen = MAX_DOMAIN_SIZE - (strlen (dns->c->conf->domain) + 2); |
628 | // MAX_DOMAIN_SIZE is technically 255, but bind doesn't compress responses well, |
629 | // MAX_DOMAIN_SIZE is technically 255, but bind doesn't compress responses well, |
629 | // so we need to have space for 2*MAX_DOMAIN_SIZE + header + extra |
630 | // so we need to have space for 2*MAX_DOMAIN_SIZE + header + extra |
630 | |
631 | |
631 | char enc[256], *encp = enc; |
632 | char enc[256], *encp = enc; |
632 | encode_header (enc, THISNODE->id, seqno); |
633 | encode_header (enc, THISNODE->id, seqno); |
… | |
… | |
650 | encp += lbllen; |
651 | encp += lbllen; |
651 | |
652 | |
652 | enclen -= lbllen; |
653 | enclen -= lbllen; |
653 | } |
654 | } |
654 | |
655 | |
655 | append_domain (*pkt, offs, THISNODE->domain); |
656 | append_domain (*pkt, offs, dns->c->conf->domain); |
656 | |
657 | |
657 | (*pkt)[offs++] = 0; |
658 | (*pkt)[offs++] = 0; |
658 | (*pkt)[offs++] = RR_TYPE_ANY >> 8; (*pkt)[offs++] = RR_TYPE_ANY; |
659 | (*pkt)[offs++] = RR_TYPE_ANY >> 8; (*pkt)[offs++] = RR_TYPE_ANY; |
659 | (*pkt)[offs++] = RR_CLASS_IN >> 8; (*pkt)[offs++] = RR_CLASS_IN; |
660 | (*pkt)[offs++] = RR_CLASS_IN >> 8; (*pkt)[offs++] = RR_CLASS_IN; |
660 | |
661 | |
… | |
… | |
676 | |
677 | |
677 | assert (elen <= MAX_LBL_SIZE); |
678 | assert (elen <= MAX_LBL_SIZE); |
678 | |
679 | |
679 | (*pkt)[offs] = elen; |
680 | (*pkt)[offs] = elen; |
680 | offs += elen + 1; |
681 | offs += elen + 1; |
681 | append_domain (*pkt, offs, THISNODE->domain); |
682 | append_domain (*pkt, offs, dns->c->conf->domain); |
682 | |
683 | |
683 | (*pkt)[offs++] = 0; |
684 | (*pkt)[offs++] = 0; |
684 | (*pkt)[offs++] = RR_TYPE_A >> 8; (*pkt)[offs++] = RR_TYPE_A; |
685 | (*pkt)[offs++] = RR_TYPE_A >> 8; (*pkt)[offs++] = RR_TYPE_A; |
685 | (*pkt)[offs++] = RR_CLASS_IN >> 8; (*pkt)[offs++] = RR_CLASS_IN; |
686 | (*pkt)[offs++] = RR_CLASS_IN >> 8; (*pkt)[offs++] = RR_CLASS_IN; |
686 | |
687 | |