-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sys/net/application_layer/sock_dns_mock: add module for mocking sock_dns
- Loading branch information
Showing
9 changed files
with
132 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (C) 2022 Freie Universität Berlin | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @defgroup net_dns_mock DNS defines | ||
* @ingroup net | ||
* @brief Generic DNS mock values | ||
* @{ | ||
* | ||
* @file | ||
* @brief Generic DNS mock values | ||
* | ||
* @author Hendrik van Essen <[email protected]> | ||
*/ | ||
#ifndef NET_DNS_MOCK_H | ||
#define NET_DNS_MOCK_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "net/ipv4/addr.h" | ||
#include "net/ipv6/addr.h" | ||
|
||
/** | ||
* @brief Hostname used to query when using sock_dns_mock | ||
*/ | ||
#define SOCK_DNS_MOCK_EXAMPLE_COM_HOSTNAME "example.com" | ||
|
||
/** | ||
* @brief IPv4 string related to the hostname when using sock_dns_mock | ||
* | ||
* @see @ref SOCK_DNS_MOCK_EXAMPLE_COM_HOSTNAME | ||
*/ | ||
#define SOCK_DNS_MOCK_EXAMPLE_COM_IPV4_STRING "93.184.216.34" | ||
|
||
/** | ||
* @brief IPv6 string related to the hostname when using sock_dns_mock | ||
* | ||
* @see @ref SOCK_DNS_MOCK_EXAMPLE_COM_HOSTNAME | ||
*/ | ||
#define SOCK_DNS_MOCK_EXAMPLE_COM_IPV6_STRING "2606:2800:220:1:248:1893:25c8:1946" | ||
|
||
/** | ||
* @brief ipv4_addr_t matching the IPv4 string when using sock_dns_mock | ||
* | ||
* @see @ref SOCK_DNS_MOCK_EXAMPLE_COM_IPV4_STRING | ||
*/ | ||
static const ipv4_addr_t sock_dns_mock_example_com_addr_ipv4 = { { 0x5d, 0xb8, 0xd8, 0x22 } }; | ||
|
||
/** | ||
* @brief ipv6_addr_t matching the IPv6 string when using sock_dns_mock | ||
* | ||
* @see @ref SOCK_DNS_MOCK_EXAMPLE_COM_IPV6_STRING | ||
*/ | ||
static const ipv6_addr_t sock_dns_mock_example_com_addr_ipv6 = { { | ||
0x26, 0x06, 0x28, 0x00, 0x02, 0x20, 0x00, 0x01, | ||
0x02, 0x48, 0x18, 0x93, 0x25, 0xc8, 0x19, 0x46 | ||
} | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* NET_DNS_MOCK_H */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2022 Freie Universität Berlin | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup net_sock_dns_mock | ||
* @{ | ||
* @file | ||
* @brief sock DNS mock implementation | ||
* @author Hendrik van Essen <[email protected]> | ||
* @author Benjamin Valentin <[email protected]> | ||
* @} | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <string.h> | ||
|
||
#include "net/af.h" | ||
#include "net/dns_mock.h" | ||
|
||
int sock_dns_query(const char *domain_name, void *addr_out, int family) | ||
{ | ||
if (strcmp(domain_name, SOCK_DNS_MOCK_EXAMPLE_COM_HOSTNAME)) { | ||
return -ENOTSUP; | ||
} | ||
|
||
switch (family) { | ||
case AF_INET: | ||
memcpy(addr_out, &sock_dns_mock_example_com_addr_ipv4, sizeof(ipv4_addr_t)); | ||
return sizeof(ipv4_addr_t); | ||
|
||
case AF_UNSPEC: | ||
/* fall-through */ | ||
case AF_INET6: | ||
memcpy(addr_out, &sock_dns_mock_example_com_addr_ipv6, sizeof(ipv6_addr_t)); | ||
return sizeof(ipv6_addr_t); | ||
default: | ||
return -EAFNOSUPPORT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.