18#if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) 
   19#ifdef HAVE_ARPA_INET_H 
   22#ifdef HAVE_NETINET_IN_H 
   23#include <netinet/in.h> 
   25#ifdef HAVE_SYS_SOCKET_H 
   26#include <sys/socket.h> 
   34#define IN_MULTICAST(Address) (0) 
   40  switch (addr->
addr.
sa.sa_family) {
 
   43    return ntohs(addr->
addr.
sin.sin_port);
 
   47    return ntohs(addr->
addr.
sin6.sin6_port);
 
   58  switch (addr->
addr.
sa.sa_family) {
 
   61    addr->
addr.
sin.sin_port = htons(port);
 
   66    addr->
addr.
sin6.sin6_port = htons(port);
 
   83  switch (a->
addr.
sa.sa_family) {
 
   88                  sizeof(
struct in_addr)) == 0;
 
   94                  sizeof(
struct in6_addr)) == 0;
 
  104#if COAP_AF_UNIX_SUPPORT 
  105  return a->
addr.
sa.sa_family == AF_UNIX;
 
  121  switch (a->
addr.
sa.sa_family) {
 
  124    return IN_MULTICAST(ntohl(a->
addr.
sin.sin_addr.s_addr));
 
  129    return IN6_IS_ADDR_MULTICAST(&a->
addr.
sin6.sin6_addr) ||
 
  130           (IN6_IS_ADDR_V4MAPPED(&a->
addr.
sin6.sin6_addr) &&
 
  131            IN_MULTICAST(ntohl(a->
addr.
sin6.sin6_addr.s6_addr[12])));
 
  133    return a->
addr.
sin6.sin6_addr.s6_addr[0] == 0xff;
 
  142#if !defined(WIN32) && !defined(__ZEPHYR__) 
  145#define COAP_BCST_CNT 15 
  149#ifndef COAP_BCST_REFRESH_SECS 
  150#define COAP_BCST_REFRESH_SECS 30 
  153#if COAP_IPV4_SUPPORT && !defined(ESPIDF_VERSION) 
  154static int bcst_cnt = -1;
 
  159#if !defined(ESPIDF_VERSION) 
  168#if !defined(ESPIDF_VERSION) 
  177  switch (a->
addr.
sa.sa_family) {
 
  180    ipv4.s_addr = a->
addr.
sin.sin_addr.s_addr;
 
  186    if (IN6_IS_ADDR_V4MAPPED(&a->
addr.
sin6.sin6_addr)) {
 
  187      memcpy(&ipv4, &a->
addr.
sin6.sin6_addr.s6_addr[12], 
sizeof(ipv4));
 
  198  if (ipv4.s_addr == INADDR_BROADCAST)
 
  201#if !defined(ESPIDF_VERSION) 
  203  if (bcst_cnt == -1 ||
 
  206    struct ifaddrs *ifa = NULL;
 
  209    if (getifaddrs(&ifa) != 0) {
 
  210      coap_log_warn(
"coap_is_bcst: Cannot determine any broadcast addresses\n");
 
  217      if (ife->ifa_addr->sa_family == AF_INET &&
 
  218          ife->ifa_flags & IFF_BROADCAST) {
 
  219        b_ipv4[bcst_cnt].s_addr = ((
struct sockaddr_in *)ife->ifa_broadaddr)->sin_addr.s_addr;
 
  225      coap_log_warn(
"coap_is_bcst: Insufficient space for broadcast addresses\n");
 
  229  for (i = 0; i < bcst_cnt; i++) {
 
  230    if (ipv4.s_addr == b_ipv4[i].s_addr)
 
  251#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) 
  259                             const uint8_t *host, 
size_t host_len) {
 
  260#if COAP_AF_UNIX_SUPPORT 
  266  for (i = 0; i < host_len; i++) {
 
  267    if ((host_len - i) >= 3 && host[i] == 
'%' && host[i+1] == 
'2' &&
 
  268        (host[i+2] == 
'F' || host[i+2] == 
'f')) {
 
  290#if !defined(WITH_CONTIKI) 
  295  if (port == 0 && update_port0)
 
  309  uint32_t scheme_hint_bits = 0;
 
  315      scheme_hint_bits |= 1 << scheme;
 
  320      scheme_hint_bits |= 1 << scheme;
 
  325      scheme_hint_bits |= 1 << scheme;
 
  330      scheme_hint_bits |= 1 << scheme;
 
  335      scheme_hint_bits |= 1 << scheme;
 
  340      scheme_hint_bits |= 1 << scheme;
 
  350  switch (use_unix_proto) {
 
  375  return scheme_hint_bits;
 
  381                          uint16_t secure_port,
 
  383                          uint16_t ws_secure_port,
 
  385                          int scheme_hint_bits,
 
  387#if !defined(RIOT_VERSION) 
  389  struct addrinfo *res, *ainfo;
 
  390  struct addrinfo hints;
 
  391  static char addrstr[256];
 
  400#if COAP_AF_UNIX_SUPPORT 
  409      if (scheme_hint_bits & (1 << scheme)) {
 
  476  memset(addrstr, 0, 
sizeof(addrstr));
 
  477  if (address && address->
length)
 
  478    memcpy(addrstr, address->
s, address->
length);
 
  480    memcpy(addrstr, 
"localhost", 9);
 
  482  memset((
char *)&hints, 0, 
sizeof(hints));
 
  483  hints.ai_socktype = 0;
 
  484  hints.ai_family = AF_UNSPEC;
 
  485  hints.ai_flags = ai_hints_flags;
 
  487  error = getaddrinfo(addrstr, NULL, &hints, &res);
 
  494  for (ainfo = res; ainfo != NULL; ainfo = ainfo->ai_next) {
 
  495#if !defined(WITH_LWIP) 
  496    if (ainfo->ai_addrlen > (socklen_t)
sizeof(info->
addr.
addr))
 
  500    switch (ainfo->ai_family) {
 
  508        if (scheme_hint_bits & (1 << scheme)) {
 
  564#if !defined(WITH_LWIP) 
  565          info->
addr.
size = (socklen_t)ainfo->ai_addrlen;
 
  566          memcpy(&info->
addr.
addr, ainfo->ai_addr, ainfo->ai_addrlen);
 
  568          memset(&info->
addr, 0, 
sizeof(info->
addr));
 
  569          switch (ainfo->ai_family) {
 
  571            struct sockaddr_in6 *sock6;
 
  574            struct sockaddr_in *sock4;
 
  576            sock4 = (
struct sockaddr_in *)ainfo->ai_addr;
 
  577            info->
addr.port = ntohs(sock4->sin_port);
 
  578            memcpy(&info->
addr.
addr, &sock4->sin_addr, 4);
 
  580            info->
addr.
addr.type = IPADDR_TYPE_V4;
 
  586            sock6 = (
struct sockaddr_in6 *)ainfo->ai_addr;
 
  587            info->
addr.port = ntohs(sock6->sin6_port);
 
  588            memcpy(&info->
addr.
addr, &sock6->sin6_addr, 16);
 
  589#if LWIP_IPV6 && LWIP_IPV4 
  590            info->
addr.
addr.type = IPADDR_TYPE_V6;
 
  637          info_tmp = info_list;
 
  644            info_tmp = info_tmp->
next;
 
  656              info_prev->
next = info;
 
  672#include "net/utils.h" 
  673  ipv6_addr_t addr_ipv6;
 
  674  netif_t *netif = NULL;
 
  680  (void)ai_hints_flags;
 
  682  if (netutils_get_ipv6(&addr_ipv6, &netif, (
const char *)address->
s) >= 0) {
 
  684      if (scheme_hint_bits & (1 << scheme)) {
 
  740          info_prev->
next = info;
 
  747        info->
addr.
size = 
sizeof(
struct sockaddr_in6);
 
  751        info->
addr.
addr.
sin6.sin6_scope_id = (uint32_t)netif_get_id(netif);
 
  801#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) 
  804#if defined(WITH_LWIP) || defined(WITH_CONTIKI) 
  810  if (src->
addr.
sa.sa_family == AF_INET6) {
 
  817#if COAP_IPV4_SUPPORT && COAP_IPV6_SUPPORT 
  821    if (src->
addr.
sa.sa_family == AF_INET) {
 
  834  switch (a->
addr.
sa.sa_family) {
 
  837    return a->
addr.
sin.sin_addr.s_addr == INADDR_ANY;
 
  841    return memcmp(&in6addr_any,
 
  843                  sizeof(in6addr_any)) == 0;
 
void coap_address_set_port(coap_address_t *addr, uint16_t port)
Set the port field of addr to port (in host byte order).
 
int coap_address_set_unix_domain(coap_address_t *addr, const uint8_t *host, size_t host_len)
Copy the parsed unix domain host into coap_address_t structure translating %2F into / on the way.
 
#define COAP_BCST_REFRESH_SECS
 
void coap_free_address_info(coap_addr_info_t *info)
Free off the one or more linked sets of coap_addr_info_t returned from coap_resolve_address_info().
 
int coap_is_af_unix(const coap_address_t *a)
Checks if given address a denotes a AF_UNIX address.
 
int coap_is_bcast(const coap_address_t *a)
Checks if given address a denotes a broadcast address.
 
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.
 
int _coap_address_isany_impl(const coap_address_t *a)
 
uint16_t coap_address_get_port(const coap_address_t *addr)
Returns the port from addr in host byte order.
 
uint32_t coap_get_available_scheme_hint_bits(int have_pki_psk, int ws_check, coap_proto_t use_unix_proto)
Determine and set up scheme_hint_bits for a server that can be used in a call to coap_resolve_address...
 
coap_addr_info_t * coap_resolve_address_info(const coap_str_const_t *address, uint16_t port, uint16_t secure_port, uint16_t ws_port, uint16_t ws_secure_port, int ai_hints_flags, int scheme_hint_bits, coap_resolve_type_t type)
Resolve the specified address into a set of coap_address_t that can be used to bind() (local) or conn...
 
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.
 
static void update_port(coap_address_t *addr, uint16_t port, uint16_t default_port, int update_port0)
 
coap_resolve_type_t
coap_resolve_type_t values
 
@ COAP_RESOLVE_TYPE_LOCAL
local side of session
 
#define COAP_UNIX_PATH_MAX
 
Pulls together all the internal only header files.
 
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
 
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
 
int coap_tcp_is_supported(void)
Check whether TCP is available.
 
int coap_host_is_unix_domain(const coap_str_const_t *host)
Determines from the host whether this is a Unix Domain socket request.
 
coap_uri_scheme_t
The scheme specifiers.
 
@ COAP_URI_SCHEME_COAPS_WS
 
@ COAP_URI_SCHEME_COAPS_TCP
 
@ COAP_URI_SCHEME_COAP_TCP
 
@ COAP_URI_SCHEME_COAP_WS
 
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
 
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
 
void coap_ticks(coap_tick_t *)
Returns the current value of an internal tick counter.
 
int coap_tls_is_supported(void)
Check whether TLS is available.
 
int coap_dtls_is_supported(void)
Check whether DTLS is available.
 
#define coap_log_warn(...)
 
#define coap_log_err(...)
 
#define COAP_DEFAULT_PORT
 
coap_proto_t
CoAP protocol types.
 
#define COAPS_DEFAULT_PORT
 
int coap_ws_is_supported(void)
Check whether WebSockets is available.
 
int coap_wss_is_supported(void)
Check whether Secure WebSockets is available.
 
Resolved addresses information.
 
coap_uri_scheme_t scheme
CoAP scheme to use.
 
coap_proto_t proto
CoAP protocol to use.
 
struct coap_addr_info_t * next
Next entry in the chain.
 
coap_address_t addr
The address to connect / bind to.
 
Multi-purpose address abstraction.
 
socklen_t size
size of addr
 
struct coap_sockaddr_un cun
 
union coap_address_t::@0 addr
 
char sun_path[COAP_UNIX_PATH_MAX]
 
CoAP string data definition with const data.
 
const uint8_t * s
read-only string data
 
size_t length
length of string