This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]