Exemple #1
0
void	data2qname(t_request *req, void *output)
{
  base64_encode((char *)req->req_data, output, req->len);
  strcat(output, ".");
  strcat(output, req->domain);
#ifndef _WIN32
  DPRINTF(3, "Query is %s len %zd\n", (char *)output, strlen(output));
#else
  DPRINTF(3, "Query is %s len %d\n", (char *)output, strlen(output));
#endif
  dns_encode(output);
}
Exemple #2
0
void			*add_reply(struct dns_hdr *hdr, void *where, uint16_t type, char *encoded_data)
{
  struct rr_hdr		*rr;
  uint16_t		*compress;
  int			len;

  PUT_16(&hdr->ancount, GET_16(&hdr->ancount)+1);
  hdr->arcount = 0;
  compress = where;
  PUT_16(compress, sizeof(struct dns_hdr) | COMPRESS_FLAG);
  rr = where + sizeof(uint16_t);
  PUT_16(&rr->type, type);
  PUT_16(&rr->klass, CLASS_IN);
  PUT_16(&rr->ttl, 0);
  where = JUMP_RR_HDR(rr);
  strcpy(where, encoded_data);
  if (type == TYPE_TXT)
    dns_encode(where);
  len = strlen(where);
  PUT_16(&rr->rdlength,len);
  return (where + len);
}
Exemple #3
0
END_TEST

START_TEST(test_encode_response)
{
	char buf[512];
	char *host = "silly.host.of.iodine.code.kryo.se";
	struct query q;
	int len;
	int ret;

	len = sizeof(buf);
	memset(&buf, 0, sizeof(buf));
	memset(&q, 0, sizeof(struct query));
	strncpy(q.name, host, strlen(host));
	q.type = T_NULL;
	q.id = 1337;

	ret = dns_encode(buf, len, &q, QR_ANSWER, msgData, strlen(msgData));
	len = sizeof(answer_packet) - 1; /* Skip extra null character */

	fail_unless(strncmp(answer_packet, buf, sizeof(answer_packet)) == 0, "Did not compile expected packet");
	fail_unless(ret == len, "Bad packet length: %d, expected %d", ret, len);
}