Hello,
i am curretly writing a program in C, which should run under linux AND
windows, where i want to send data over the WLAN interface.
To bind a socket to this interface i need its IP address.
i started to develop on linux where i am using the "ioctl(sock,
SIOCGIFADDR, & ifreq)" function and probe for different interface names
like "eth1", "ath0", "wlan0" and so on.
But now i want to port the program to windows and there the ioctl
function is not working as i read in
http://www.faqs.org/faqs/windows/winsock-faq/
to solve this problem i tried to use gethostname() which gives me the
right host name, and pass this to gethostbyname(). but this only
returns the localhost address (which i already know is 127.0.0.1 :-@ )
here is the source code, can anybody tell me WHY there are not the ip
addresses of the other interfaces??? (and, by the way, can anybody tell
me how to find out which address, only in case that i get them in the
future, belongs to the WLAN interface??)
networking()
{
struct in_addr *addrPtr = 0;
struct hostent *hoststruct;
char * host_name;
int host_name_len = 256;
gethostname(host_name, host_name_len);
hoststruct = gethostbyname(host_name);
printf("Host name : %s\n", hoststruct->h_name);
printf("IP Address : %s\n", inet_ntoa(*((struct in_addr
*)hoststruct->h_addr)));
while((addrPtr = (struct in_addr *) *hoststruct->h_addr_list++))
printf("Internet address is %s\n", inet_ntoa(*addrPtr));
}