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
b366e59c
Commit
b366e59c
authored
9 years ago
by
Oleg Hahm
Browse files
Options
Downloads
Patches
Plain Diff
conn: add function to find the best source address
...and use it in POSIX sendto() function.
parent
315ae0ee
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
sys/include/net/conn.h
+14
-0
14 additions, 0 deletions
sys/include/net/conn.h
sys/net/gnrc/conn/gnrc_conn.c
+8
-0
8 additions, 0 deletions
sys/net/gnrc/conn/gnrc_conn.c
sys/posix/sockets/posix_sockets.c
+10
-4
10 additions, 4 deletions
sys/posix/sockets/posix_sockets.c
with
32 additions
and
4 deletions
sys/include/net/conn.h
+
14
−
0
View file @
b366e59c
...
...
@@ -31,6 +31,7 @@
* @brief Application connection API definitions
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
*/
#ifndef NET_CONN_H_
#define NET_CONN_H_
...
...
@@ -38,11 +39,24 @@
#include
"net/conn/ip.h"
#include
"net/conn/tcp.h"
#include
"net/conn/udp.h"
#include
"net/ipv6/addr.h"
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* @brief Find the best matching source address for a given prefix
*
* @param[in] dst Pointer to the IPv6 address to find a match for
* Must not be NULL
*
* @return NULL if no matching address on any interface could be found
* @return pointer to an IPv6 address configured on an interface with the best
* match to @p dst
*/
ipv6_addr_t
*
conn_find_best_source
(
const
ipv6_addr_t
*
dst
);
#ifdef __cplusplus
}
#endif
...
...
This diff is collapsed.
Click to expand it.
sys/net/gnrc/conn/gnrc_conn.c
+
8
−
0
View file @
b366e59c
...
...
@@ -11,6 +11,7 @@
*
* @file
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
*/
#include
"net/conn.h"
...
...
@@ -85,6 +86,13 @@ bool gnrc_conn6_set_local_addr(uint8_t *conn_addr, const ipv6_addr_t *addr)
}
return
true
;
}
ipv6_addr_t
*
conn_find_best_source
(
const
ipv6_addr_t
*
dst
)
{
ipv6_addr_t
*
local
=
NULL
;
gnrc_ipv6_netif_find_by_prefix
(
&
local
,
dst
);
return
local
;
}
#endif
/** @} */
This diff is collapsed.
Click to expand it.
sys/posix/sockets/posix_sockets.c
+
10
−
4
View file @
b366e59c
/*
* Copyright (C) 2015 Freie Universität Berlin
* Copyright (C) 2015 INRIA
*
* 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
...
...
@@ -11,6 +12,7 @@
* @file
* @brief Providing implementation for POSIX socket wrapper.
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @todo
*/
...
...
@@ -862,11 +864,15 @@ ssize_t sendto(int socket, const void *buffer, size_t length, int flags,
sport
,
byteorder_ntohs
(
port
));
}
else
if
(
address
!=
NULL
)
{
ipv6_addr_t
local
;
ipv6_addr_t
unspec
;
ipv6_addr_t
*
best_match
;
s
->
src_port
=
(
uint16_t
)
genrand_uint32_range
(
1LU
<<
10U
,
1LU
<<
16U
);
/* implicitly bind the socket here */
ipv6_addr_set_unspecified
(
&
local
);
if
((
res
=
conn_udp_create
(
&
s
->
conn
.
udp
,
&
local
,
sizeof
(
local
),
/* find the best matching source address */
if
((
best_match
=
conn_find_best_source
(
addr
))
==
NULL
)
{
ipv6_addr_set_unspecified
(
&
unspec
);
best_match
=
&
unspec
;
}
if
((
res
=
conn_udp_create
(
&
s
->
conn
.
udp
,
best_match
,
sizeof
(
unspec
),
s
->
domain
,
s
->
src_port
))
<
0
)
{
errno
=
-
res
;
return
-
1
;
...
...
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