Networking Forums

Networking Forums > Computer Networking > Linux Networking > extract ip address from WLAN interface, programming in C

Reply
Thread Tools Display Modes

extract ip address from WLAN interface, programming in C

 
 
burn
Guest
Posts: n/a

 
      06-18-2005, 06:06 PM
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));

}

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Receiving neighbor advertisement to extract link-layer (MAC) address pdbuchan@yahoo.com Linux Networking 0 11-19-2011 03:02 AM
Command for assigning IPv6 address and MAC address on the interface iceman Linux Networking 7 03-03-2008 07:51 PM
Wlan design: access point vs. wlan interface no_one_reads_it@gmx.net Linux Networking 0 09-17-2006 03:42 PM
WLAN interface vanishes!! Spare Brain Linux Networking 4 09-13-2005 01:26 PM
PROGRAMMING MY WIRELESS INTERFACE in linux sam1967 Wireless Internet 2 06-08-2005 06:49 AM



1 2 3 4 5 6 7 8 9 10 11