This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Retrieve the IP address.
- From: "David Miras" <david dot miras at sogeti dot com>
- To: <ecos-discuss at ecos dot sourceware dot org>
- Date: Mon, 2 Jul 2007 17:55:49 +0200
- Subject: [ECOS] Retrieve the IP address.
Hi,
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
FRANCE
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