net/sock_udp: add sock_udp_ep_equal()
This commit is contained in:
parent
534b0da9a5
commit
bf8f8dfa67
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* 2018 Freie Universität Berlin
|
||||
*
|
||||
* 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
|
||||
@ -15,19 +16,23 @@
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief sock utility function definitions
|
||||
* @brief sock utility function definitions
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef NET_SOCK_UTIL_H
|
||||
#define NET_SOCK_UTIL_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "net/sock/udp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Format UDP endpoint to string and port
|
||||
*
|
||||
@ -73,6 +78,21 @@ int sock_urlsplit(const char *url, char *hostport, char *urlpath);
|
||||
*/
|
||||
int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @name helper definitions
|
||||
* @{
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* 2018 Freie Universität Berlin
|
||||
*
|
||||
* 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
|
||||
@ -7,11 +8,14 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup net_sock_util
|
||||
* @ingroup net_sock_util
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief sock utility functions implementation
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @brief sock utility functions implementation
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
* @}
|
||||
*/
|
||||
|
||||
@ -181,3 +185,26 @@ int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
|
||||
#endif
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bool sock_udp_ep_equal(const sock_udp_ep_t *a, const sock_udp_ep_t *b)
|
||||
{
|
||||
assert(a && b);
|
||||
|
||||
/* compare family and port */
|
||||
if ((a->family != b->family) || (a->port != b->port)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* compare addresses */
|
||||
switch (a->family) {
|
||||
#ifdef SOCK_HAS_IPV6
|
||||
case AF_INET6:
|
||||
return (memcmp(a->addr.ipv6, b->addr.ipv6, 16) == 0);
|
||||
|
||||
#endif
|
||||
case AF_INET:
|
||||
return (memcmp(a->addr.ipv4, b->addr.ipv4, 4) == 0);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user