Find the answer to your Linux question:
Results 1 to 5 of 5
Hi! I'm doing some application in C/C++ using pure berkeley sockets. I want to know, what is the best way to get the adress from the current local machine, right ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2006
    Posts
    17

    Getting Local IP of current machine (internet sockets)


    Hi!

    I'm doing some application in C/C++ using pure berkeley sockets.

    I want to know, what is the best way to get the adress from the current local machine, right now what I do is returning me 127.1.1.0, i want to have 192.168.0.100 for insntace

    i gethostname() -> gives me my computer name ( marcd-linuxbox )
    and then i create a hostent struct with the gethostbyname()

    it works on Windows machine, probably because Windows is dumb, i found it more logical to have something like 127.0.0.1 or something like that returned. But i really need to find a way to get this local IP for my local network broadcast thingy.

    Thanks for any help

  2. #2
    Just Joined!
    Join Date
    Nov 2006
    Posts
    17
    ok i managed to find this talking about ioctl() function and i managed to get that the second interface returned 192.168.0.102 like i wanted

    But this brings me to another question, how can i know if the second interface will always return the right local adress, as the first one currently returns 127.0.0.1

  3. #3
    Linux User
    Join Date
    Aug 2006
    Location
    Croydon, PA
    Posts
    392

    ifconfig -a


    This gives all the IP ethernet addresses on the machine.
    Good Luck,
    Ski
    RHCT

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Nov 2006
    Posts
    17
    Quote Originally Posted by Skiboy

    ifconfig -a


    This gives all the IP ethernet addresses on the machine.
    Yes but not inside a C program, thats why i had to use the ioctl() function

  6. #5
    Just Joined!
    Join Date
    Feb 2007
    Posts
    1
    Quote Originally Posted by md_lasalle
    Yes but not inside a C program, thats why i had to use the ioctl() function

    hi md_lasalle,

    now..i'm facing the same problem with you. Can u teach me how to use the ioctl() function in C program.

    tq

Posting Permissions

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