diff --git a/examples/coap-client.c b/examples/coap-client.c index f22cfb83..b95211dd 100644 --- a/examples/coap-client.c +++ b/examples/coap-client.c @@ -1500,8 +1500,8 @@ get_session(coap_context_t *ctx, coap_session_t *session = NULL; is_mcast = coap_is_mcast(dst); - if (local_addr || dst->addr.sa.sa_family == AF_UNIX) { - if (dst->addr.sa.sa_family == AF_UNIX) { + if (local_addr || coap_is_af_unix(dst)) { + if (coap_is_af_unix(dst)) { coap_address_t bind_addr; if (local_addr) { diff --git a/include/coap3/coap_address.h b/include/coap3/coap_address.h index 0db22a16..8fe1b8e1 100644 --- a/include/coap3/coap_address.h +++ b/include/coap3/coap_address.h @@ -269,6 +269,12 @@ int coap_is_mcast(const coap_address_t *a); */ int coap_is_bcast(const coap_address_t *a); +/** + * Checks if given address @p a denotes a AF_UNIX address. This function + * returns @c 1 if @p a is of type AF_UNIX, @c 0 otherwise. + */ +int coap_is_af_unix(const coap_address_t *a); + #else /* WITH_LWIP || WITH_CONTIKI */ /** @@ -280,6 +286,16 @@ coap_is_mcast(const coap_address_t *a) { return a && _coap_is_mcast_impl(a); } +/** + * Checks if given address @p a denotes a AF_UNIX address. This function + * returns @c 1 if @p a is of type AF_UNIX, @c 0 otherwise. + */ +COAP_STATIC_INLINE int +coap_is_af_unix(const coap_address_t *a) { + (void)a; + return 0; +} + #endif /* WITH_LWIP || WITH_CONTIKI */ #endif /* COAP_ADDRESS_H_ */ diff --git a/libcoap-3.map b/libcoap-3.map index d19419f9..26fd9482 100644 --- a/libcoap-3.map +++ b/libcoap-3.map @@ -116,6 +116,7 @@ global: coap_io_prepare_io; coap_io_process; coap_io_process_with_fds; + coap_is_af_unix; coap_is_bcast; coap_is_mcast; coap_join_mcast_group_intf; diff --git a/libcoap-3.sym b/libcoap-3.sym index e7569dcb..1d4df1dc 100644 --- a/libcoap-3.sym +++ b/libcoap-3.sym @@ -114,6 +114,7 @@ coap_io_prepare_epoll coap_io_prepare_io coap_io_process coap_io_process_with_fds +coap_is_af_unix coap_is_bcast coap_is_mcast coap_join_mcast_group_intf diff --git a/man/Makefile.am b/man/Makefile.am index b44e8077..5017738a 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -101,6 +101,13 @@ A2X_EXTRA_PAGES_5 = @DOLLAR_SIGN@(shell for fil in $(TXT5) ; do sed -ne '/^NAME/ # Then all the alternative names as well as the extras defined below need # to be cleaned up in a 'make unistall'. install-man: install-man3 install-man5 install-man7 + @echo ".so man3/coap_address.3" > coap_free_address_info.3 + @echo ".so man3/coap_address.3" > coap_sockaddr_un.3 + @echo ".so man3/coap_address.3" > coap_address_set_unix_domain.3 + @echo ".so man3/coap_address.3" > coap_host_is_unix_domain.3 + @echo ".so man3/coap_address.3" > coap_is_bcast.3 + @echo ".so man3/coap_address.3" > coap_is_mcast.3 + @echo ".so man3/coap_address.3" > coap_is_af_unix.3 @echo ".so man3/coap_cache.3" > coap_cache_get_pdu.3 @echo ".so man3/coap_cache.3" > coap_cache_get_app_data.3 @echo ".so man3/coap_cache.3" > coap_cache_set_app_data.3 diff --git a/man/coap.txt.in b/man/coap.txt.in index 7aed692b..226d11df 100644 --- a/man/coap.txt.in +++ b/man/coap.txt.in @@ -38,17 +38,18 @@ examples directory. SEE ALSO -------- -*coap_address*(3), -*coap_async*(3), *coap_attribute*(3), *coap_block*(3), *coap_cache*(3), -*coap_context*(3), *coap_encryption*(3), *coap_endpoint_client*(3), -*coap_endpoint_server*(3), *coap_handler*(3), *coap_io*(3), -*coap_keepalive*(3), *coap_logging*(3), *coap_lwip*(3), *coap_observe*(3), -*coap_oscore*(3), *coap_pdu_access*(3), *coap_pdu_setup*(3), *coap_recovery*(3), -*coap_resource*(3), *coap_session*(3), *coap_string*(3), *coap_tls_library*(3) -and *coap_uri*(3) +*coap_address*(3), *coap_async*(3), *coap_attribute*(3), *coap_block*(3), +*coap_cache*(3), *coap_context*(3), *coap_deprecated*(3), *coap_encryption*(3), +*coap_endpoint_client*(3), *coap_endpoint_server*(3), *coap_handler*(3), +*coap_io*(3), *coap_keepalive*(3), *coap_logging*(3), *coap_lwip*(3), +*coap_observe*(3), *coap_oscore*(3), *coap_pdu_access*(3), *coap_pdu_setup*(3), +*coap_persist*(3), *coap_recovery*(3), *coap_resource*(3), *coap_session*(3), +*coap_string*(3), *coap_tls_library*(3), *coap_uri*(3) and *coap_websockets*(3) For example executables, see *coap-client*(5), *coap-rd*(5) and *coap-server*(5) +For OSCORE configuration, see *coap-oscore-conf*(5) + FURTHER INFORMATION ------------------- See diff --git a/man/coap_address.txt.in b/man/coap_address.txt.in index a9d015f5..5d0bcc08 100644 --- a/man/coap_address.txt.in +++ b/man/coap_address.txt.in @@ -13,11 +13,19 @@ NAME coap_address, coap_address_t, coap_address_init, +coap_address_copy, +coap_address_equals, +coap_address_get_port, +coap_address_set_port, coap_get_available_scheme_hint_bits, coap_resolve_address_info, coap_free_address_info, coap_sockaddr_un, -coap_address_set_unix_domain +coap_address_set_unix_domain, +coap_host_is_unix_domain, +coap_is_bcast, +coap_is_mcast, +coap_is_af_unix - Work with CoAP Socket Address Types SYNOPSIS @@ -30,6 +38,14 @@ SYNOPSIS *void coap_address_init(coap_address_t *_addr_);* +*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_);* + +*uint16_t coap_address_get_port(const coap_address_t *_addr_);* + +*void coap_address_set_port(coap_address_t *_addr_, uint16_t _port_);* + *uint32_t coap_get_available_scheme_hint_bits(int _have_pki_psk_, int _ws_check_, coap_proto_t _use_unix_proto_);* @@ -39,9 +55,17 @@ int _scheme_hint_bits_, coap_resolve_type_t _type_);* *void coap_free_address_info(coap_addr_info_t *_info_list_);* +*int coap_host_is_unix_domain(const coap_str_const_t *_host_);* + *int coap_address_set_unix_domain(coap_address_t *_addr_, const uint8_t *_host_, size_t _host_len_);* +*int coap_is_bcast(const coap_address_t *_addr_);* + +*int coap_is_mcast(const coap_address_t *_addr_);* + +*int coap_is_af_unix(const coap_address_t *_addr_);* + For specific (D)TLS library support, link with *-lcoap-@LIBCOAP_API_VERSION@-notls*, *-lcoap-@LIBCOAP_API_VERSION@-gnutls*, *-lcoap-@LIBCOAP_API_VERSION@-openssl*, *-lcoap-@LIBCOAP_API_VERSION@-mbedtls* @@ -139,6 +163,25 @@ It is then the responsibility of the application to set the address family in addr.sa.sa_family and then fill in the the appropriate union structure based on the address family before the coap_address_t _addr_ is used. +*Function: coap_address_copy()* + +The *coap_address_copy*() function copies the address _src_ into _dst_. + +*Function: coap_address_equals()* + +The *coap_address_equals*() function checks whether the addresses _a_ and _b_ +are identical. + +*Function: coap_address_get_port()* + +The *coap_address_get_port*() function gets the the port from _addr_ if +_addr_ is AF_INET or AF_INET6. + +*Function: coap_address_set_port()* + +The *coap_address_set_port*() function sets the the _port_ in _addr_ if +_addr_ is AF_INET or AF_INET6. + *Function: coap_get_available_scheme_hint_bits()* The *coap_get_available_scheme_hint_bits*() function is used for servers to @@ -176,8 +219,31 @@ populates _addr_ with all the appropriate information for a Unix Domain Socket. The _host_ information with length _host_len_ abstracted from a CoAP URI is copied into _addr_'s _sun_path_ translating any %2F encoding to /. +*Function: coap_host_is_unix_domain()* + +The *coap_host_is_unix_domain*() function checks whether _host_ is an +an AF_UNIX file name (encoded using %2F to indicate a /). + +*Function: coap_is_mcast()* + +The *coap_is_mcast*() function checks whether _addr_ is a multicast +address. + +*Function: coap_is_bcast()* + +The *coap_is_mcast*() function checks whether _addr_ is a broadcast +address. + +*Function: coap_is_af_unix()* + +The *coap_is_mcast*() function checks whether _addr_ is of the type AF_UNIX. + RETURN VALUES ------------- +*coap_address_equals*() returns 1 if the addresses are equal or 0 if not. + +*coap_address_get_port*() returns the port in network byte order. + *coap_get_available_scheme_hint_bits*() returns a set of COAP_URI_SCHEME_*_BIT or'd together based on the supported libcoap functionality. @@ -186,6 +252,14 @@ used for session setup or NULL if there is a failure. *coap_address_set_unix_domain*() returns 1 on success or 0 on failure. +*coap_host_is_unix_domain*() returns 1 if encoded unix path name or 0 if not. + +*coap_is_mcast*() returns 1 if address is multicast or 0 if not. + +*coap_is_bcast*() returns 1 if address is broadcast or 0 if not. + +*coap_is_af_unix*() returns 1 if address is of type AF_UNIX or 0 if not. + EXAMPLES -------- *Get target address from uri* diff --git a/src/coap_address.c b/src/coap_address.c index 39c5be36..81d6e426 100644 --- a/src/coap_address.c +++ b/src/coap_address.c @@ -99,6 +99,16 @@ coap_address_equals(const coap_address_t *a, const coap_address_t *b) { return 0; } +int +coap_is_af_unix(const coap_address_t *a) { +#if COAP_AF_UNIX_SUPPORT + return a->addr.sa.sa_family == AF_UNIX; +#else /* ! COAP_AF_UNIX_SUPPORT */ + (void)a; + return 0; +#endif /* ! COAP_AF_UNIX_SUPPORT */ +} + int coap_is_mcast(const coap_address_t *a) { if (!a)