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 ...
- 11-23-2006 #1Just 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
- 11-23-2006 #2Just 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
- 11-23-2006 #3Linux 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
- 11-23-2006 #4Just Joined!
- Join Date
- Nov 2006
- Posts
- 17
Yes but not inside a C program, thats why i had to use the ioctl() function
Originally Posted by Skiboy
- 02-15-2007 #5Just Joined!
- Join Date
- Feb 2007
- Posts
- 1
Originally Posted by md_lasalle
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


Reply With Quote
