programatically determine netlink-type: can or vcan ...
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
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/can1somehow.
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.)
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/can1exists.)
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
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
Re: @Marc Kleine-Budde
Quoted 2 lines · ajneu <ajneu1 <at> gmail.com> writes:
@Marc Kleine-Budde: Any chance, to see this go into upstream (pengutronix git repo)???
Thanks.