Thank you for your answer!
I was not able to find any indication that I could somehow change the
ioctl() call to return all interfaces.
I will now let the user name the interfaces he wants to use which even
could be a more elegant method.

Regards,
Jan-Niklas

Am Mittwoch, den 03.11.2010, 20:48 +0100 schrieb Oliver Hartkopp:
> On 01.11.2010 11:16, Jan-Niklas Meier wrote:
> > Hello!
> > I am currently trying to get a list of all CAN interfaces on my machine.
> > Im am using ioctl() with SIOCGIFCONF for this purpose as already
> > mentioned in a previous post on this mailinglist
> > (http://old.nabble.com/Enumerating-a-list-of-CAN-interfaces-td27603207.html).
> 
> > 
> > I found out that it makes no difference with which protocol I create the
> > socket - I always get all interfaces like lo and eth0. My problem is
> > that there also is a vcan0 which is not listed. Does this method only
> > work for nonvirtual CAN interfaces and is there any possibility to get
> > them listed too? Unfortunately I don't have a "real" CAN device for
> > testing...
> 
> Hi Jan-Niklas,
> 
> i checked both your code and this example:
> 
> http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html
> 
> It looks like that only interfaces are listed, that have an assigned
> IP-address. No matter if they are up or down.
> 
> Maybe there can be passed some flags to the ioctl() that removes the need for
> assigned IP-addresses ?!?
> 
> Regards,
> Oliver
> 
> > 
> > Here is the code I am using:
> > 
> > struct ifreq *ifr;
> > struct ifconf ifc;
> > int sock, i;
> > int numif;
> > 
> > memset(&ifc, 0, sizeof(ifc));
> > ifc.ifc_ifcu.ifcu_req = NULL;
> > ifc.ifc_len = 0;
> > 
> > /* Create a socket to be able to use ioctl */
> > if ((sock = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
> >     perror("socket");
> >     exit(1);
> > }
> > 
> > /* First call to determin how much memory will be needed */
> > if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
> >     perror("ioctl");
> >     exit(2);
> > }
> >             
> > /* Malloc the necessary memory */   
> > if ((ifr = malloc(ifc.ifc_len)) == NULL) {
> >     perror("malloc");
> >     exit(3);
> > }
> > ifc.ifc_ifcu.ifcu_req = ifr;
> > 
> > /* Request the infomation */
> > if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
> >     perror("ioctl2");
> >     exit(4);
> > }
> > close(sock);
> > 
> > numif = ifc.ifc_len / sizeof(struct ifreq);
> > for (i = 0; i < numif; i++) {
> >     struct ifreq *r = &ifr[i];
> >     printf("%-8s\n", r->ifr_name);
> > }
> > 
> > free(ifr);
> > 
> > Regards,
> > Jan-Niklas
> > 

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Socketcan-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users

Reply via email to