mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-23 18:15:13 +00:00
dns: improve code style
Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
parent
4591cafd27
commit
119d1b2da1
32
src/dns.c
32
src/dns.c
@ -49,8 +49,8 @@ int dnsc_use_edns0 = 1;
|
||||
|
||||
#define CHECKLEN(x) if (buflen < (x) + (unsigned)(p-buf)) return 0
|
||||
|
||||
int
|
||||
dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, const char *data, size_t datalen)
|
||||
int dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr,
|
||||
const char *data, size_t datalen)
|
||||
{
|
||||
HEADER *header;
|
||||
short name;
|
||||
@ -91,7 +91,8 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, const char *data,
|
||||
/* Answer section */
|
||||
|
||||
if (q->type == T_CNAME || q->type == T_A) {
|
||||
/* data is expected to be like "Hblabla.host.name.com\0" */
|
||||
/* data is expected to be like
|
||||
* "Hblabla.host.name.com\0" */
|
||||
|
||||
char *startp;
|
||||
int namelen;
|
||||
@ -177,7 +178,6 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, const char *data,
|
||||
ancnt = 1;
|
||||
} else {
|
||||
/* NULL has raw binary data */
|
||||
|
||||
CHECKLEN(10);
|
||||
putshort(&p, name);
|
||||
putshort(&p, q->type);
|
||||
@ -227,10 +227,10 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, const char *data,
|
||||
return len;
|
||||
}
|
||||
|
||||
int
|
||||
dns_encode_ns_response(char *buf, size_t buflen, struct query *q, char *topdomain)
|
||||
/* Only used when iodined gets an NS type query */
|
||||
/* Mostly same as dns_encode_a_response() below */
|
||||
int dns_encode_ns_response(char *buf, size_t buflen, struct query *q,
|
||||
char *topdomain)
|
||||
{
|
||||
HEADER *header;
|
||||
int len;
|
||||
@ -319,10 +319,9 @@ dns_encode_ns_response(char *buf, size_t buflen, struct query *q, char *topdomai
|
||||
return len;
|
||||
}
|
||||
|
||||
int
|
||||
dns_encode_a_response(char *buf, size_t buflen, struct query *q)
|
||||
/* Only used when iodined gets an A type query for ns.topdomain or www.topdomain */
|
||||
/* Mostly same as dns_encode_ns_response() above */
|
||||
/* Only used when iodined gets an A type query for ns.topdomain or
|
||||
* www.topdomain . Mostly same as dns_encode_ns_response() above */
|
||||
int dns_encode_a_response(char *buf, size_t buflen, struct query *q)
|
||||
{
|
||||
HEADER *header;
|
||||
int len;
|
||||
@ -381,8 +380,7 @@ dns_encode_a_response(char *buf, size_t buflen, struct query *q)
|
||||
|
||||
#undef CHECKLEN
|
||||
|
||||
unsigned short
|
||||
dns_get_id(char *packet, size_t packetlen)
|
||||
unsigned short dns_get_id(char *packet, size_t packetlen)
|
||||
{
|
||||
HEADER *header;
|
||||
header = (HEADER*)packet;
|
||||
@ -395,8 +393,8 @@ dns_get_id(char *packet, size_t packetlen)
|
||||
|
||||
#define CHECKLEN(x) if (packetlen < (x) + (unsigned)(data-packet)) return 0
|
||||
|
||||
int
|
||||
dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, size_t packetlen)
|
||||
int dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet,
|
||||
size_t packetlen)
|
||||
{
|
||||
char name[QUERY_NAME_SIZE];
|
||||
char rdata[4*1024];
|
||||
@ -536,7 +534,8 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||
readname(packet, packetlen, &data,
|
||||
names[pref / 10 - 1],
|
||||
QUERY_NAME_SIZE - 1);
|
||||
names[pref / 10 - 1][QUERY_NAME_SIZE-1] = '\0';
|
||||
names[pref / 10 - 1]
|
||||
[QUERY_NAME_SIZE-1] = '\0';
|
||||
}
|
||||
|
||||
/* always trust rlen, not name encoding */
|
||||
@ -569,7 +568,8 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||
readlong(packet, &data, &ttl);
|
||||
readshort(packet, &data, &rlen);
|
||||
|
||||
rv = readtxtbin(packet, &data, rlen, rdata, sizeof(rdata));
|
||||
rv = readtxtbin(packet, &data, rlen, rdata,
|
||||
sizeof(rdata));
|
||||
if (rv >= 1) {
|
||||
rv = MIN(rv, buflen);
|
||||
memcpy(buf, rdata, rv);
|
||||
|
Loading…
Reference in New Issue
Block a user