Smart Home firewall
Profile-based Smart Home firewall
Functions
dns_map.c 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 "dns_map.h"
Include dependency graph for dns_map.c:

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

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. 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)

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

◆ 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