Skip to content

Commit

Permalink
Ancillary data in the msghdr struct is optional, not mandatory.
Browse files Browse the repository at this point in the history
If it doesn't exist, that's ok sendmsg() anyway.  Fixes pkg repo
issues now that pkg uses sendmsg.
  • Loading branch information
Sean Bruno committed Oct 4, 2014
1 parent 200e09e commit ad92220
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions bsd-user/freebsd/os-socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ static inline abi_long do_freebsd_sendmsg(int fd, abi_ulong target_msg,
msg.msg_name = NULL;
msg.msg_namelen = 0;
}
msg.msg_controllen = 2 * tswapal(msgp->msg_controllen);
msg.msg_control = alloca(msg.msg_controllen);
msg.msg_flags = tswap32(msgp->msg_flags);
if (tswapal(msgp->msg_controllen) > 0) {
msg.msg_controllen = 2 * tswapal(msgp->msg_controllen);
msg.msg_control = alloca(msg.msg_controllen);
msg.msg_flags = tswap32(msgp->msg_flags);
} else {
msg.msg_controllen = 0;
msg.msg_control = NULL;
msg.msg_flags = 0;
}

count = tswapal(msgp->msg_iovlen);
vec = alloca(count * sizeof(struct iovec));
Expand All @@ -65,7 +71,10 @@ static inline abi_long do_freebsd_sendmsg(int fd, abi_ulong target_msg,
msg.msg_iovlen = count;
msg.msg_iov = vec;

ret = t2h_freebsd_cmsg(&msg, msgp);
if (msg.msg_controllen > 0)
ret = t2h_freebsd_cmsg(&msg, msgp);
else /* no ancillary data */
ret = 0;
if (!is_error(ret)) {
ret = get_errno(sendmsg(fd, &msg, flags));
}
Expand Down Expand Up @@ -116,7 +125,10 @@ static inline abi_long do_freebsd_recvmsg(int fd, abi_ulong target_msg,
ret = get_errno(recvmsg(fd, &msg, flags));
if (!is_error(ret)) {
len = ret;
ret = h2t_freebsd_cmsg(msgp, &msg);
if (msg.msg_controllen > 0)
ret = h2t_freebsd_cmsg(msgp, &msg);
else /* no ancillary data */
ret = 0;
if (!is_error(ret)) {
msgp->msg_namelen = tswap32(msg.msg_namelen);
if (msg.msg_name != NULL) {
Expand Down

0 comments on commit ad92220

Please sign in to comment.