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 8030075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:39:05+00:00 2026-06-05T00:39:05+00:00

I am looking for a particular network address using a small snippet like: char

  • 0

I am looking for a particular network address using a small snippet like:

  char name[INET_ADDRSTRLEN];
  struct ifaddrs *iflist;
  if (getifaddrs(&iflist) < 0)
    perror("getifaddrs");

  struct in_addr addr;
  for (struct ifaddrs *p = iflist; p; p = p->ifa_next)
    {
      if (strcmp(p->ifa_name, "lo") == 0)
        {
          addr = reinterpret_cast<struct sockaddr_in*>(p->ifa_addr)->sin_addr;
          if (inet_ntop(AF_INET, &addr, name, sizeof(name)) == NULL)
            {
              perror("inet_ntop");
              continue;
            }

          cout << name << " ---> " << if_nametoindex("lo") << " : " << addr.s_addr << endl;
        }
    }

And the output i get is:

1.0.0.0 ---> 1 : 1
127.0.0.1 ---> 1 : 16777343

I don’t understand the first result..this doesnt happen with something like eth# but it does with another interface called bond0. What is this?

  • 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-05T00:39:06+00:00Added an answer on June 5, 2026 at 12:39 am

    getifaddr is non-standard. I suppose you are using it on a linux system. The man page there has the note:

    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 , which contains various interface attributes and
    statistics.

    You probably should check ifa_addr->sa_family if this has the family that you are expecting.

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

Sidebar

Related Questions

I am looking to scroll the page to a particular location.Something like this: function
How would you find a particular class name inside lots of jar files? (Looking
Firebug has the ability to log calls to a particular function name. I'm looking
In particular I'm looking for an IP address that I can put in my
I'm looking at trying to optimise a particular function in a PHP application and
I was looking a source code of a particular page of my project and
Am looking for a query to sum values in a particular time duration say
I'm looking at the log messages for a particular branch in TortoiseSVN. We have
What is the best way to undertake Servlet profiling? In particular I am looking
I'm currently using subversion and tourtiseSVN. I am looking to revamp the way my

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.