Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    How to get IP of pc using c program

    hi , if any body have idea that how to get ip address and hardwared address of network card by using c program then please help me . I have writtne source below i don't have much experience of C programming on linux.
    #include <ifaddrs.h>
    #include <stdio.h>
    int main()

    struct ifaddrs *id;

    int val;

    val = getifaddrs(&id);

    printf("Network Interface Name :- %s\n",id->ifa_name);
    printf("Network Address of %s :- %d\n",id->ifa_name,id->ifa_addr);
    printf("Network Data :- %d \n",id->ifa_data);
    //printf("%d \n",(id->ifa_next)->ifa_addr);

    printf("Socket Data : -%c\n",id->ifa_addr->sa_data);

    return 0;


    out put:
    Network Interface Name :- lo
    Network Address of lo :- 165750228
    Network Data :- 165751520

  2. #2
    Linux Engineer
    Join Date
    Oct 2004

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts