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

  • Home
  • SEARCH
  • 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 8536341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:38:25+00:00 2026-06-11T10:38:25+00:00

I am developing an application on Linux. Linux executes the command: ifconfig eth0 192.168.10.15

  • 0

I am developing an application on Linux. Linux executes the command:

ifconfig eth0 192.168.10.15 netmask 255.255.255.0

at the boot process with systemd.

When I try to learn my ip address with ifconfig here below the result:

eth0      Link encap:Ethernet  HWaddr 00:18:31:E0:44:C6  
          inet addr:192.168.10.15  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::218:31ff:fee0:44c6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:24799 errors:0 dropped:1 overruns:0 frame:0
          TX packets:13753 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5475289 (5.2 MiB)  TX bytes:1403459 (1.3 MiB)

On the other hand when I try to learn my ip address via program below, I get 192.168.10.42.

void GetMyIp(char caIP[INET_ADDRSTRLEN])
{
  int s;
  struct ifconf ifconf;
  struct ifreq ifr[50];
  int ifs;
  int i;    

  s = socket(AF_INET, SOCK_STREAM, 0);
  if (s < 0) 
  {
      #ifdef _DEBUG_PROCESS
        if(EDebugProcess<GetDebugLevelOfPMC())
        {
        PrintToLogFile("Socket error\n");
        }
      #endif
  }

  ifconf.ifc_buf = (char *) ifr;
  ifconf.ifc_len = sizeof ifr;

  if (ioctl(s, SIOCGIFCONF, &ifconf) == -1) 
  {
    #ifdef _DEBUG_PROCESS
        if(EDebugProcess<GetDebugLevelOfPMC())
        {
        PrintToLogFile("ioctl error\n");
        }
      #endif
  }

  ifs = ifconf.ifc_len / sizeof(ifr[0]);
    struct sockaddr_in *s_in = (struct sockaddr_in *) &ifr[ifs-1].ifr_addr;
    if (!inet_ntop(AF_INET, &s_in->sin_addr, gcaMyIP, sizeof(gcaMyIP))) 
    {
    #ifdef _DEBUG_PROCESS
        if(EDebugProcess<GetDebugLevelOfPMC())
        {
        PrintToLogFile("inet_ntop error\n");
        }
    #endif
    }


    close(s);
    memcpy(caIP,gcaMyIP,INET_ADDRSTRLEN);
}

What is the source of the difference?

  • 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-11T10:38:26+00:00Added an answer on June 11, 2026 at 10:38 am

    You can try that if you want:

    http://www.binarytides.com/get-local-ip-in-c-on-linux/

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

Sidebar

Related Questions

I am developing some application in Linux .This Linux is a virtual machine running
I am developing a Qt application on Red Hat Linux. I want to capture
Anyone know application like network location(mac) for linux,windows.If not i am thinking of developing
I am developing a small business application, and my development environment is a Linux
I am developing application to filter logcat generated by android.I executed linux comand '/system/bin/logcat
I am using NET Beans IDE for developing my application in LINUX. I have
I'm developing application with Qt Embedded and run it in linux framebuffer. I need
I am developing an application that will run on Linux to run fullscreen all
I'm currently developing an application which needs a lot of system and process information,
I am developing a non-GUI application for Linux. At some point I ask the

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.