help getting ip address in c code
- From: laclac01@xxxxxxxxx
- Date: 28 Jun 2006 06:47:55 -0700
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;
}
.
- Follow-Ups:
- Re: help getting ip address in c code
- From: none
- Re: help getting ip address in c code
- Prev by Date: Re: Dumb news readers
- Next by Date: Re: help getting ip address in c code
- Previous by thread: What are the issue for
- Next by thread: Re: help getting ip address in c code
- Index(es):
Relevant Pages
|