[ECOS] Retrieve the IP address.

David Miras david.miras@sogeti.com
Mon Jul 2 16:01:00 GMT 2007


I have a problem when I want to retrieve my IP address.

I use this program:

char *recup_ip(void) 
int s; 
char *ip; 
struct ifreq buffer; 
struct sockaddr_in inetAddr; 

s = socket (PF_INET, SOCK_DGRAM, 0); 
ip = (char *)malloc (16); 
memset (&buffer, 0, sizeof (buffer)); 
strcpy (buffer.ifr_name, "ppp0"); 
ioctl (s, SIOCGIFADDR, &buffer); 
memcpy (&inetAddr, &(buffer.ifr_addr), sizeof (struct sockaddr_in)); 
strcpy(ip, inet_ntoa(inetAddr.sin_addr)); 
shutdown (s, 2); 

return ip; 

Sometimes, my IP address isn't retrieved completely.
Example: ip="192.68.65"

Thank you for your answer.

Best Regards.
David MIRAS 
Sogeti High Tech
485 Avenue de l'Europe
38330 Montbonnot Saint-Martin
email: david.miras@sogeti.com

Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

More information about the Ecos-discuss mailing list