* getifaddrs and SocketCAN interfaces
@ 2015-03-28 20:30 Paarvai Naai
2015-03-29 18:36 ` Oliver Hartkopp
2015-03-29 22:23 ` Tom Evans
0 siblings, 2 replies; 5+ messages in thread
From: Paarvai Naai @ 2015-03-28 20:30 UTC (permalink / raw)
To: linux-can
Hi,
I recently tried using getifaddrs to list all of the SocketCAN
interfaces on my system programmatically.
However, I found that the SocketCAN interfaces do not have their
ifa_addr field in the returned ifaddrs structure set. This makes it
not possible to identifying the interface as type SocketCAN.
Presumably if the ifa_addr field was set, we could look at the
sa_family field and check if it is AF_CAN.
The other option is to use netlink to query the network devices, but
that is more involved. Is there an easier way?
Thanks!
Paarvai
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getifaddrs and SocketCAN interfaces
2015-03-28 20:30 getifaddrs and SocketCAN interfaces Paarvai Naai
@ 2015-03-29 18:36 ` Oliver Hartkopp
2015-03-29 19:40 ` dev.kurt
2015-03-29 22:23 ` Tom Evans
1 sibling, 1 reply; 5+ messages in thread
From: Oliver Hartkopp @ 2015-03-29 18:36 UTC (permalink / raw)
To: Paarvai Naai, linux-can
On 28.03.2015 21:30, Paarvai Naai wrote:
> I recently tried using getifaddrs to list all of the SocketCAN
> interfaces on my system programmatically.
>
> However, I found that the SocketCAN interfaces do not have their
> ifa_addr field in the returned ifaddrs structure set. This makes it
> not possible to identifying the interface as type SocketCAN.
> Presumably if the ifa_addr field was set, we could look at the
> sa_family field and check if it is AF_CAN.
Hi Paarvai,
on the CAN bus you don't have node addresses - so there's nothing comparable
to ethernet devices which have an IP-address bound to them.
The CAN netdevice stuff in linux/driver/net/can is currently separated from
the network layer stuff in linux/net/can pretty good.
So attaching a (useless) sock_addr from the network layer to the CAN
interface seems inappropriate.
Do you know about the network device ARPHRD definitions:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/if_arp.h#n55
> The other option is to use netlink to query the network devices, but
> that is more involved. Is there an easier way?
E.g. you can get this netdevice type information from
$ cat /sys/class/net/vcan0/type
280
Regards,
Oliver
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getifaddrs and SocketCAN interfaces
2015-03-29 18:36 ` Oliver Hartkopp
@ 2015-03-29 19:40 ` dev.kurt
2015-03-30 21:46 ` Paarvai Naai
0 siblings, 1 reply; 5+ messages in thread
From: dev.kurt @ 2015-03-29 19:40 UTC (permalink / raw)
To: Oliver Hartkopp, Paarvai Naai, linux-can
On 29 March 2015 20:36:48 CEST, Oliver Hartkopp <socketcan@hartkopp.net> wrote:
>On 28.03.2015 21:30, Paarvai Naai wrote:
>> I recently tried using getifaddrs to list all of the SocketCAN
>> interfaces on my system programmatically.
>>
>> However, I found that the SocketCAN interfaces do not have their
>> ifa_addr field in the returned ifaddrs structure set. This makes it
>> not possible to identifying the interface as type SocketCAN.
>> Presumably if the ifa_addr field was set, we could look at the
>> sa_family field and check if it is AF_CAN.
>
>Hi Paarvai,
>
>on the CAN bus you don't have node addresses - so there's nothing
>comparable
>to ethernet devices which have an IP-address bound to them.
>
>The CAN netdevice stuff in linux/driver/net/can is currently separated
>from
>the network layer stuff in linux/net/can pretty good.
>
>So attaching a (useless) sock_addr from the network layer to the CAN
>interface seems inappropriate.
>
>Do you know about the network device ARPHRD definitions:
>
>http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/if_arp.h#n55
>
>> The other option is to use netlink to query the network devices, but
>> that is more involved. Is there an easier way?
>
>E.g. you can get this netdevice type information from
I created
https://github.com/kurt-vd/enumif
for this reason.
I'd explain if I was using my own computer
Kurt
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getifaddrs and SocketCAN interfaces
2015-03-28 20:30 getifaddrs and SocketCAN interfaces Paarvai Naai
2015-03-29 18:36 ` Oliver Hartkopp
@ 2015-03-29 22:23 ` Tom Evans
1 sibling, 0 replies; 5+ messages in thread
From: Tom Evans @ 2015-03-29 22:23 UTC (permalink / raw)
To: Paarvai Naai, linux-can
On 29/03/15 07:30, Paarvai Naai wrote:
> Hi,
>
> I recently tried using getifaddrs to list all of the SocketCAN
> interfaces on my system programmatically.
root@triton1:/# find /sys -name "*can*"
/sys/bus/platform/devices/flexcan.0
/sys/bus/platform/devices/flexcan.1
/sys/bus/platform/drivers/flexcan
/sys/bus/platform/drivers/flexcan/flexcan.0
/sys/bus/platform/drivers/flexcan/flexcan.1
/sys/devices/soc.0/50000000.aips/flexcan.0
/sys/devices/soc.0/50000000.aips/flexcan.0/net/can0
/sys/devices/soc.0/50000000.aips/flexcan.1
/sys/devices/soc.0/50000000.aips/flexcan.1/net/can1
/sys/devices/virtual/net/vcan0
...
/sys/class/net/vcan0
/sys/class/net/can0
/sys/class/net/can1
Then I open them by name:
struct ifreq ifr;
strcpy(ifr.ifr_name, f_vnCanBusNames[a_eDevice]);
/* ifr.ifr_ifindex gets filled
rc = ioctl(pSkt->skt, SIOCGIFINDEX, &ifr);
Or was there something else you needed?
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: getifaddrs and SocketCAN interfaces
2015-03-29 19:40 ` dev.kurt
@ 2015-03-30 21:46 ` Paarvai Naai
0 siblings, 0 replies; 5+ messages in thread
From: Paarvai Naai @ 2015-03-30 21:46 UTC (permalink / raw)
To: dev.kurt; +Cc: Oliver Hartkopp, linux-can
Hi Kurt,
Thanks for that pointer! It's exactly what I'm looking for as it is
less complicated than libnetlink from iproute2.
(I see there was an earlier post about enumif too, but I missed it
during my earlier search:
http://permalink.gmane.org/gmane.linux.can/3351)
I see that your libenumif.cc has the following includes:
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
Not being super familiar with netlink, what would you say are the
forward/backward compatibility guarantees for these kernel-level
includes? I'm assuming the dependance on these kernel-level includes
is pretty stable?
Regarding, the other suggestions, these are good options too, but I'd
prefer not to use the /sys filesystem if possible. Relying on /sys
can be brittle.
Thanks!
Paarvai
On Sun, Mar 29, 2015 at 12:40 PM, <dev.kurt@vandijck-laurijssen.be> wrote:
> I created
> https://github.com/kurt-vd/enumif
> for this reason.
> I'd explain if I was using my own computer
>
> Kurt
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-03-30 21:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-28 20:30 getifaddrs and SocketCAN interfaces Paarvai Naai
2015-03-29 18:36 ` Oliver Hartkopp
2015-03-29 19:40 ` dev.kurt
2015-03-30 21:46 ` Paarvai Naai
2015-03-29 22:23 ` Tom Evans
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.