coap_address.[ch]: Add coap_resolve_address_info() and coap_free_address_info()

coap_resolve_address_info() emulates getaddrinfo() but has the extensibility to
support other socket types based on the address to resolve.

coap-client, coap-server and lwip/client updated to use this new functionality.

coap_address(3) updated to include the new functions.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2023-02-03 09:53:24 +00:00
1 parent 556a8ac213
commit 0a5d80ad66
12 files changed
+480 -260

No files matched your search

+37 -1
View File
@@ -23,6 +23,8 @@
#include <sys/types.h>
#include "libcoap.h"
#include "coap3/pdu.h"
#if defined(WITH_LWIP)
#include <lwip/ip_addr.h>
@@ -92,7 +94,7 @@ coap_address_set_port(coap_address_t *addr, uint16_t port) {
#else /* WITH_LWIP || WITH_CONTIKI */
/** multi-purpose address abstraction */
/** Multi-purpose address abstraction */
typedef struct coap_address_t {
socklen_t size; /**< size of addr */
union {
@@ -137,6 +139,40 @@ _coap_address_isany_impl(const coap_address_t *a) {
}
#endif /* WITH_LWIP || WITH_CONTIKI */
/** Resolved addresses information */
typedef struct coap_addr_info_t {
struct coap_addr_info_t *next; /**< Next entry in the chain */
coap_uri_scheme_t scheme; /**< CoAP scheme to use */
coap_address_t addr; /**< The address to connect / bind to */
} coap_addr_info_t;
/**
* Resolve the specified @p server into a set of coap_address_t that can
* be used to bind() or connect() to.
*
* @param server The Address to resolve.
* @param port The unsecured protocol port to use.
* @param secure_port The secured protocol port to use.
* @param ai_hints_flags AI_* Hint flags to use for internal getaddrinfo().
* @param scheme_hint_bits Which schemes to return information for. One or
* more of COAP_URI_SCHEME_*_BIT or'd together.
*
* @return One or more linked sets of coap_addr_info_t or @c NULL if error.
*/
coap_addr_info_t *coap_resolve_address_info(const coap_str_const_t *server,
uint16_t port,
uint16_t secure_port,
int ai_hints_flags,
int scheme_hint_bits);
/**
* Free off the one or more linked sets of coap_addr_info_t returned from
* coap_resolve_address_info().
*
* @param info_list The set of coap_addr_info_t to free off.
*/
void coap_free_address_info(coap_addr_info_t *info_list);
/**
* Resets the given coap_address_t object @p addr to its default values. In
* particular, the member size must be initialized to the available size for
+12
View File
@@ -38,6 +38,18 @@ typedef enum coap_uri_scheme_t {
/** This mask can be used to check if a parsed URI scheme is secure. */
#define COAP_URI_SCHEME_SECURE_MASK 0x01
#define COAP_URI_SCHEME_COAP_BIT (1 << COAP_URI_SCHEME_COAP)
#define COAP_URI_SCHEME_COAPS_BIT (1 << COAP_URI_SCHEME_COAPS)
#define COAP_URI_SCHEME_COAP_TCP_BIT (1 << COAP_URI_SCHEME_COAP_TCP)
#define COAP_URI_SCHEME_COAPS_TCP_BIT (1 << COAP_URI_SCHEME_COAPS_TCP)
#define COAP_URI_SCHEME_HTTP_BIT (1 << COAP_URI_SCHEME_HTTP)
#define COAP_URI_SCHEME_HTTPS_BIT (1 << COAP_URI_SCHEME_HTTPS)
#define COAP_URI_SCHEME_ALL_COAP_BITS (COAP_URI_SCHEME_COAP_BIT | \
COAP_URI_SCHEME_COAPS_BIT | \
COAP_URI_SCHEME_COAP_TCP_BIT | \
COAP_URI_SCHEME_COAPS_TCP_BIT)
/**
* Representation of parsed URI. Components may be filled from a string with
* coap_split_uri() or coap_split_proxy_uri() and can be used as input for