Local IP address

Till Straumann strauman at SLAC.Stanford.EDU
Mon Oct 20 16:45:40 UTC 2003


Richard M. Barry wrote:
> Thomas,
> I tried your code, but I get a compiler error: "sizeof applied to an incomplete type" for the rtems_bsdnet_config() line.  
>  

#include <rtems/rtems_bsdnet.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <netinet/in.h>
#include <net/if.h>
 

void
gifaddr(struct sockaddr_in *paddr)
{
   rtems_bsdnet_ifconfig("eth0", SIOCGIFADDR, paddr);
}


HTH
-- Till

> Richard
> 
> 	-----Original Message----- 
> 	From: Thomas Rauscher [mailto:trauscher at loytec.com] 
> 	Sent: Mon 20/10/2003 11:23 
> 	To: Richard M. Barry; rtems-users at rtems.com 
> 	Cc: 
> 	Subject: RE: Local IP address
> 	
> 	
> 
> 
> 
> 	> -----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