public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] setting static arp enteries in arp table
@ 2005-09-07  0:06 mkhoyila
  2005-09-07  9:09 ` Sébastien Couret
  0 siblings, 1 reply; 2+ messages in thread
From: mkhoyila @ 2005-09-07  0:06 UTC (permalink / raw)
  To: ecos-discuss

Hi all

I am using SmartBits to test the performance of my driver. I need to add
static arp entries in eCos arp table. how can I access arp table of eCos
and add static entries in there. Thanks.

Michael


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

* Re: [ECOS] setting static arp enteries in arp table
  2005-09-07  0:06 [ECOS] setting static arp enteries in arp table mkhoyila
@ 2005-09-07  9:09 ` Sébastien Couret
  0 siblings, 0 replies; 2+ messages in thread
From: Sébastien Couret @ 2005-09-07  9:09 UTC (permalink / raw)
  To: mkhoyila; +Cc: ecos-discuss

[-- Attachment #1: Type: text/plain, Size: 3233 bytes --]

Routing table handling could be done via ioctl calls.

Here's a routine i used to to this with Ecos FreeBSD TCP/IP stack (sorry, comments are in french )
But hope this helps anyway.


Note : 
My own defines and routines :
#define MACSTRING 18
#define IPSTRING 16
char* ether_print(const u_char cp[ETHER_ADDR_LEN], char *etheraddr,const unsigned int len)
{
 snprintf(etheraddr,len,"%02x:%02x:%02x:%02x:%02x:%02x",cp[0],cp[1],cp[2],cp[3],cp[4],cp[5]);
 return(etheraddr);
}


The main sub-routine :
int AddMAC(const char* dest,const char* gateway,const int index)
{
 struct sockaddr_dl gway;		// Adresse passerelle
 struct sockaddr_in dst;		// Réseau/hote cible

 char ds[IPSTRING];
 struct ecos_rtentry *rt=NULL;		// Entrée dans la table de routage
 int s=0;				// Descripteur de socket
 u_char cp[MACSTRING];			// Adresse MAC sous forme chaine

 memset(&gway,0,sizeof(struct sockaddr_dl));
 gway.sdl_family=AF_LINK; // AF_UNSPEC ?
 gway.sdl_len=sizeof(struct sockaddr_dl);
 gway.sdl_index=index;
 gway.sdl_type=IFT_ETHER;  
 gway.sdl_alen=ETHER_ADDR_LEN;
 memcpy(gway.sdl_data,gateway,ETHER_ADDR_LEN);

 memset(&dst,0,sizeof(struct sockaddr_in));
 dst.sin_family=AF_INET;
 dst.sin_port=0;
 dst.sin_len=sizeof(struct sockaddr_in);
 dst.sin_addr.s_addr=inet_addr(dest);

 rt=(struct ecos_rtentry*)malloc(sizeof(struct ecos_rtentry));
 if (!rt)
 {
  diag_printf("Erreur d'allocation d'une route :'%s'",strerror(errno));
  return(-1);
 }
 memset(rt,0,sizeof(struct ecos_rtentry));
 rt->rt_flags|=RTF_LLINFO;
 rt->rt_flags|=RTF_HOST; // Host entry
 memcpy(&(rt->rt_gateway), &gway, sizeof(struct sockaddr));
 memcpy(&(rt->rt_dst), &dst, sizeof(struct sockaddr_in));

 rt->rt_flags|=RTF_UP; // Route utilisable
// rt->rt_flags|=RTF_WAS_CLONED;
 //rt->rt_use=0;
 rt->rt_dev=NULL;
 rt->rt_metric=1;		// Reseau local
 strncpy(ds,inet_ntoa(dst.sin_addr),IPSTRING);
 ether_print((u_char*)gateway,(char*)cp,MACSTRING);
 diag_printf("Ajout d'une adresse MAC  pour '%s' :'%s' sur interface eth%d",ds,cp,index-1);
 s=socket(AF_INET,SOCK_DGRAM,0);
 if (s<0)
 {
  diag_printf("Socket error :'%s'",strerror(errno));
  free(rt);
  return(-1);
 }
 if (ioctl(s,SIOCADDRT,rt)<0)
 {
  diag_printf("Ioctl error :'%s'",strerror(errno));
  switch (errno)
  {
   case EINVAL:diag_printf("Invalid Command or agument");
	  break;
   case ENOTTY:diag_printf("Not a device");
	  break;
   case EBADF:diag_printf("Bad File descriptor");
	  break;
   case EEXIST:diag_printf("Already existing");
	   break;
   default:diag_printf("Unknown error %d:'%s'",errno,strerror(errno));
  }
  free(rt);
  close(s);
  return (-1);
 }
 diag_printf("ARP entry added");
 free(rt);
 close(s);
 return(0);
}


On Tue, 6 Sep 2005 17:09:36 -0700 (PDT)
mkhoyila@uci.edu wrote:

> Hi all
> 
> I am using SmartBits to test the performance of my driver. I need to add
> static arp entries in eCos arp table. how can I access arp table of eCos
> and add static entries in there. Thanks.
> 
> Michael
> 
> 
> -- 
> Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
> and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
> 
> 


-- 

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-09-07  9:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-07  0:06 [ECOS] setting static arp enteries in arp table mkhoyila
2005-09-07  9:09 ` Sébastien Couret

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