Smart Home firewall
Profile-based Smart Home firewall
Classes | Macros | Typedefs | Functions
dns_map.h File Reference

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"
Include dependency graph for dns_map.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ip_list
 
struct  dns_entry
 

Macros

#define DNS_MAP_INIT_SIZE   0
 

Typedefs

typedef struct ip_list ip_list_t
 
typedef struct dns_entry dns_entry_t
 
typedef struct hashmap dns_map_t
 

Functions

ip_list_t ip_list_init ()
 Initialize an ip_list_t structure. More...
 
bool dns_entry_contains (dns_entry_t *dns_entry, ip_addr_t ip_address)
 Checks if a dns_entry_t structure contains a given IP address. More...
 
dns_map_tdns_map_create ()
 
void dns_map_free (dns_map_t *table)
 
void dns_map_add (dns_map_t *table, char *domain_name, ip_list_t ip_list)
 
void dns_map_remove (dns_map_t *table, char *domain_name)
 
dns_entry_tdns_map_get (dns_map_t *table, char *domain_name)
 
dns_entry_tdns_map_pop (dns_map_t *table, char *domain_name)
 
void dns_entry_print (dns_entry_t *dns_entry)
 Print a DNS table entry. More...
 

Detailed Description

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

Typedef Documentation

◆ dns_entry_t

typedef struct dns_entry dns_entry_t

DNS table entry: mapping between domain name and a list of IP addresses.

◆ dns_map_t

typedef struct hashmap dns_map_t

Alias for the hashmap structure.

◆ ip_list_t

typedef struct ip_list ip_list_t

List of IP addresses

Function Documentation

◆ dns_entry_contains()

bool dns_entry_contains ( dns_entry_t dns_entry,
ip_addr_t  ip_address 
)

Checks if a dns_entry_t structure contains a given IP address.

Parameters
dns_entrypointer to the DNS entry to process
ip_addressIP address to check the presence of
Returns
true if the IP address is present in the DNS entry, false otherwise

◆ dns_entry_print()

void dns_entry_print ( dns_entry_t dns_entry)

Print a DNS table entry.

Parameters
dns_entrythe DNS table entry to print

◆ dns_map_add()

void dns_map_add ( dns_map_t table,
char *  domain_name,
ip_list_t  ip_list 
)

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
tablethe DNS table to add the entry to
domain_namethe domain name of the entry
ip_listan ip_list_t structure containing the list of IP addresses

◆ dns_map_create()

dns_map_t* 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()

void dns_map_free ( dns_map_t table)

Destroy (free) a DNS table.

Parameters
tablethe DNS table to free

Free the memory allocated for a DNS table.

Parameters
tablethe DNS table to free

◆ dns_map_get()

dns_entry_t* dns_map_get ( dns_map_t table,
char *  domain_name 
)

Retrieve the IP addresses corresponding to a given domain name in the DNS table.

Parameters
tablethe DNS table to retrieve the entry from
domain_namethe 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()

dns_entry_t* dns_map_pop ( dns_map_t table,
char *  domain_name 
)

Retrieve the IP addresses corresponding to a given domain name, and remove the domain name from the DNS table.

Parameters
tablethe DNS table to retrieve the entry from
domain_namethe 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
tablethe DNS table to remove the entry from
domain_namethe domain name of the entry to remove

Remove a domain name, and its corresponding IP addresses, from the DNS table.

Parameters
tablethe DNS table to remove the entry from
domain_namethe domain name of the entry to remove

◆ ip_list_init()

ip_list_t 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