PCAN-USB FD with libpcap on Raspberry Pi 3

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
nypdmax
Posts: 3
Joined: Tue 24. Apr 2018, 08:17

PCAN-USB FD with libpcap on Raspberry Pi 3

Post by nypdmax » Tue 24. Apr 2018, 08:23

Hello all,

I posted same issue in libpcap's github repo.

I have a program woking well on my PC (ubuntu 16.04 amd64, with libpcap0.8 and libpcap0.8-dev installed from ubuntu apt repo, version 1.7.4) . Now I'm running that CAN bus monitor in my raspberry pi 3 and I found some issues.

While I'm opening a socketcan interface with libpcap.

Code: Select all

     char err_buff[PCAP_ERRBUF_SIZE];
     pcap_t *hl;

     hl = pcap_open_live(CAN_DEV.c_str(), BUFSIZ, 1, 1000, err_buff);
     if (hl == NULL)
     {
         /* open failed */
         std::cout << "Couldn't open device " << CAN_DEV << std::endl;
         std::cout <<" Error: " << err_buff << std::endl;
         return -1;
     }
 
     if (pcap_datalink(hl) != DLT_CAN_SOCKETCAN)
     {
         // it is not a socketCAN frame 
         std::cout << "Device doesn't use socketCAN, it use " << pcap_datalink(hl) << std::endl;
         return -1;
     } 
In both master and libpcap-1.8 branches, pcap_datalink(hl) returned 113 (DLT_LINUX_SLL) instead of 227 (DLT_CAN_SOCKETCAN).

However on my PC it's working as expected.

FYI, my raspberry pi 3 is running Linux 4.14.33. I've recompiled the kernel to support CAN devices and my PCAN-USB FD adapter.
And I set up the CAN interface using:

Code: Select all

sudo ip link set can0 type can bitrate 500000 triple-sampling on
sudo ifconfig can0 up
I used a simple socketcan program to test sending and receiving frames and found no problem.
So I guess the problem lies in somewhere else like kernel configuration or other libraries missing or something else?
Please advice... Is there anyone ever encountered samilar issue? Any help is appreciated!

nypdmax
Posts: 3
Joined: Tue 24. Apr 2018, 08:17

Re: PCAN-USB FD with libpcap on Raspberry Pi 3

Post by nypdmax » Wed 25. Apr 2018, 09:56

Problem solved. For anyone interested, see here:
https://github.com/the-tcpdump-group/libpcap/issues/699

Post Reply