17 #ifndef COAP_ADDRESS_H_
18 #define COAP_ADDRESS_H_
23 #include <sys/types.h>
26 #if defined(WITH_LWIP)
28 #include <lwip/ip_addr.h>
40 return ntohs(addr->port);
48 addr->port = htons(port);
51 #define _coap_address_equals_impl(A, B) \
52 ((A)->port == (B)->port \
53 && (!!ip_addr_cmp(&(A)->addr,&(B)->addr)))
55 #define _coap_address_isany_impl(A) ip_addr_isany(&(A)->addr)
57 #define _coap_is_mcast_impl(Address) ip_addr_ismulticast(&(Address)->addr)
59 #elif defined(WITH_CONTIKI)
73 return uip_ntohs(addr->port);
81 addr->port = uip_htons(port);
84 #define _coap_address_equals_impl(A,B) \
85 ((A)->port == (B)->port \
86 && uip_ipaddr_cmp(&((A)->addr),&((B)->addr)))
89 #define _coap_address_isany_impl(A) 0
91 #define _coap_is_mcast_impl(Address) uip_is_addr_mcast(&((Address)->addr))
100 struct sockaddr_in
sin;
101 struct sockaddr_in6
sin6;
125 switch (a->
addr.
sa.sa_family) {
127 return a->
addr.
sin.sin_addr.s_addr == INADDR_ANY;
129 return memcmp(&in6addr_any,
131 sizeof(in6addr_any)) == 0;
153 #if defined(WITH_LWIP) || defined(WITH_CONTIKI)
158 if ( src->
addr.
sa.sa_family == AF_INET6 ) {
163 }
else if ( src->
addr.
sa.sa_family == AF_INET ) {
171 #if defined(WITH_LWIP) || defined(WITH_CONTIKI)
179 assert(a); assert(b);
180 return _coap_address_equals_impl(a, b);
195 #if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
209 return a && _coap_is_mcast_impl(a);
COAP_STATIC_INLINE int coap_address_isany(const coap_address_t *a)
Checks if given address object a denotes the wildcard address.
void coap_address_set_port(coap_address_t *addr, uint16_t port)
Set the port field of addr to port (in host byte order).
COAP_STATIC_INLINE int _coap_address_isany_impl(const coap_address_t *a)
void coap_address_init(coap_address_t *addr)
Resets the given coap_address_t object addr to its default values.
int coap_is_mcast(const coap_address_t *a)
Checks if given address a denotes a multicast address.
uint16_t coap_address_get_port(const coap_address_t *addr)
Returns the port from addr in host byte order.
struct coap_address_t coap_address_t
multi-purpose address abstraction
COAP_STATIC_INLINE void coap_address_copy(coap_address_t *dst, const coap_address_t *src)
int coap_address_equals(const coap_address_t *a, const coap_address_t *b)
Compares given address objects a and b.
#define COAP_STATIC_INLINE
multi-purpose address abstraction
socklen_t size
size of addr
union coap_address_t::@0 addr