Re: help getting ip address in c code
- From: none <""moma\"@(none)">
- Date: Wed, 28 Jun 2006 16:38:09 +0200
Hello,
Study Beej's guide to network programming
http://beej.us/guide/
and send your question to
news://comp.os.linux.development.apps
( news://comp.os.linux.development )
// moma
http://www.futuredesktop.com/opportunities.html
laclac01@xxxxxxxxx wrote:
have some code that is trying to get the IP address of interface eth0,.
when i complie it i get the following error
"getip.c: In function `main':
getip.c:9: error: storage size of `saddr' isn't known
getip.c:13: error: dereferencing pointer to incomplete type"
How can i get this to work? Or is there a better way to get the IP
address?
Here is the code
#include <linux/if.h>
#include <linux/if_tun.h>
#include <linux/ioctl.h>
int main()
{
int fd;
struct ifreq ifr;
struct sockaddr_in saddr;
fd=socket(PF_INET,SOCK_STREAM,0);
strcpy(ifr.ifr_name,"eth0");
ioctl(fd, SIOCGIFADDR,&ifr);
saddr=*((struct sockaddr_in *)(&(ifr.ifr_addr)));
return 0;
}
- References:
- help getting ip address in c code
- From: laclac01
- help getting ip address in c code
- Prev by Date: help getting ip address in c code
- Next by Date: Re: Dumb news readers
- Previous by thread: help getting ip address in c code
- Index(es):
Relevant Pages
|