Skip to content
Permalink
Browse files

net: context: Allow TCP to use sendmsg()

If sendmsg() is used for TCP sockets, the msghdr->msg_name is not
really used as the socket must already have been connected.
In that case just get the destination address directly from
net_context remote address field.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed Aug 6, 2019
1 parent 75bf3c5 commit 7c387a34ac3e49c0a8c3179e359c972faf1b72b9
Showing with 16 additions and 4 deletions.
  1. +16 −4 subsys/net/ip/net_context.c
@@ -1364,8 +1364,14 @@ static int context_sendto(struct net_context *context,
addr6 = msghdr->msg_name;
addrlen = msghdr->msg_namelen;

if (!addr6) {
return -EINVAL;
if (net_context_get_ip_proto(context) ==
IPPROTO_TCP) {
addr6 = net_sin6(&context->remote);
addrlen = sizeof(struct sockaddr_in6);
} else {
if (!addr6) {
return -EINVAL;
}
}

/* For sendmsg(), the dst_addr is NULL so set it here.
@@ -1389,8 +1395,14 @@ static int context_sendto(struct net_context *context,
addr4 = msghdr->msg_name;
addrlen = msghdr->msg_namelen;

if (!addr4) {
return -EINVAL;
if (net_context_get_ip_proto(context) ==
IPPROTO_TCP) {
addr4 = net_sin(&context->remote);
addrlen = sizeof(struct sockaddr_in);
} else {
if (!addr4) {
return -EINVAL;
}
}

/* For sendmsg(), the dst_addr is NULL so set it here.

0 comments on commit 7c387a3

Please sign in to comment.
You can’t perform that action at this time.