X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=low-can-binding%2Futils%2Fsocketcan-bcm.cpp;h=3f3a0968bb1d9928a2ce05914454a638852feade;hb=refs%2Fchanges%2F57%2F18757%2F3;hp=d1fd8e0acbed1cbd3a663069d0221dc8f74b41cb;hpb=e190b7b3069d86fce25831c366bb0cd3fa615289;p=apps%2Fagl-service-can-low-level.git diff --git a/low-can-binding/utils/socketcan-bcm.cpp b/low-can-binding/utils/socketcan-bcm.cpp index d1fd8e0a..3f3a0968 100644 --- a/low-can-binding/utils/socketcan-bcm.cpp +++ b/low-can-binding/utils/socketcan-bcm.cpp @@ -74,14 +74,22 @@ namespace utils { struct utils::bcm_msg msg; - ::memset(&msg, 0, sizeof(msg)); const struct sockaddr_can& addr = s.get_tx_address(); socklen_t addrlen = sizeof(addr); struct ifreq ifr; ssize_t nbytes = ::recvfrom(s.socket(), &msg, sizeof(msg), 0, (struct sockaddr*)&addr, &addrlen); + if(nbytes < 0) + { + AFB_ERROR("Can't read the next message from socket '%d'. '%s'", s.socket(), strerror(errno)); + return s; + } ifr.ifr_ifindex = addr.can_ifindex; - ioctl(s.socket(), SIOCGIFNAME, &ifr); + if(ioctl(s.socket(), SIOCGIFNAME, &ifr) < 0) + { + AFB_ERROR("Can't read the interface name. '%s'", strerror(errno)); + return s; + } long unsigned int frame_size = nbytes-sizeof(struct bcm_msg_head); AFB_DEBUG("Data available: %li bytes read. BCM head, opcode: %i, can_id: %i, nframes: %i", frame_size, msg.msg_head.opcode, msg.msg_head.can_id, msg.msg_head.nframes);