Local IP address

Thomas Rauscher trauscher at loytec.com
Mon Oct 20 10:23:01 UTC 2003



> -----Original Message-----
> From: Richard M. Barry [mailto:R.Barry at sstl.co.uk]
> Sent: Monday, October 20, 2003 11:16 AM
> To: rtems-users at rtems.com
> Subject: Local IP address
> 
> 
> How can I get the local IP address (the server's address, not 
> the client's) in a server I'm running?  I want to do this 
> before any connections are made from a client.
> 
> Richard
> 

The following code should do it.
You just have to provide the correct interface name.

  struct sockaddr_in addr;                                                                                                                                   
  rtems_bsdnet_ifconfig("eth0", SIOCGIFADDR, &addr);                                                                                                         

The IP address is then in addr.sin_addr.s_addr .

Best regards,
Thomas Rauscher

--
Dipl.-Ing. Thomas Rauscher                 Tel.:   ++43 1 402 08 05 15
                                           Fax:    ++43 1 402 08 05 99
LOYTEC electronics GmbH                    E-mail: trauscher at loytec.com
Stolzenthalergasse 24/3, A-1080 Wien       Web:    http://www.loytec.com



More information about the users mailing list