public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Retrieve the IP address.
@ 2007-07-02 16:01 David Miras
  0 siblings, 0 replies; only message in thread
From: David Miras @ 2007-07-02 16:01 UTC (permalink / raw)
  To: ecos-discuss

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-07-02 16:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-02 16:01 [ECOS] Retrieve the IP address David Miras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).