Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
bf8f8dfa
Commit
bf8f8dfa
authored
6 years ago
by
Hauke Petersen
Browse files
Options
Downloads
Patches
Plain Diff
net/sock_udp: add sock_udp_ep_equal()
parent
534b0da9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sys/include/net/sock/util.h
+23
-3
23 additions, 3 deletions
sys/include/net/sock/util.h
sys/net/sock/sock_util.c
+30
-3
30 additions, 3 deletions
sys/net/sock/sock_util.c
with
53 additions
and
6 deletions
sys/include/net/sock/util.h
+
23
−
3
View file @
bf8f8dfa
/*
* 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
* @{
...
...
This diff is collapsed.
Click to expand it.
sys/net/sock/sock_util.c
+
30
−
3
View file @
bf8f8dfa
/*
* 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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment