Example #1
0
//we'd better send the right domain and id
int
send_tc_to_client(mbuf_type *mbuf)
{
    uchar *itor = mbuf->buf;
    dnsheader *hdr = (dnsheader *) itor;
    qdns *qd = NULL;
    if (mbuf->td == NULL)
        return -1;
    hdr->id = mbuf->id;
    hdr->flags = 0;
    hdr->flags = SET_QR_R(hdr->flags);
    hdr->flags = SET_RA(hdr->flags);
    hdr->flags = SET_TC(hdr->flags);
    hdr->flags = htons(hdr->flags);
    hdr->qdcount = htons(1);
    hdr->ancount = hdr->nscount = hdr->arcount = htons(0);
    itor += sizeof(dnsheader);
    memcpy(itor, mbuf->td, mbuf->dlen);
    itor = itor + mbuf->dlen;
    qd = (qdns *) itor;
    qd->type = htons(mbuf->qtype);
    qd->dclass = htons(CLASS_IN);
    itor += sizeof(qdns);
    mbuf->buflen = itor - mbuf->buf;
    udp_write_info(mbuf, 0);
    return 0;
}
Example #2
0
uchar *fill_header_in_msg(struct setheader *sh)
{
 uchar llen = 0;
 uchar *itor = sh->itor;
 dnsheader *hdr = (dnsheader*)(sh->itor);
 qdns *qd;
 int i,dlen;
 hdr->id = sh->id;
 hdr->flags = 0;
 hdr->flags = SET_QR_R(hdr->flags);
 hdr->flags = SET_RA(hdr->flags);
 //hdr->flags = SET_ERROR(hdr->flags,mf->ed);
 hdr->flags = htons(hdr->flags);
 hdr->qdcount = htons(1);
 hdr->ancount = htons(sh->an);
 hdr->nscount = htons(sh->ns);
 hdr->arcount = htons(0);
 itor += sizeof(dnsheader);
 dlen = strlen(sh->od) + 1;
 memcpy(itor,sh->od,dlen);
 itor = itor + dlen;
 qd = (qdns*)itor;
 qd->type = htons(sh->type);
 qd->dclass = htons(CLASS_IN);
 itor += sizeof(qdns);
 return itor;
}
Example #3
0
//we'd better send the right domain and id
int send_tc_to_client(uchar *td,struct sockinfo *si,ushort cid)
{
 uchar buffer[255] = {0},*itor = buffer;
 dnsheader *hdr = (dnsheader*)itor;
 qdns *qd = NULL;
 int dlen = -1;
 if(td == NULL || si == NULL)
	return -1;
 hdr->id = cid;
 hdr->flags = 0;
 hdr->flags = SET_QR_R(hdr->flags);
 hdr->flags = SET_RA(hdr->flags);
 hdr->flags = SET_TC(hdr->flags);
 hdr->flags = htons(hdr->flags);
 hdr->qdcount = htons(1);
 hdr->ancount = hdr->nscount = hdr->arcount = htons(0);
 itor += sizeof(dnsheader);
 dlen = strlen(td + 1);
 memcpy(itor,td + 1,dlen + 1);
 itor = itor + dlen + 1;
 qd = (qdns*)itor;
 qd->type = htons(td[0]);
 qd->dclass = htons(CLASS_IN);
 itor += sizeof(qdns);
 si->buf = buffer;
 si->buflen = itor - buffer;
 udp_write_info(si,0);
 return 0;
}
Example #4
0
int check_out_msg(ushort cid,uchar *buf,int len)
{
 dnsheader *hdr = (dnsheader*)buf;
 hdr->id = cid;
 hdr->flags = 0;
 hdr->flags = htons(SET_QR_R(hdr->flags));
 return 0;
}
Example #5
0
uchar *
fill_header_in_msg(struct setheader * sh)
{
    uchar *itor = sh->itor;
    dnsheader *hdr = (dnsheader *) (sh->itor);
    qdns *qd;
    hdr->flags = 0;
    hdr->flags = SET_QR_R(hdr->flags);
    hdr->flags = SET_RA(hdr->flags);
    hdr->flags = DNS_GET16(hdr->flags);
    hdr->ancount = DNS_GET16(sh->an);
    hdr->nscount = DNS_GET16(sh->ns);
    hdr->arcount = 0; //DNS_GET16(0);
    itor += sizeof(dnsheader);
    itor = itor + sh->dlen;
    qd = (qdns *) itor;
    qd->type = DNS_GET16(sh->type);
    qd->dclass = DNS_GET16(CLASS_IN);
    itor += sizeof(qdns);
    return itor;
}