Implementation of a DNS domain name to IP addresses mapping, using Joshua J Baker's hashmap.c (https://github.com/tidwall/hashmap.c)
More...
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "hashmap.h"
#include "packet_utils.h"
Go to the source code of this file.
|
#define | DNS_MAP_INIT_SIZE 0 |
|
Implementation of a DNS domain name to IP addresses mapping, using Joshua J Baker's hashmap.c (https://github.com/tidwall/hashmap.c)
- Date
- 2022-09-06
- Copyright
- Copyright (c) 2022
◆ dns_entry_t
DNS table entry: mapping between domain name and a list of IP addresses.
◆ dns_map_t
Alias for the hashmap structure.
◆ ip_list_t
◆ dns_entry_contains()
Checks if a dns_entry_t structure contains a given IP address.
- Parameters
-
dns_entry | pointer to the DNS entry to process |
ip_address | IP address to check the presence of |
- Returns
- true if the IP address is present in the DNS entry, false otherwise
◆ dns_entry_print()
Print a DNS table entry.
- Parameters
-
◆ dns_map_add()
Add IP addresses corresponding to a given domain name in the DNS table. If the domain name was already present, its IP addresses will be replaced by the new ones.
- Parameters
-
table | the DNS table to add the entry to |
domain_name | the domain name of the entry |
ip_list | an ip_list_t structure containing the list of IP addresses |
◆ dns_map_create()
Create a new DNS table.
- Returns
- the newly created DNS table
Create a new DNS table. Uses random seeds for the hash function.
- Returns
- the newly created DNS table, or NULL if creation failed
◆ dns_map_free()
Destroy (free) a DNS table.
- Parameters
-
table | the DNS table to free |
Free the memory allocated for a DNS table.
- Parameters
-
table | the DNS table to free |
◆ dns_map_get()
Retrieve the IP addresses corresponding to a given domain name in the DNS table.
- Parameters
-
table | the DNS table to retrieve the entry from |
domain_name | the domain name of the entry to retrieve |
- Returns
- a pointer to a dns_entry structure containing the IP addresses corresponding to the domain name, or NULL if the domain name was not found in the DNS table
◆ dns_map_pop()
Retrieve the IP addresses corresponding to a given domain name, and remove the domain name from the DNS table.
- Parameters
-
table | the DNS table to retrieve the entry from |
domain_name | the domain name of the entry to retrieve |
- Returns
- a pointer to a dns_entry structure containing the IP addresses corresponding to the domain name, or NULL if the domain name was not found in the DNS table
◆ dns_map_remove()
void dns_map_remove |
( |
dns_map_t * |
table, |
|
|
char * |
domain_name |
|
) |
| |
Remove a domain name (and its corresponding IP addresses) from the DNS table.
- Parameters
-
table | the DNS table to remove the entry from |
domain_name | the domain name of the entry to remove |
Remove a domain name, and its corresponding IP addresses, from the DNS table.
- Parameters
-
table | the DNS table to remove the entry from |
domain_name | the domain name of the entry to remove |
◆ ip_list_init()
Initialize an ip_list_t structure.
Creates an empty list of IP addresses. The ip_count
field is set to 0, and the ip_addresses
field is set to NULL.
- Returns
- ip_list_t newly initialized structure