2017-03-05 23:53:51 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
2018-06-29 17:22:59 +02:00
|
|
|
* 2018 Freie Universität Berlin
|
2017-03-05 23:53:51 +01:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup net_sock_util sock utility functions
|
|
|
|
* @ingroup net_sock
|
|
|
|
*
|
|
|
|
* @brief sock utility function
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
2018-06-29 17:22:59 +02:00
|
|
|
* @brief sock utility function definitions
|
2017-03-05 23:53:51 +01:00
|
|
|
*
|
2018-06-29 17:22:59 +02:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
2017-03-05 23:53:51 +01:00
|
|
|
*/
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#ifndef NET_SOCK_UTIL_H
|
|
|
|
#define NET_SOCK_UTIL_H
|
2017-03-05 23:53:51 +01:00
|
|
|
|
2018-06-29 17:22:59 +02:00
|
|
|
#include <stdbool.h>
|
2018-07-18 15:28:01 +02:00
|
|
|
#include <stdint.h>
|
2018-06-29 17:22:59 +02:00
|
|
|
|
|
|
|
#include "net/sock/udp.h"
|
|
|
|
|
2017-03-05 23:53:51 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Format UDP endpoint to string and port
|
|
|
|
*
|
|
|
|
* @param[in] endpoint endpoint to format
|
|
|
|
* @param[out] addr_str where to write address as string
|
|
|
|
* @param[out] port where to write prt number as uint16_t
|
|
|
|
*
|
|
|
|
* @returns number of bytes written to @p addr_str on success
|
|
|
|
* @returns <0 otherwise
|
|
|
|
*/
|
|
|
|
int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *port);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Split url to host:port and url path
|
|
|
|
*
|
|
|
|
* Will split e.g., "https://host.name:1234/url/path" into
|
|
|
|
* "host.name:1234" and "/url/path".
|
|
|
|
*
|
|
|
|
* @note Caller has to make sure hostport and urlpath can hold the results!
|
2018-07-18 14:33:35 +02:00
|
|
|
* Make sure to provide space for @ref SOCK_HOSTPORT_MAXLEN respectively
|
2019-06-11 17:27:20 +02:00
|
|
|
* @ref SOCK_URLPATH_MAXLEN bytes, if pointers are not NULL.
|
2018-07-18 14:33:35 +02:00
|
|
|
* Scheme part of the URL is limited to @ref SOCK_SCHEME_MAXLEN length.
|
2017-03-05 23:53:51 +01:00
|
|
|
*
|
2019-06-11 17:27:20 +02:00
|
|
|
* @pre `url != NULL`
|
|
|
|
*
|
|
|
|
* @param[in] url URL to split. Must not be NULL.
|
|
|
|
* @param[out] hostport where to write host:port. Can be NULL.
|
|
|
|
* @param[out] urlpath where to write url path. Can be NULL.
|
2017-03-05 23:53:51 +01:00
|
|
|
*
|
|
|
|
* @returns 0 on success
|
|
|
|
* @returns <0 otherwise
|
|
|
|
*/
|
|
|
|
int sock_urlsplit(const char *url, char *hostport, char *urlpath);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Convert string to UDP endpoint
|
|
|
|
*
|
|
|
|
* Takes eg., "[2001:db8::1]:1234" and converts it into the corresponding UDP
|
|
|
|
* endpoint structure.
|
|
|
|
*
|
|
|
|
* @param[out] ep_out endpoint structure to fill
|
|
|
|
* @param[in] str string to read from
|
|
|
|
*
|
|
|
|
* @returns 0 on success
|
|
|
|
* @returns <0 otherwise
|
|
|
|
*/
|
|
|
|
int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str);
|
|
|
|
|
2018-06-29 17:22:59 +02:00
|
|
|
/**
|
|
|
|
* @brief Compare the two given UDP endpoints
|
|
|
|
*
|
|
|
|
* The given endpoint identifiers are compared by checking their address family,
|
|
|
|
* their addresses, and their port value.
|
|
|
|
*
|
|
|
|
* @param[in] a Endpoint A
|
|
|
|
* @param[in] b Endpoint B
|
|
|
|
*
|
|
|
|
* @return true if given endpoint identifiers point to the same destination
|
|
|
|
* @return false if given endpoint identifiers do not point to the same
|
|
|
|
* destination, or if the address family is unknown
|
|
|
|
*/
|
|
|
|
bool sock_udp_ep_equal(const sock_udp_ep_t *a, const sock_udp_ep_t *b);
|
|
|
|
|
2017-03-05 23:53:51 +01:00
|
|
|
/**
|
2019-05-22 15:45:57 +02:00
|
|
|
* @defgroup net_sock_util_conf SOCK utility functions compile configurations
|
|
|
|
* @ingroup net_sock_util
|
|
|
|
* @ingroup config
|
2017-03-05 23:53:51 +01:00
|
|
|
* @{
|
|
|
|
*/
|
2019-05-21 12:06:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief maximum length of the scheme part for sock_urlsplit.
|
|
|
|
*
|
|
|
|
* Ensures a hard limit on the string iterator
|
|
|
|
* */
|
|
|
|
#ifndef SOCK_SCHEME_MAXLEN
|
|
|
|
#define SOCK_SCHEME_MAXLEN (16U)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief maximum length of host:port part for sock_urlsplit()
|
|
|
|
*/
|
|
|
|
#ifndef SOCK_HOSTPORT_MAXLEN
|
|
|
|
#define SOCK_HOSTPORT_MAXLEN (64U)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief maximum length path for sock_urlsplit()
|
|
|
|
*/
|
|
|
|
#ifndef SOCK_URLPATH_MAXLEN
|
|
|
|
#define SOCK_URLPATH_MAXLEN (64U)
|
|
|
|
#endif
|
|
|
|
|
2017-03-05 23:53:51 +01:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#endif /* NET_SOCK_UTIL_H */
|
2017-03-05 23:53:51 +01:00
|
|
|
/** @} */
|