help getting ip address in c code



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;
}

.



Relevant Pages