Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:23:22+00:00 2026-06-17T05:23:22+00:00

I have used the program which is present in the following link http://www.linuxhowtos.org/manpages/3/getifaddrs.htm .

  • 0

I have used the program which is present in the following link http://www.linuxhowtos.org/manpages/3/getifaddrs.htm .

but it prints all the IP like loopback,eth0,eth1 lo etc

now I need to get only the ip which are active excpet loopback ip
ex

$iffconfig
eth6 Link encap:Ethernet HWaddr 08:00:27:47:99:da
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe47:99da/64 Scope:Link
as the ifconfig gives the active interface and correspoding IPs

what has to be changed in this code to get the above thing working ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:23:23+00:00Added an answer on June 17, 2026 at 5:23 am

    Change

        if (ifa->ifa_addr == NULL)
            continue;
    
        family = ifa->ifa_addr->sa_family;
    

    with

        if (ifa->ifa_addr == NULL)
            continue;
    
        if ((strcmp("lo", ifa->ifa_name) == 0) ||
            !(ifa->ifa_flags & (IFF_RUNNING)))
            continue;
    
        family = ifa->ifa_addr->sa_family;
    

    and add this line just after the other includes

    #include <net/if.h>
    

    The added lines just check for “lo” interface name, contained into ifa->ifa_name, and check the flags of the interfaces. Testing IFF_RUNNING bit ( look at net/if.h for further definitions) will return only running interfaces.

    If you want to check other feature of the interfaces, just check for this flags (taken from net/if.h)

    • IFF_UP Interface is running.
    • IFF_BROADCAST Valid broadcast address set.
    • IFF_DEBUG Internal debugging flag.
    • IFF_LOOPBACK Interface is a loopback interface.
    • IFF_POINTOPOINT Interface is a point-to-point link.
    • IFF_RUNNING Resources allocated.
    • IFF_NOARP No arp protocol, L2 destination address not set.
    • IFF_PROMISC Interface is in promiscuous mode.
    • IFF_NOTRAILERS Avoid use of trailers.
    • IFF_ALLMULTI Receive all multicast packets.
    • IFF_MASTER Master of a load balancing bundle.
    • IFF_SLAVE Slave of a load balancing bundle.
    • IFF_MULTICAST Supports multicast
    • IFF_PORTSEL Is able to select media type via ifmap.
    • IFF_AUTOMEDIA Auto media selection active.
    • IFF_DYNAMIC The addresses are lost when the interface goes down.
    • IFF_LOWER_UP Driver signals L1 up (since Linux 2.6.17)
    • IFF_DORMANT Driver signals dormant (since Linux 2.6.17)
    • IFF_ECHO Echo sent packets (since Linux 2.6.25)

    EDIT

    if you need to discriminate IPV6 GUA and ULA address use this macros

    #ifndef IN6_IS_ADDR_GLOBAL
    #define IN6_IS_ADDR_GLOBAL(a) \
            ((((__const uint32_t *) (a))[0] & htonl(0x70000000)) \
            == htonl (0x20000000))
    #endif /* IS ADDR GLOBAL */
    
    #ifndef IN6_IS_ADDR_ULA
    #define IN6_IS_ADDR_ULA(a) \
            ((((__const uint32_t *) (a))[0] & htonl(0xfe000000)) \
            == htonl (0xfc000000))
    #endif /* IS ADDR ULA */
    

    the parameter must be taken from ((sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C program which has always used hard coded define statements for
Under Windows, I have used a program called Dependency Walker to examine the libraries
I have used JSON::Any in my program to transfer the hash between client and
I have used ajax auto completeextender in my program well its works fine no
I have a program that is used to create other program and compile it
I have a general purpose Utility dll file used in my WPF program. The
I have a ios program for iPad. It is used 2 view, A view
I have written a C++ program for a University assignment. I used Netbeans 6.8
I have a C# Winforms program with multiple textboxes. I used the properties for
I used SWIG to generate a Perl module for a C++ program. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.