Thread: Need help to obtain NIC IP and MAC in C

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    South Pacific Island
    Posts
    9

    Need help to obtain NIC IP and MAC in C

    Hi all.

    I want to obtain the IP address and MAC address of the local NIC. How to write the code in C? or any header file and library can be used?

    Thanks.

  2. #2
    Cat Lover
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    109
    getaddrinfo or gethostbyname on the local host (obtained by gethostname) should return all the IP addresses of the local host (127.0.0.1 and another).

  3. #3
    Registered User
    Join Date
    Sep 2006
    Location
    South Pacific Island
    Posts
    9
    thank you. Which header file or library support "getaddrinfo"?

    I am using Mingw 3.4.2 (Dev-C++). Thanks.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    ws2tcpip.h

    For future reference, if you install something like msys you can use grep to search files for a specific function. Or you can use google.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by Dweia
    getaddrinfo or gethostbyname on the local host (obtained by gethostname) should return all the IP addresses of the local host (127.0.0.1 and another).
    gethostbyname doesn't always work. If you want the sure-fire way to do it, look at the code for ifconfig in BusyBox.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to spoof a MAC address?
    By Lateralus in forum Linux Programming
    Replies: 3
    Last Post: 06-26-2005, 07:50 PM
  2. MAC addresses
    By Thantos in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-20-2004, 02:26 PM