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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:57:05+00:00 2026-05-17T15:57:05+00:00

I think there is no way to enumerate each network interface on my system

  • 0

I think there is no way to enumerate each network interface on my system and their assigned IP address using just sockets. Is this correct?

I mean, in Linux this could be:

eth0: 192.168.1.5
wlan0: 192.168.0.5
lo: 127.0.0.1

I don’t care about interface names, just the IP addresses assigned.

I recall to have done this in the past in Windows, using Win32 (though I don’t remember how). But is there a method to do this in a portable way?

  • 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-05-17T15:57:05+00:00Added an answer on May 17, 2026 at 3:57 pm

    Here’s a good start:

    #include <sys/types.h>
    #include <netinet/in.h>
    #include <sys/socket.h>
    #include <ifaddrs.h>
    #include <stdio.h>
    void
    print_sockaddr(struct sockaddr* addr,const char *name)
    {
        char addrbuf[128] ;
    
        addrbuf[0] = 0;
        if(addr->sa_family == AF_UNSPEC)
            return;
        switch(addr->sa_family) {
            case AF_INET:
                inet_ntop(addr->sa_family,&((struct sockaddr_in*)addr)->sin_addr,addrbuf,sizeof(addrbuf));
                break;
            case AF_INET6:
                inet_ntop(addr->sa_family,&((struct sockaddr_in6*)addr)->sin6_addr,addrbuf,sizeof(addrbuf));
                break;
            default:
                sprintf(addrbuf,"Unknown (%d)",(int)addr->sa_family);
                break;
    
        }
        printf("%-16s %s\n",name,addrbuf);
    }
    
    void
    print_ifaddr(struct ifaddrs *addr)
    {
        char addrbuf[128] ;
    
        addrbuf[0] = 0;
        printf("%-16s %s\n","Name",addr->ifa_name);
        if(addr->ifa_addr != NULL)
            print_sockaddr(addr->ifa_addr,"Address");
        if(addr->ifa_netmask != NULL)
            print_sockaddr(addr->ifa_netmask,"Netmask");
        if(addr->ifa_broadaddr != NULL)
            print_sockaddr(addr->ifa_broadaddr,"Broadcast addr.");
        if(addr->ifa_dstaddr != NULL)
            print_sockaddr(addr->ifa_dstaddr,"Peer addr.");
        puts("");
    }
    
    int main(int argc,char *argv[])
    {
        struct ifaddrs *addrs,*tmp;
    
        if(getifaddrs(&addrs) != 0) {
            perror("getifaddrs");
            return 1;
        }
        for(tmp = addrs; tmp ; tmp = tmp->ifa_next) {
            print_ifaddr(tmp);
        }
    
        freeifaddrs(addrs);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using guidelines right now, but I do not think there is any way
I'm making my way into using Event Sourcing pattern, and there is one thing
I think there is a simple answer to this, but for some reason I
Edit I think there is some confusion, I am not using both of the
I've been using the search function but I think there isn't any related question
Is there a way to do this (psedo code): GetCurrentThread().Items.Add(new RefObject); then later on
when using a MVC 3 collection that uses IEnumerable, is there a way to
Is there a way to enumerate a process with a given PID in Windows,
Is there any way to enumerate all of a character's Unicode properties in Ruby?
Is there way to select object by their specific tag without the use of

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.