Bringing down ethernet
Charles Steaderman
charlies at poliac.com
Fri Mar 28 19:02:49 UTC 2003
Is there a simple function for bringing down and ethernet port? I tried
using something like:
short flags = ~IFF_UP;
rtems_bsdnet_ifconfig ("eth0", SIOCGIFFLAGS, &flags);
but when I traced throught the rtems_bsdnet_ifconfig source it appears
that you can only ADD flags, but never DELETE them. Is this correct? I
ended up copying a source snippet from rtems_bsdnet_ifconfig which looks
as follows:
int ifDown(const char* sIfName)
{
int status = 0;
int s, r = 0;
struct ifreq ifreq;
s = socket (AF_INET, SOCK_DGRAM, 0);
if (s < 0)
return(-1);
strncpy (ifreq.ifr_name, sIfName, IFNAMSIZ);
rtems_bsdnet_semaphore_obtain ();
if ((r = ioctl (s, SIOCGIFFLAGS, &ifreq)) < 0)
status = -1;
if(status == 0)
{
ifreq.ifr_flags &= ~IFF_UP;
r = ioctl (s, SIOCSIFFLAGS, &ifreq);
}
rtems_bsdnet_semaphore_release ();
close (s);
return status;
}
but I didn't like having to expose myself to such low level code. Any
comments would be appreciated.
- Charlie
More information about the users
mailing list