diff --git a/src/seeder/dns.h b/src/seeder/dns.h --- a/src/seeder/dns.h +++ b/src/seeder/dns.h @@ -8,6 +8,13 @@ #include #include +const static uint8_t DNS_NO_ERROR = 0; +const static uint8_t DNS_FORMAT_ERROR = 1; +const static uint8_t DNS_SERVER_FAILURE = 2; +const static uint8_t DNS_NAME_ERROR = 3; +const static uint8_t DNS_NOT_IMPLEMENTED = 4; +const static uint8_t DNS_REFUSED = 5; + struct addr_t { int v; union { diff --git a/src/seeder/dns.cpp b/src/seeder/dns.cpp --- a/src/seeder/dns.cpp +++ b/src/seeder/dns.cpp @@ -349,7 +349,7 @@ static ssize_t dnshandle(dns_opt_t *opt, const uint8_t *inbuf, size_t insize, uint8_t *outbuf) { - int error = 0; + int error = DNS_NO_ERROR; if (insize < 12) { // DNS header return -1; @@ -371,14 +371,14 @@ // check qr if (inbuf[2] & 128) { /* fprintf(stdout, "Got response?\n"); */ - error = 1; + error = DNS_FORMAT_ERROR; goto error; } // check opcode if (((inbuf[2] & 120) >> 3) != 0) { /* fprintf(stdout, "Opcode nonzero?\n"); */ - error = 4; + error = DNS_NOT_IMPLEMENTED; goto error; } @@ -390,13 +390,13 @@ nquestion = (inbuf[4] << 8) + inbuf[5]; if (nquestion == 0) { /* fprintf(stdout, "No questions?\n"); */ - error = 0; + error = DNS_NO_ERROR; goto error; } if (nquestion > 1) { /* fprintf(stdout, "Multiple questions %i?\n", nquestion); */ - error = 4; + error = DNS_NOT_IMPLEMENTED; goto error; } @@ -407,12 +407,12 @@ int offset = inpos - inbuf; int ret = parse_name(&inpos, inend, inbuf, name, 256); if (ret == -1) { - error = 1; + error = DNS_FORMAT_ERROR; goto error; } if (ret == -2) { - error = 5; + error = DNS_REFUSED; goto error; } @@ -420,12 +420,12 @@ if (strcasecmp(name, opt->host) && (namel < hostl + 2 || name[namel - hostl - 1] != '.' || strcasecmp(name + namel - hostl, opt->host))) { - error = 5; + error = DNS_REFUSED; goto error; } if (inend - inpos < 4) { - error = 1; + error = DNS_FORMAT_ERROR; goto error; }