Description
Hi guys!
I am just a beginner so please, be patient to my ineptitude.
I was trying to write simple code to test BCM sockets, but anytime i want to add some new rule, the write function returns an error and errno is set to 22. I decided then to run bcmserver and add rule through a socket, but the results are the same. Here are the details:
I am using RaspberryPi 4 with CAN FD shield.
juraszekl@raspberrypi:~ $ uname -a
Linux raspberrypi 6.1.0-rpi8-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.73-1+rpt1 (2024-01-25) aarch64 GNU/Linux
First, simple configuration of interface:
juraszekl@raspberrypi:~ $ sudo ip link set can0 up type can bitrate 100000
Next loading can_bcm module:
juraszekl@raspberrypi:~ $ sudo modprobe can-bcm
juraszekl@raspberrypi:~ $ sudo lsmod | grep can
can_bcm 24576 0
can 28672 1 can_bcm
can_dev 40960 1 mcp251xfd
I've add a few printf's to the original bcmserver.c file, then recompiled. if i send the command:
juraszekl@raspberrypi:~ $ echo "< can0 A 1 0 123 8 11 22 33 44 55 66 77 88 >" | nc 0.0.0.0 28600
the output from bcmserver is:
juraszekl@raspberrypi:~/Temp/can-utils $ ./bcmserver
listening
forking
BCM socket opened, sc = 5
BCM socket connected
read '< can0 A 1 0 123 8 11 22 33 44 55 66 77 88 >'
sscanf ok! items = 14
res = -1, errno = 22
code that gives the last line looks like this:
if (!ioctl(sc, SIOCGIFINDEX, &ifr)) {
caddr.can_ifindex = ifr.ifr_ifindex;
res = sendto(sc, &msg, sizeof(msg), 0,
(struct sockaddr*)&caddr, sizeof(caddr));
printf("res = %d, errno = %d\n", res, errno);
}
After two days and many different combinations with msg structure, interface numbers and socket options i must give up.
Please tell me what am i doing wrong.
BR.
Łukasz