From 32f65eaa9ad699898fa274ea1f29655e6a344fb9 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 11 Aug 2015 11:39:52 +0200 Subject: swrap: Fix TCP support with sendmsg/recvmsg Signed-off-by: Andreas Schneider Reviewed-by: Stefan Metzmacher --- src/socket_wrapper.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index bd2798b..18622af 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -4603,9 +4603,11 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, int flags) * length of the returned address. If the application does not need * to know the source address, msg_name can be specified as NULL. */ - if (omsg->msg_name != NULL && - omsg->msg_namelen != 0 && - omsg->msg_namelen >= msg.msg_namelen) { + if (si->type == SOCK_STREAM) { + omsg->msg_namelen = 0; + } else if (omsg->msg_name != NULL && + omsg->msg_namelen != 0 && + omsg->msg_namelen >= msg.msg_namelen) { memcpy(omsg->msg_name, msg.msg_name, msg.msg_namelen); omsg->msg_namelen = msg.msg_namelen; } @@ -4644,8 +4646,11 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr *omsg, int flags) tmp.iov_len = 0; ZERO_STRUCT(msg); - msg.msg_name = omsg->msg_name; /* optional address */ - msg.msg_namelen = omsg->msg_namelen; /* size of address */ + + if (si->connected == 0) { + msg.msg_name = omsg->msg_name; /* optional address */ + msg.msg_namelen = omsg->msg_namelen; /* size of address */ + } msg.msg_iov = omsg->msg_iov; /* scatter/gather array */ msg.msg_iovlen = omsg->msg_iovlen; /* # elements in msg_iov */ #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL -- cgit