diff --git a/components/coap/libcoap/include/coap/address.h b/components/coap/libcoap/include/coap/address.h index 85db2046..b45e81e6 100644 --- a/components/coap/libcoap/include/coap/address.h +++ b/components/coap/libcoap/include/coap/address.h @@ -62,7 +62,9 @@ typedef struct coap_address_t { struct sockaddr sa; struct sockaddr_storage st; struct sockaddr_in sin; +#if COAP_IPV6 struct sockaddr_in6 sin6; +#endif } addr; } coap_address_t; @@ -79,10 +81,12 @@ _coap_address_isany_impl(const coap_address_t *a) { switch (a->addr.sa.sa_family) { case AF_INET: return a->addr.sin.sin_addr.s_addr == INADDR_ANY; +#if COAP_IPV6 case AF_INET6: return memcmp(&in6addr_any, &a->addr.sin6.sin6_addr, sizeof(in6addr_any)) == 0; +#endif default: ; } diff --git a/components/coap/libcoap/src/address.c b/components/coap/libcoap/src/address.c index b4db76f0..acb9ba3c 100644 --- a/components/coap/libcoap/src/address.c +++ b/components/coap/libcoap/src/address.c @@ -28,10 +28,12 @@ coap_address_equals(const coap_address_t *a, const coap_address_t *b) { a->addr.sin.sin_port == b->addr.sin.sin_port && memcmp(&a->addr.sin.sin_addr, &b->addr.sin.sin_addr, sizeof(struct in_addr)) == 0; +#if COAP_IPV6 case AF_INET6: return a->addr.sin6.sin6_port == b->addr.sin6.sin6_port && memcmp(&a->addr.sin6.sin6_addr, &b->addr.sin6.sin6_addr, sizeof(struct in6_addr)) == 0; +#endif default: /* fall through and signal error */ ; } @@ -45,8 +47,10 @@ int coap_is_mcast(const coap_address_t *a) { switch (a->addr.sa.sa_family) { case AF_INET: return IN_MULTICAST(ntohl(a->addr.sin.sin_addr.s_addr)); +#if COAP_IPV6 case AF_INET6: return IN6_IS_ADDR_MULTICAST(&a->addr.sin6.sin6_addr); +#endif default: /* fall through and signal error */ ; } diff --git a/components/coap/libcoap/src/debug.c b/components/coap/libcoap/src/debug.c index d68438b7..e1afda60 100644 --- a/components/coap/libcoap/src/debug.c +++ b/components/coap/libcoap/src/debug.c @@ -170,6 +170,7 @@ coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t le addrptr = &addr->addr.sin.sin_addr; port = ntohs(addr->addr.sin.sin_port); break; +#if COAP_IPV6 case AF_INET6: if (len < 7) /* do not proceed if buffer is even too short for [::]:0 */ return 0; @@ -180,6 +181,7 @@ coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t le port = ntohs(addr->addr.sin6.sin6_port); break; +#endif default: memcpy(buf, "(unknown address type)", min(22, len)); return min(22, len); diff --git a/components/coap/libcoap/src/net.c b/components/coap/libcoap/src/net.c index e08aaa43..7ebe48ad 100644 --- a/components/coap/libcoap/src/net.c +++ b/components/coap/libcoap/src/net.c @@ -508,12 +508,14 @@ coap_transaction_id(const coap_address_t *peer, const coap_pdu_t *pdu, coap_hash((const unsigned char *)&peer->addr.sin.sin_addr, sizeof(peer->addr.sin.sin_addr), h); break; +#if COAP_IPV6 case AF_INET6: coap_hash((const unsigned char *)&peer->addr.sin6.sin6_port, sizeof(peer->addr.sin6.sin6_port), h); coap_hash((const unsigned char *)&peer->addr.sin6.sin6_addr, sizeof(peer->addr.sin6.sin6_addr), h); break; +#endif default: return; } diff --git a/components/coap/port/include/coap_config_posix.h b/components/coap/port/include/coap_config_posix.h index a77e97f0..a925b8d2 100644 --- a/components/coap/port/include/coap_config_posix.h +++ b/components/coap/port/include/coap_config_posix.h @@ -36,6 +36,8 @@ #define CUSTOM_COAP_NETWORK_SEND #define CUSTOM_COAP_NETWORK_READ +#define COAP_IPV6 LWIP_IPV6 + #endif #endif /* COAP_CONFIG_POSIX_H_ */