finding ip addr from a c prog

ismitevijay's Avatar, Join Date: Aug 2006
Light Poster
hi all;
i hav written a code in c for finding ip:


int main()
	struct ifreq ifr;
	char buf[30];
	int fd;
	strcpy(buf,inet_ntoa(((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr));
	printf(" %s",buf);
	return 0;
but i m getting err as :
ip.c: In function ‘main’:
ip.c:15: error: ‘struct ifreq’ has no member named ‘if_name

tell me wat i m missisng

Last edited by shabbir; 28Aug2006 at 20:42.. Reason: Code formating.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
if_name is not a member of ifreq structure.

The structure contains 128 bytes which has the following members
Code: C
union {
   sockaddr   ifru_addr
   sockaddr   ifru_dstaddr
   sockaddr   ifru_broadaddr
   short   ifru_flags
   int   ifru_metric
   caddr_t   ifru_data