#include "socketcan-bcm.hpp"
+#include <net/if.h>
+#include <sys/ioctl.h>
+
namespace utils
{
/// @brief Construct a default, invalid, socket.
: socketcan_t{}
{}
- /// @brief Construct a socket by moving an existing one.
- socketcan_bcm_t::socketcan_bcm_t(socketcan_bcm_t&& s)
- : socket_{s.socket_}
- {
- s.socket_ = INVALID_SOCKET;
- }
-
/// @brief Destruct the socket.
socketcan_bcm_t::~socketcan_bcm_t()
+ {}
+
+ /// @brief Connect the socket.
+ /// @return 0 if success.
+ int socketcan_bcm_t::connect(const struct sockaddr* addr, socklen_t len)
{
- if(socket_ != INVALID_SOCKET)
- ::close(socket_);
+ return socket_ != INVALID_SOCKET ? ::connect(socket_, addr, len) : 0;
}
/// @brief Open a raw socket CAN.
close();
struct ifreq ifr;
- socket_ = open(PF_CAN, SOCK_DGRAM, CAN_BCM);
+ socket_ = socketcan_t::open(PF_CAN, SOCK_DGRAM, CAN_BCM);
// Attempts to open a socket to CAN bus
::strcpy(ifr.ifr_name, device_name.c_str());