mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-28 01:37:15 +02:00
IDF release/v4.0 08219f3cf
This commit is contained in:
@ -12,8 +12,8 @@
|
||||
* @brief Representation of network addresses
|
||||
*/
|
||||
|
||||
#ifndef _COAP_ADDRESS_H_
|
||||
#define _COAP_ADDRESS_H_
|
||||
#ifndef COAP_ADDRESS_H_
|
||||
#define COAP_ADDRESS_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
@ -21,7 +21,8 @@
|
||||
#include <sys/types.h>
|
||||
#include "libcoap.h"
|
||||
|
||||
#ifdef WITH_LWIP
|
||||
#if defined(WITH_LWIP)
|
||||
|
||||
#include <lwip/ip_addr.h>
|
||||
|
||||
typedef struct coap_address_t {
|
||||
@ -29,19 +30,21 @@ typedef struct coap_address_t {
|
||||
ip_addr_t addr;
|
||||
} coap_address_t;
|
||||
|
||||
#define _coap_address_equals_impl(A, B) (!!ip_addr_cmp(&(A)->addr,&(B)->addr))
|
||||
#define _coap_address_equals_impl(A, B) \
|
||||
((A)->port == (B)->port \
|
||||
&& (!!ip_addr_cmp(&(A)->addr,&(B)->addr)))
|
||||
|
||||
#define _coap_address_isany_impl(A) ip_addr_isany(&(A)->addr)
|
||||
|
||||
#define _coap_is_mcast_impl(Address) ip_addr_ismulticast(&(Address)->addr)
|
||||
#endif /* WITH_LWIP */
|
||||
|
||||
#ifdef WITH_CONTIKI
|
||||
#elif defined(WITH_CONTIKI)
|
||||
|
||||
#include "uip.h"
|
||||
|
||||
typedef struct coap_address_t {
|
||||
uip_ipaddr_t addr;
|
||||
unsigned short port;
|
||||
uint16_t port;
|
||||
} coap_address_t;
|
||||
|
||||
#define _coap_address_equals_impl(A,B) \
|
||||
@ -52,15 +55,14 @@ typedef struct coap_address_t {
|
||||
#define _coap_address_isany_impl(A) 0
|
||||
|
||||
#define _coap_is_mcast_impl(Address) uip_is_addr_mcast(&((Address)->addr))
|
||||
#endif /* WITH_CONTIKI */
|
||||
|
||||
#ifdef WITH_POSIX
|
||||
/** multi-purpose address abstraction */
|
||||
#else /* WITH_LWIP || WITH_CONTIKI */
|
||||
|
||||
/** multi-purpose address abstraction */
|
||||
typedef struct coap_address_t {
|
||||
socklen_t size; /**< size of addr */
|
||||
union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_storage st;
|
||||
struct sockaddr_in sin;
|
||||
struct sockaddr_in6 sin6;
|
||||
} addr;
|
||||
@ -73,7 +75,7 @@ typedef struct coap_address_t {
|
||||
*/
|
||||
int coap_address_equals(const coap_address_t *a, const coap_address_t *b);
|
||||
|
||||
static inline int
|
||||
COAP_STATIC_INLINE int
|
||||
_coap_address_isany_impl(const coap_address_t *a) {
|
||||
/* need to compare only relevant parts of sockaddr_in6 */
|
||||
switch (a->addr.sa.sa_family) {
|
||||
@ -89,7 +91,7 @@ _coap_address_isany_impl(const coap_address_t *a) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* WITH_POSIX */
|
||||
#endif /* WITH_LWIP || WITH_CONTIKI */
|
||||
|
||||
/**
|
||||
* Resets the given coap_address_t object @p addr to its default values. In
|
||||
@ -98,23 +100,45 @@ _coap_address_isany_impl(const coap_address_t *a) {
|
||||
*
|
||||
* @param addr The coap_address_t object to initialize.
|
||||
*/
|
||||
static inline void
|
||||
COAP_STATIC_INLINE void
|
||||
coap_address_init(coap_address_t *addr) {
|
||||
assert(addr);
|
||||
memset(addr, 0, sizeof(coap_address_t));
|
||||
#ifdef WITH_POSIX
|
||||
#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
|
||||
/* lwip and Contiki have constant address sizes and doesn't need the .size part */
|
||||
addr->size = sizeof(addr->addr);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef WITH_POSIX
|
||||
/* Convenience function to copy IPv6 addresses without garbage. */
|
||||
|
||||
COAP_STATIC_INLINE void
|
||||
coap_address_copy( coap_address_t *dst, const coap_address_t *src ) {
|
||||
#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
|
||||
memcpy( dst, src, sizeof( coap_address_t ) );
|
||||
#else
|
||||
memset( dst, 0, sizeof( coap_address_t ) );
|
||||
dst->size = src->size;
|
||||
if ( src->addr.sa.sa_family == AF_INET6 ) {
|
||||
dst->addr.sin6.sin6_family = src->addr.sin6.sin6_family;
|
||||
dst->addr.sin6.sin6_addr = src->addr.sin6.sin6_addr;
|
||||
dst->addr.sin6.sin6_port = src->addr.sin6.sin6_port;
|
||||
dst->addr.sin6.sin6_scope_id = src->addr.sin6.sin6_scope_id;
|
||||
} else if ( src->addr.sa.sa_family == AF_INET ) {
|
||||
dst->addr.sin = src->addr.sin;
|
||||
} else {
|
||||
memcpy( &dst->addr, &src->addr, src->size );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(WITH_LWIP) || defined(WITH_CONTIKI)
|
||||
/**
|
||||
* Compares given address objects @p a and @p b. This function returns @c 1 if
|
||||
* addresses are equal, @c 0 otherwise. The parameters @p a and @p b must not be
|
||||
* @c NULL;
|
||||
*/
|
||||
static inline int
|
||||
COAP_STATIC_INLINE int
|
||||
coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
|
||||
assert(a); assert(b);
|
||||
return _coap_address_equals_impl(a, b);
|
||||
@ -126,27 +150,28 @@ coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
|
||||
* function returns @c 1 if this is the case, @c 0 otherwise. The parameters @p
|
||||
* a must not be @c NULL;
|
||||
*/
|
||||
static inline int
|
||||
COAP_STATIC_INLINE int
|
||||
coap_address_isany(const coap_address_t *a) {
|
||||
assert(a);
|
||||
return _coap_address_isany_impl(a);
|
||||
}
|
||||
|
||||
#ifdef WITH_POSIX
|
||||
#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
|
||||
|
||||
/**
|
||||
* Checks if given address @p a denotes a multicast address. This function
|
||||
* returns @c 1 if @p a is multicast, @c 0 otherwise.
|
||||
*/
|
||||
int coap_is_mcast(const coap_address_t *a);
|
||||
#else /* WITH_POSIX */
|
||||
#else /* !WITH_LWIP && !WITH_CONTIKI */
|
||||
/**
|
||||
* Checks if given address @p a denotes a multicast address. This function
|
||||
* returns @c 1 if @p a is multicast, @c 0 otherwise.
|
||||
*/
|
||||
static inline int
|
||||
COAP_STATIC_INLINE int
|
||||
coap_is_mcast(const coap_address_t *a) {
|
||||
return a && _coap_is_mcast_impl(a);
|
||||
}
|
||||
#endif /* WITH_POSIX */
|
||||
#endif /* !WITH_LWIP && !WITH_CONTIKI */
|
||||
|
||||
#endif /* _COAP_ADDRESS_H_ */
|
||||
#endif /* COAP_ADDRESS_H_ */
|
||||
|
Reference in New Issue
Block a user