Skip to content

Commit

Permalink
Finish up
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasssadar committed Nov 16, 2023
1 parent d2a1625 commit 9bbed17
Show file tree
Hide file tree
Showing 14 changed files with 790 additions and 892 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.0)
set(SRCS
"src/rbdns.cpp"
"src/rbjson.cpp"
"src/rbprotocol.cpp"
"src/rbprotocoludp.cpp"
"src/rbprotocolws.cpp"
"src/rbtcp.cpp"
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"maintainer": true
}
],
"version": "11.3.1",
"version": "12.0.0",
"frameworks": ["espidf", "arduino"],
"platforms": "espressif32"
}
17 changes: 12 additions & 5 deletions src/rbdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,18 @@ ssize_t DnsServer::receivePacket(std::vector<uint8_t>& buff, struct sockaddr_in
ssize_t msg_size;

while(true) {
msg_size = recvfrom(m_socket, (void*)buff.data(), buff.size(), MSG_PEEK, NULL, NULL);
msg_size = recvfrom(m_socket, (void*)buff.data(), buff.size(), MSG_PEEK | MSG_DONTWAIT, NULL, NULL);
if (msg_size < 0) {
const auto err = errno;
if (err == EBADF)
if (err == EAGAIN) {
vTaskDelay(pdMS_TO_TICKS(30));
continue;
}

if (err == EBADF) {
return -EBADF;
}

ESP_LOGE(TAG, "error in recvfrom: %d %s!", err, strerror(err));
return -1;
}
Expand Down Expand Up @@ -169,7 +176,7 @@ uint8_t *DnsServer::parseDnsName(uint8_t *src_data, size_t maxlen, std::string&
ssize_t DnsServer::processDnsQuestion(std::vector<uint8_t>& buff, ssize_t req_size) {
dns_header_t *header = (dns_header_t *)buff.data();

ESP_LOGE(TAG, "DNS query with header id: 0x%X, flags: 0x%X, qd_count: %d",
ESP_LOGD(TAG, "DNS query with header id: 0x%X, flags: 0x%X, qd_count: %d",
ntohs(header->id), ntohs(header->flags), ntohs(header->qd_count));

// Not a standard query
Expand Down Expand Up @@ -213,7 +220,7 @@ ssize_t DnsServer::processDnsQuestion(std::vector<uint8_t>& buff, ssize_t req_si
uint16_t qd_type = ntohs(question->type);
uint16_t qd_class = ntohs(question->clazz);

ESP_LOGE(TAG, "Received type: %d | Class: %d | Question for: %s", qd_type, qd_class, hostname.c_str());
ESP_LOGD(TAG, "Received type: %d | Class: %d | Question for: %s", qd_type, qd_class, hostname.c_str());

if (qd_type != QD_TYPE_A) {
cur_question_ptr = name_end_ptr + sizeof(dns_question_t);
Expand All @@ -227,7 +234,7 @@ ssize_t DnsServer::processDnsQuestion(std::vector<uint8_t>& buff, ssize_t req_si
answer->clazz = htons(qd_class);
answer->ttl = htonl(ANS_TTL_SEC);

ESP_LOGE(TAG, "Answer with PTR offset: 0x%" PRIX16 " and IP 0x%" PRIX32, ntohs(answer->ptr_offset), cur_esp_ip);
ESP_LOGD(TAG, "Answer with PTR offset: 0x%" PRIX16 " and IP 0x%" PRIX32, ntohs(answer->ptr_offset), cur_esp_ip);

/*
TODO: add support for custom DNS entries, now it always returns ESP's IP.
Expand Down
Loading

0 comments on commit 9bbed17

Please sign in to comment.