public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] network interfaces
@ 2005-11-24 10:26 Bass8tt8
  2005-11-24 10:35 ` Gary Thomas
  2005-11-24 13:48 ` Andrew Lunn
  0 siblings, 2 replies; 3+ messages in thread
From: Bass8tt8 @ 2005-11-24 10:26 UTC (permalink / raw)
  To: ecos-discuss

Hi,

i have a function ( on Linux work well ) that get the list and the numbers
of network interfaces excluding the LOOPBACK INTERFACE, but on ecos this
dosn't work  :
for debugging i print the name of interface finded : printf ("scheda_lan :
%s\n",ifReq.ifr_name);
but "eth0" there isn't ...  and this function return me always 0 !

Ps: in Main () i do init_all_network_interfaces() !

************************************************  CODE
*********************************************

int ILibGetLocalIPAddressList(int** pp_int)
{
 char szBuffer[16*sizeof(struct ifreq)];
 struct ifconf ifConf;
 struct ifreq ifReq;
 int nResult;
 int LocalSock;
 struct sockaddr_in LocalAddr;
 int tempresults[16];
 int ctr=0;
 int i;

 // Create an unbound datagram socket to do the SIOCGIFADDR ioctl on.
 if ((LocalSock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
 {
  DEBUGSTATEMENT(printf("Can't do that\r\n"));
  //exit(1);
 }
 /// Get the interface configuration information...
 ifConf.ifc_len = sizeof szBuffer;
 ifConf.ifc_ifcu.ifcu_buf = (caddr_t)szBuffer;
 nResult = ioctl(LocalSock, SIOCGIFCONF, &ifConf);
 if (nResult < 0)
 {
  DEBUGSTATEMENT(printf("ioctl error\r\n"));
  //exit(1);
 }
 // Cycle through the list of interfaces looking for IP addresses.
 for (i = 0;(i < ifConf.ifc_len);)
 {
  struct ifreq *pifReq = (struct ifreq *)((caddr_t)ifConf.ifc_req + i);
  i += sizeof *pifReq;
  // See if this is the sort of interface we want to deal with.
  strcpy (ifReq.ifr_name, pifReq -> ifr_name);

  ------>>>>    printf ("scheda_lan : %s\n",ifReq.ifr_name);

  if (ioctl (LocalSock, SIOCGIFFLAGS, &ifReq) < 0)
  {
   DEBUGSTATEMENT(printf("Can't get flags\r\n"));
   //exit(1);
  }
  /* Skip loopback, point-to-point and down interfaces, */
  /* except don't skip down interfaces */
  /* if we're trying to get a list of configurable interfaces.
  if ((ifReq.ifr_flags & IFF_LOOPBACK) || (!(ifReq.ifr_flags & IFF_UP)))
  {
   continue;
  }
  if (pifReq -> ifr_addr.sa_family == AF_INET)
  {
   /* Get a pointer to the address...
   memcpy (&LocalAddr, &pifReq -> ifr_addr, sizeof pifReq -> ifr_addr);
   if (LocalAddr.sin_addr.s_addr != htonl (INADDR_LOOPBACK))
   {
    tempresults[ctr] = LocalAddr.sin_addr.s_addr;
    ++ctr;
   }
  }
 }

 close(LocalSock);
 *pp_int = (int*)malloc(sizeof(int)*(ctr));
 memcpy(*pp_int,tempresults,sizeof(int)*ctr);

 return(ctr);
#endif
}


Thanks Michele


-- 
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] 3+ messages in thread

* Re: [ECOS] network interfaces
  2005-11-24 10:26 [ECOS] network interfaces Bass8tt8
@ 2005-11-24 10:35 ` Gary Thomas
  2005-11-24 13:48 ` Andrew Lunn
  1 sibling, 0 replies; 3+ messages in thread
From: Gary Thomas @ 2005-11-24 10:35 UTC (permalink / raw)
  To: Bass8tt8; +Cc: eCos Discussion

On Thu, 2005-11-24 at 11:26 +0100, Bass8tt8 wrote:
> Hi,
> 
> i have a function ( on Linux work well ) that get the list and the numbers
> of network interfaces excluding the LOOPBACK INTERFACE, but on ecos this
> dosn't work  :
> for debugging i print the name of interface finded : printf ("scheda_lan :
> %s\n",ifReq.ifr_name);
> but "eth0" there isn't ...  and this function return me always 0 !

Walking through the results of SIOCGIFCONF is a bit tricky.

Try looking at some eCos code that uses this API, e.g.
  .../packages/net/common/current/src/ifaddrs.c

-- 
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------


-- 
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] 3+ messages in thread

* Re: [ECOS] network interfaces
  2005-11-24 10:26 [ECOS] network interfaces Bass8tt8
  2005-11-24 10:35 ` Gary Thomas
@ 2005-11-24 13:48 ` Andrew Lunn
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2005-11-24 13:48 UTC (permalink / raw)
  To: Bass8tt8; +Cc: ecos-discuss

On Thu, Nov 24, 2005 at 11:26:25AM +0100, Bass8tt8 wrote:
> Hi,
> 
> i have a function ( on Linux work well ) that get the list and the numbers
> of network interfaces excluding the LOOPBACK INTERFACE, but on ecos this
> dosn't work  :

The network stack in eCos is from FreeBSD. So working on Linux does
not tell you that much....

As Gary suggested, try looking at some code which is known to work...

        Andrew

-- 
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] 3+ messages in thread

end of thread, other threads:[~2005-11-24 13:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-24 10:26 [ECOS] network interfaces Bass8tt8
2005-11-24 10:35 ` Gary Thomas
2005-11-24 13:48 ` Andrew Lunn

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).