Skip to content
Extraits de code Groupes Projets
Valider 30cb2c73 rédigé par François De Keersmaeker's avatar François De Keersmaeker
Parcourir les fichiers

Updated DNS send & receive

parent 22912b37
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Subproject commit ac24792f4f020c816d50b96f2c5e2325d02e75ad Subproject commit 4e8157dae43eef16842182b09d941c1ed3fb0c46
...@@ -28,6 +28,8 @@ void usage(char* prog) { ...@@ -28,6 +28,8 @@ void usage(char* prog) {
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// Initialize variables
int ret;
char *dns_server_ip = "8.8.8.8"; // Default DNS server: Google Quad8 char *dns_server_ip = "8.8.8.8"; // Default DNS server: Google Quad8
// Setup SIGINT handler // Setup SIGINT handler
...@@ -71,8 +73,11 @@ int main(int argc, char *argv[]) { ...@@ -71,8 +73,11 @@ int main(int argc, char *argv[]) {
/* GLOBAL STRUCTURES INITIALIZATION */ /* GLOBAL STRUCTURES INITIALIZATION */
{% if "dns" in custom_parsers or "mdns" in custom_parsers or domain_names|length > 0 %} {% if "dns" in custom_parsers or "mdns" in custom_parsers or domain_names|length > 0 %}
// Initialize DNS map // Initialize variables for DNS
dns_map = dns_map_create(); dns_map = dns_map_create();
dns_message_t dns_response;
ip_list_t ip_list;
dns_entry_t *dns_entry;
{% if domain_names|length > 0 %} {% if domain_names|length > 0 %}
// Open socket for DNS // Open socket for DNS
...@@ -91,23 +96,19 @@ int main(int argc, char *argv[]) { ...@@ -91,23 +96,19 @@ int main(int argc, char *argv[]) {
{% for name in domain_names %} {% for name in domain_names %}
// Add addresses for domain {{name}} to DNS map // Add addresses for domain {{name}} to DNS map
dns_send_query("{{name}}", sockfd, &server_addr); ret = dns_send_query("{{name}}", sockfd, &server_addr);
{% if loop.index == 1 %} if (ret == 0) {
dns_message_t dns_response = dns_receive_response(sockfd, &server_addr); ret = dns_receive_response(sockfd, &server_addr, &dns_response);
ip_list_t ip_list = dns_get_ip_from_name(dns_response.answers, dns_response.header.ancount, "{{name}}"); if (ret == 0) {
{% else %} ip_list = dns_get_ip_from_name(dns_response.answers, dns_response.header.ancount, "{{name}}");
dns_response = dns_receive_response(sockfd, &server_addr); dns_map_add(dns_map, "{{name}}", ip_list);
ip_list = dns_get_ip_from_name(dns_response.answers, dns_response.header.ancount, "{{name}}"); #ifdef DEBUG
{% endif %} // Check DNS map has been correctly updated
dns_map_add(dns_map, "{{name}}", ip_list); dns_entry = dns_map_get(dns_map, "{{name}}");
dns_entry_print(dns_entry);
// Check DNS map has been correctly updated #endif /* DEBUG */
{% if loop.index == 1 %} }
dns_entry_t *dns_entry = dns_map_get(dns_map, "{{name}}"); }
{% else %}
dns_entry = dns_map_get(dns_map, "{{name}}");
{% endif %}
dns_entry_print(dns_entry);
{% endfor %} {% endfor %}
{% endif %} {% endif %}
...@@ -118,7 +119,6 @@ int main(int argc, char *argv[]) { ...@@ -118,7 +119,6 @@ int main(int argc, char *argv[]) {
/* NFQUEUE THREADS LAUNCH */ /* NFQUEUE THREADS LAUNCH */
// Create threads // Create threads
int ret = 0; // Return code for pthread_create function
uint8_t i = 0; uint8_t i = 0;
{% for nfqueue in nfqueues if nfqueue.queue_num >= 0 %} {% for nfqueue in nfqueues if nfqueue.queue_num >= 0 %}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter