Thread: getifaddrs return same adapter multiple times

  1. #1
    Registered User
    Join Date
    Mar 2009

    getifaddrs return same adapter multiple times

    I have written a c program to retrieve all the network interfaces.
    But when I iterate through the ifaddr elements of the linklist it returns same interface many times. When I prints the ifa_name s it prints like as follow.

    eth0 *
    eth0 *
    eth0 *

    * - repeats

    I want to eliminate this repeating and need to retrieve the address that return with ifconfig -a command.
    How can I overcome this ?

    when I command $ifconfig -a its list as follows.

    eth0 Link encap:Ethernet

    irda0 Link encap:IrLAP

    lo Link encap:Local

    pan0 Link encap:Ethernet

    wlan0 Link encap:Ethernet

    wmaster0 Link encap:UNSPEC

    Thank you very much.

    Nuwan Gunarathne

  2. #2
    Registered User
    Join Date
    Sep 2007
    If this is on Linux, look at the NOTES section of the getifaddrs() man page:
    The addresses returned on Linux will usually be the IPv4 and IPv6 addresses assigned to the interface, but also one AF_PACKET address per interface containing lower-level details about the interface and its physical layer. In this case, the ifa_data field may contain a pointer to a struct net_device_stats, defined in <linux/netdevice.h>, which contains various interface attributes and statistics.
    That's probably where the multiple interfaces are coming from. You should be able to filter these by looking at ifa_addr->sa_family.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  2. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  3. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM
  4. sort linked list using BST
    By Micko in forum C Programming
    Replies: 8
    Last Post: 10-04-2004, 02:04 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM