Skip to contentSkip to conversation

programatically determine netlink-type: can or vcan ...

DISCUSSION ajneu 1 participant 5 messages Jun 21, 2016 – Jul 19, 2016 CAN network drivers

lore
Share & tools
lore

ajneu

author
#0 lore raw

Hi,

how can one determine the netlink-type (can or vcan, ...) of an interface-name (e.g. can1), from a C program?

It would be great if I can e.g. get that from /sys/class/net/can1 somehow.

What would work, but is NOT nice (because of portability problems), is to use the C-function system:

if (system("test \"$(ip link show can1 type vcan)\" != \"\"")) {
printf("can1 is not vcan\n");
} else {
printf("can1 is vcan\n");
}

Thanks.
ajneu

author
#1 lore raw
Quoted 8 lines · ajneu <ajneu1 <at> gmail.com> writes:

Hi,

how can one determine the netlink-type (can or vcan, ...) of an interface-name (e.g. can1), from a C program?

It would be great if I can e.g. get that from /sys/class/net/can1 somehow.

Quoted 8 lines

What would work, but is NOT nice (because of portability problems), is to use the C-function system:

if (system("test \"$(ip link show can1 type vcan)\" !=  \"\"")) {
   printf("can1 is not vcan\n");
} else {

printf("can1 is vcan\n");
}

(on command line:
test "$(ip link show can1 type vcan)" != "" )

This would be nice in libsocketcan, but it's not in there. Somewhat limited...

Missing also, from libsocketcan, is the ability to determine if a device such as can1 exists.
(What I do now, is to just check if /sys/class/net/can1 exists.)

author
#2 lore raw
Quoted 7 lines · ajneu <ajneu1 <at> gmail.com> writes:

This would be nice in libsocketcan, but it's not in there. Somewhat limited...

Missing also, from libsocketcan, is the ability to determine if a device such as can1 exists.
(What I do now, is to just check if /sys/class/net/can1 exists.)

OK, it turns out that it was quite manageable, to add the desired functionality to libsocketcan.
See
https://github.com/ajneu/libsocketcan
https://github.com/ajneu/libsocketcan/commit/26ef

author
#3 lore raw
Quoted 5 lines · ajneu <ajneu1 <at> gmail.com> writes:

OK, it turns out that it was quite manageable, to add the desired functionality to libsocketcan.
See
https://github.com/ajneu/libsocketcan
https://github.com/ajneu/libsocketcan/commit/26ef

Added another commit, that adds function: device_is_up()

Why? The existing can_get_state() is limited only to can devices. It does not work for vcan.

I hope Marc Kleine-Budde can integrate these changes into the official git.

Regards,
ajneu