mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:47:44 +00:00
LookupServer: Clang-Format
This commit is contained in:
parent
59c37363b6
commit
4f62176c3e
1 changed files with 22 additions and 20 deletions
|
@ -27,7 +27,7 @@
|
||||||
static Vector<String> lookup(const String& hostname, bool& did_timeout, const String& DNS_IP, unsigned short record_type);
|
static Vector<String> lookup(const String& hostname, bool& did_timeout, const String& DNS_IP, unsigned short record_type);
|
||||||
static String parse_dns_name(const byte*, int& offset, int max_offset);
|
static String parse_dns_name(const byte*, int& offset, int max_offset);
|
||||||
|
|
||||||
int main(int argc, char**argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
@ -185,15 +185,17 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
|
||||||
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("socket");
|
perror("socket");
|
||||||
return { };
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timeval timeout { 1, 0 };
|
struct timeval timeout {
|
||||||
|
1, 0
|
||||||
|
};
|
||||||
int rc = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
|
int rc = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror("setsockopt");
|
perror("setsockopt");
|
||||||
close(fd);
|
close(fd);
|
||||||
return { };
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr_in dst_addr;
|
struct sockaddr_in dst_addr;
|
||||||
|
@ -203,10 +205,10 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
|
||||||
dst_addr.sin_port = htons(53);
|
dst_addr.sin_port = htons(53);
|
||||||
rc = inet_pton(AF_INET, DNS_IP.characters(), &dst_addr.sin_addr);
|
rc = inet_pton(AF_INET, DNS_IP.characters(), &dst_addr.sin_addr);
|
||||||
|
|
||||||
int nsent = sendto(fd, buffer.pointer(), buffer.size(), 0,(const struct sockaddr *)&dst_addr, sizeof(dst_addr));
|
int nsent = sendto(fd, buffer.pointer(), buffer.size(), 0, (const struct sockaddr*)&dst_addr, sizeof(dst_addr));
|
||||||
if (nsent < 0) {
|
if (nsent < 0) {
|
||||||
perror("sendto");
|
perror("sendto");
|
||||||
return { };
|
return {};
|
||||||
}
|
}
|
||||||
ASSERT(nsent == buffer.size());
|
ASSERT(nsent == buffer.size());
|
||||||
|
|
||||||
|
@ -221,7 +223,7 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
|
||||||
perror("recvfrom");
|
perror("recvfrom");
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
return { };
|
return {};
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
@ -229,7 +231,7 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
|
||||||
|
|
||||||
if (nrecv < (int)sizeof(DNSPacket)) {
|
if (nrecv < (int)sizeof(DNSPacket)) {
|
||||||
dbgprintf("LookupServer: Response not big enough (%d) to be a DNS packet :(\n", nrecv);
|
dbgprintf("LookupServer: Response not big enough (%d) to be a DNS packet :(\n", nrecv);
|
||||||
return { };
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& response_header = *(DNSPacket*)(response_buffer);
|
auto& response_header = *(DNSPacket*)(response_buffer);
|
||||||
|
@ -241,15 +243,15 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
|
||||||
|
|
||||||
if (response_header.id() != request_header.id()) {
|
if (response_header.id() != request_header.id()) {
|
||||||
dbgprintf("LookupServer: ID mismatch (%u vs %u) :(\n", response_header.id(), request_header.id());
|
dbgprintf("LookupServer: ID mismatch (%u vs %u) :(\n", response_header.id(), request_header.id());
|
||||||
return { };
|
return {};
|
||||||
}
|
}
|
||||||
if (response_header.question_count() != 1) {
|
if (response_header.question_count() != 1) {
|
||||||
dbgprintf("LookupServer: Question count (%u vs %u) :(\n", response_header.question_count(), request_header.question_count());
|
dbgprintf("LookupServer: Question count (%u vs %u) :(\n", response_header.question_count(), request_header.question_count());
|
||||||
return { };
|
return {};
|
||||||
}
|
}
|
||||||
if (response_header.answer_count() < 1) {
|
if (response_header.answer_count() < 1) {
|
||||||
dbgprintf("LookupServer: Not enough answers (%u) :(\n", response_header.answer_count());
|
dbgprintf("LookupServer: Not enough answers (%u) :(\n", response_header.answer_count());
|
||||||
return { };
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue