public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Grant Edwards <grante@visi.com>
To: Nick Barnes <Nick.Barnes@pobox.com>
Cc: bartv@redhat.com, ecos-discuss@sourceware.cygnus.com
Subject: Re: [ECOS] Notes on static configuration of an eCos network interface
Date: Tue, 18 Jul 2000 08:03:00 -0000	[thread overview]
Message-ID: <20000718150357.A2075@visi.com> (raw)
In-Reply-To: <145.963924726@raven.ravenbrook.com>

On Tue, Jul 18, 2000 at 01:52:06PM +0100, Nick Barnes wrote:

> > Instead you could have an upper bound on the number of such routes and
> > have the appropriate number of config options. Or you could put
> > multiple routes into one configuration value, although extracting all
> > the information at compile-time can then prove tricky. Alternatively
> > the configury would support only the most common situation of a single
> > route, with an opt-out to defer the whole thing to application code.
> > I am not sure which of these approaches would be most appropriate in
> > this case.
> 
> Either way.  This isn't very important to me.
> 
> Another option would be to have a single string option for additional
> static routes, which is then parsed in network_support.c.
> 
> It's an interesting problem.  As other writers have pointed out,
> there's a case for taking this out of the kernel configuration
> altogether.  

It's handy having a default configuration when writing test
programs, but my real applications will all configure the
network "manually", since I don't know until run-time whether
to use bootp/DHCP or not.

> For my project I'm now intending to use the ioctl()s
> directly, and never call init_all_network_interfaces().

Yesterday I changed over to calling the ioctl()s directly.  So
far it seems to be working. The eCos system is trying to use
the router I configure, but I don't have one on the network
right now, so I've got to set up one of my Linux machines as a
router to make sure.

FWIW, here's the init code I'm using:


void StackInit( void )
{
  int s,rc;
  struct sockaddr_in *addrp;
  struct ifreq ifr;
  int one = 1;
  struct ecos_rtentry route;
#ifdef MTM_NET_DEBUG
  extern int net_debug;
  net_debug = 1;
#endif
  
  if ( DhcpData.MyIpAddr == 0 )   // not gonna do ip
    return;  

  s = socket(AF_INET, SOCK_DGRAM, 0);
  
  if (s < 0)
    {
      diag_printf("socket: %d\n",s);
      return;
    }

  if ((rc=setsockopt(s, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one))))
    {
      diag_printf("setsockopt: %d\n",rc);
      close(s);
      return;
    }
  
  strcpy(ifr.ifr_name, "eth0");
  
  addrp = (struct sockaddr_in *) &ifr.ifr_addr;

  memset(addrp, 0, sizeof(*addrp));
  addrp->sin_family = AF_INET;
  addrp->sin_len = sizeof(*addrp);
  addrp->sin_port = 0;
  
  addrp->sin_addr.s_addr = DhcpData.MyIpAddr;
  if ((rc=ioctl(s, SIOCSIFADDR, &ifr)))
    {
      diag_printf("SIOCSIFADDR: %d\n",rc);
      close(s);
      return;
    }
  
  addrp->sin_addr.s_addr = DhcpData.SubnetMask;
  if ((rc=ioctl(s, SIOCSIFNETMASK, &ifr))) 
    {
      diag_printf("SIOCSIFNETMASK: %d\n",rc);
      close(s);
      return;
    }

  addrp->sin_addr.s_addr =  ~DhcpData.SubnetMask | DhcpData.Subnet;
  if ((rc=ioctl(s, SIOCSIFBRDADDR, &ifr)))
    {
      diag_printf("SIOCSIFBRDADDR: %d\n",rc);
      close(s);
      return;
    }

  // Set up routing
  
  diag_printf("   IP = %08x\n", DhcpData.MyIpAddr);
  diag_printf(" Mask = %08x\n", DhcpData.SubnetMask);
  diag_printf(" Gate = %08x\n", DhcpData.Gateways[0]);
  
  memset(&route, 0, sizeof(route));
  
  addrp->sin_addr.s_addr = 0;
  memcpy(&route.rt_dst, addrp, sizeof(*addrp));
  memcpy(&route.rt_genmask, addrp, sizeof(*addrp));
  
  addrp->sin_addr.s_addr = DhcpData.Gateways[0];
  memcpy(&route.rt_gateway, addrp, sizeof(*addrp));
  
  route.rt_dev = ifr.ifr_name;
  route.rt_flags = RTF_UP|RTF_GATEWAY;
  route.rt_metric = 0;
  
  if ((rc=ioctl(s, SIOCADDRT, &route)))
    diag_printf("Route Failed: %d\n",rc);
  else
    {
      diag_printf("Net init complete.\n");
      StackOk = 1;
    }
  close(s);
}


-- 
Grant Edwards
grante@visi.com

  reply	other threads:[~2000-07-18  8:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-17  5:45 Nick Barnes
2000-07-17  6:59 ` Bart Veer
2000-07-17  7:07   ` [ECOS] Notes on static configuration of an eCos network inte Gary Thomas
2000-07-18  5:52   ` [ECOS] Notes on static configuration of an eCos network interface Nick Barnes
2000-07-18  8:03     ` Grant Edwards [this message]
2000-07-17  8:52 ` Grant Edwards
2000-07-17  9:03   ` [ECOS] Notes on static configuration of an eCos network inte Gary Thomas
2000-07-17  9:28     ` Andrew Lunn
2000-07-17  9:40       ` Grant Edwards
2000-07-17  9:47         ` Andrew Lunn
2000-07-17  9:29     ` Grant Edwards
2000-07-17  9:45       ` Gary Thomas
2000-07-17 10:01         ` Grant Edwards
2000-07-17  9:45   ` [ECOS] Notes on static configuration of an eCos network interface Hugo 'NOx' Tyson
2000-07-20  7:00 ` Hugo 'NOx' Tyson
2000-07-20  9:57   ` Bart Veer
2000-07-20 11:00     ` Hugo 'NOx' Tyson
2000-07-20 11:19       ` Bart Veer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20000718150357.A2075@visi.com \
    --to=grante@visi.com \
    --cc=Nick.Barnes@pobox.com \
    --cc=bartv@redhat.com \
    --cc=ecos-discuss@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).