mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-23 03:49:23 +00:00
Fixed DNS TXT parsing
This commit is contained in:
parent
4fa344a0f7
commit
3c7fcf65a9
2 changed files with 15 additions and 16 deletions
|
@ -238,20 +238,17 @@ int main(int argc, char* argv[])
|
||||||
for (int rrnum = 0, n = ns_msg_count(handle, ns_s_an); rrnum < n; ++rrnum) {
|
for (int rrnum = 0, n = ns_msg_count(handle, ns_s_an); rrnum < n; ++rrnum) {
|
||||||
ns_rr rr;
|
ns_rr rr;
|
||||||
if ((ns_parserr(&handle, ns_s_an, rrnum, &rr) == 0) && (ns_rr_type(rr) == ns_t_txt)) {
|
if ((ns_parserr(&handle, ns_s_an, rrnum, &rr) == 0) && (ns_rr_type(rr) == ns_t_txt)) {
|
||||||
const uint8_t* data = ns_rr_rdata(rr);
|
for (const uint8_t* data = ns_rr_rdata(rr), *e = data + ns_rr_rdlen(rr); data < e;) {
|
||||||
|
const int k = *(data++);
|
||||||
int len = ns_rr_rdlen(rr) - 1;
|
if (k && (data + k <= e)) {
|
||||||
if (len > data[0]) len = data[0];
|
|
||||||
|
|
||||||
if (len <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
memcpy(buf, data + 1, len);
|
memcpy(buf, data, k);
|
||||||
buf[len] = 0;
|
buf[k] = 0;
|
||||||
puts(buf);
|
puts(buf);
|
||||||
}
|
}
|
||||||
|
data += k;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
10
src/util.cpp
10
src/util.cpp
|
@ -517,10 +517,12 @@ bool get_dns_txt_records_base(const std::string& host, Callback<void, const char
|
||||||
for (int rrnum = 0, n = ns_msg_count(handle, ns_s_an); rrnum < n; ++rrnum) {
|
for (int rrnum = 0, n = ns_msg_count(handle, ns_s_an); rrnum < n; ++rrnum) {
|
||||||
ns_rr rr;
|
ns_rr rr;
|
||||||
if ((ns_parserr(&handle, ns_s_an, rrnum, &rr) == 0) && (ns_rr_type(rr) == ns_t_txt)) {
|
if ((ns_parserr(&handle, ns_s_an, rrnum, &rr) == 0) && (ns_rr_type(rr) == ns_t_txt)) {
|
||||||
const uint8_t* s = ns_rr_rdata(rr);
|
for (const uint8_t* data = ns_rr_rdata(rr), *e = data + ns_rr_rdlen(rr); data < e;) {
|
||||||
const int n = std::min<int>(ns_rr_rdlen(rr) - 1, *s);
|
const size_t k = *(data++);
|
||||||
if (n > 0) {
|
if (k && (data + k <= e)) {
|
||||||
callback(reinterpret_cast<const char*>(s + 1), static_cast<size_t>(n));
|
callback(reinterpret_cast<const char*>(data), k);
|
||||||
|
}
|
||||||
|
data += k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue