Skip to content

Commit 271e0c5

Browse files
rlubosMaureenHelm
authored andcommitted
net: context: Reset peer address on connect with AF_UNSPEC
As per POSIX, for non-connection-mode sockets the peer address should be reset if AF_UNSPEC family type is provided to the connect() call: "If the sa_family member of address is AF_UNSPEC, the socket's peer address shall be reset."" Signed-off-by: Robert Lubos <[email protected]>
1 parent b8b0407 commit 271e0c5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

subsys/net/ip/net_context.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,18 @@ int net_context_connect(struct net_context *context,
13571357
goto unlock;
13581358
}
13591359

1360+
/* As per POSIX, for non-connection-mode sockets:
1361+
* "If the sa_family member of address is AF_UNSPEC, the socket's peer
1362+
* address shall be reset.""
1363+
*/
1364+
if (IS_ENABLED(CONFIG_NET_UDP) && addr->sa_family == AF_UNSPEC &&
1365+
net_context_get_type(context) == SOCK_DGRAM) {
1366+
context->flags &= ~NET_CONTEXT_REMOTE_ADDR_SET;
1367+
memset(&context->remote, 0, sizeof(context->remote));
1368+
ret = 0;
1369+
goto unlock;
1370+
}
1371+
13601372
if (addr->sa_family != net_context_get_family(context)) {
13611373
NET_ERR("Address family %d does not match network context family %d",
13621374
addr->sa_family, net_context_get_family(context));

0 commit comments

Comments
 (0)