Skip to content

Commit

Permalink
Merge pull request #117 from battlesnake/master
Browse files Browse the repository at this point in the history
Fixed failing build when socket.h adds flexible arrays to end of structures
  • Loading branch information
pavel-kirienko authored Nov 24, 2017
2 parents a1022b0 + e797d69 commit ba9af4c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions libuavcan_drivers/linux/include/uavcan_linux/socketcan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,17 @@ class SocketCanIface : public uavcan::ICanIface
iov.iov_base = &sockcan_frame;
iov.iov_len = sizeof(sockcan_frame);

struct Control
{
cmsghdr cm;
std::uint8_t data[sizeof(::timeval)];
};
auto control = Control();
static constexpr size_t ControlSize = sizeof(cmsghdr) + sizeof(::timeval);
using ControlStorage = typename std::aligned_storage<ControlSize>::type;
ControlStorage control_storage;
auto control = reinterpret_cast<std::uint8_t *>(&control_storage);
std::fill(control, control + ControlSize, 0x00);

auto msg = ::msghdr();
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &control;
msg.msg_controllen = sizeof(control);
msg.msg_control = control;
msg.msg_controllen = ControlSize;

const int res = ::recvmsg(fd_, &msg, MSG_DONTWAIT);
if (res <= 0)
Expand Down

0 comments on commit ba9af4c

Please sign in to comment.