examples: Remove references to sockaddr* structures

This means that apps need to have no knowledge of what IP support is available.

Updates coap_uri_into_options() and coap_resolve_address_info()
which have only been recently added to develop branch and are not in any
previous release.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2023-06-09 12:04:09 +01:00
1 parent d4b9a53eed
commit 21bd1df95b
19 files changed
+220 -181

No files matched your search

+23 -13
View File
@@ -29,10 +29,10 @@
#include <lwip/ip_addr.h>
typedef struct coap_address_t {
struct coap_address_t {
uint16_t port;
ip_addr_t addr;
} coap_address_t;
};
/**
* Returns the port from @p addr in host byte order.
@@ -62,10 +62,10 @@ coap_address_set_port(coap_address_t *addr, uint16_t port) {
#include "uip.h"
typedef struct coap_address_t {
struct coap_address_t {
uip_ipaddr_t addr;
uint16_t port;
} coap_address_t;
};
/**
* Returns the port from @p addr in host byte order.
@@ -92,7 +92,7 @@ coap_address_set_port(coap_address_t *addr, uint16_t port) {
#define _coap_is_mcast_impl(Address) uip_is_addr_mcast(&((Address)->addr))
#else /* WITH_LWIP || WITH_CONTIKI */
#else /* ! WITH_LWIP && ! WITH_CONTIKI */
#ifdef _WIN32
#define sa_family_t short
@@ -106,7 +106,7 @@ struct coap_sockaddr_un {
};
/** Multi-purpose address abstraction */
typedef struct coap_address_t {
struct coap_address_t {
socklen_t size; /**< size of addr */
union {
struct sockaddr sa;
@@ -114,7 +114,7 @@ typedef struct coap_address_t {
struct sockaddr_in6 sin6;
struct coap_sockaddr_un cun; /* CoAP shortened special */
} addr;
} coap_address_t;
};
/**
* Returns the port from @p addr in host byte order.
@@ -176,23 +176,33 @@ uint32_t coap_get_available_scheme_hint_bits(int have_pki_psk, int ws_check,
coap_proto_t use_unix_proto);
/**
* Resolve the specified @p server into a set of coap_address_t that can
* be used to bind() or connect() to.
* coap_resolve_type_t values
*/
typedef enum coap_resolve_type_t {
COAP_RESOLVE_TYPE_LOCAL, /**< local side of session */
COAP_RESOLVE_TYPE_REMOTE, /**< remote side of session */
} coap_resolve_type_t;
/**
* Resolve the specified @p address into a set of coap_address_t that can
* be used to bind() (local) or connect() (remote) to.
*
* @param server The Address to resolve.
* @param port The unsecured protocol port to use.
* @param address 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.
* @param type COAP_ADDRESS_TYPE_LOCAL or COAP_ADDRESS_TYPE_REMOTE
*
* @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,
coap_addr_info_t *coap_resolve_address_info(const coap_str_const_t *address,
uint16_t port,
uint16_t secure_port,
int ai_hints_flags,
int scheme_hint_bits);
int scheme_hint_bits,
coap_resolve_type_t type);
/**
* Free off the one or more linked sets of coap_addr_info_t returned from
+2
View File
@@ -29,6 +29,8 @@ struct coap_dtls_pki_t;
struct coap_str_const_t;
struct coap_string_t;
typedef struct coap_address_t coap_address_t;
/*
* typedef all the opaque structures that are defined in coap_*_internal.h
*/
+13 -7
View File
@@ -166,23 +166,29 @@ int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
/**
* Takes a coap_uri_t and then adds CoAP options into the @p optlist_chain.
* If the port is not the default port and create_port_opt is not 0, then
* the Port option is added in. Any path or query are broken down into the
* individual segment Path or Query options and added to the @p optlist_chain.
* If the port is not the default port and create_port_host_opt is not 0, then
* the Port option is added to the @p optlist_chain.
* If the dst defines an address that does not match the host in uri->host and
* is not 0, then the Host option is added to the @p optlist_chain.
* Any path or query are broken down into the individual segment Path or Query
* options and added to the @p optlist_chain.
*
* @param uri The coap_uri_t object.
* @param dst The destination, or NULL if URI_HOST not to be added.
* @param optlist_chain Where to store the chain of options.
* @param buf Scratch buffer area (needs to be bigger than
* uri->path.length and uri->query.length)
* @param buflen Size of scratch buffer.
* @param create_port_opt @c 1 if port option to be added (if non-default)
* else @c 0
* @param create_port_host_opt @c 1 if port/host option to be added
* (if non-default) else @c 0
*
* @return @c 0 on success, or < 0 on error.
*
*/
int coap_uri_into_options(coap_uri_t *uri, coap_optlist_t **optlist_chain,
int create_port_opt, uint8_t *buf, size_t buflen);
int coap_uri_into_options(const coap_uri_t *uri, const coap_address_t *dst,
coap_optlist_t **optlist_chain,
int create_port_host_opt,
uint8_t *buf, size_t buflen);
/**
* Splits the given URI path into segments. Each segment is preceded