Networking Forums

Networking Forums > Computer Networking > Linux Networking > Remove entry from /proc/net/dev

Reply
Thread Tools Display Modes

Remove entry from /proc/net/dev

 
 
Rohan Romanus Almeida
Guest
Posts: n/a

 
      08-17-2003, 07:42 AM

Hi,

After I up an(y) interface, an entry is
made in /proc/net/dev

Any idea how to remove the entry from
/proc/net/dev after I down the respective
interface?

I tried all kinda stunts, but the only
one which works is the faithful reboot!

--
arc_of_descent

 
Reply With Quote
 
 
 
 
beltorak
Guest
Posts: n/a

 
      08-17-2003, 03:23 PM
Rohan Romanus Almeida <(E-Mail Removed)> wrote in message news:<(E-Mail Removed) et>...
> Hi,
>
> After I up an(y) interface, an entry is
> made in /proc/net/dev
>
> Any idea how to remove the entry from
> /proc/net/dev after I down the respective
> interface?
>


modprobe -r

btw; why would you want to do that?

-t?
 
Reply With Quote
 
Rohan Romanus Almeida
Guest
Posts: n/a

 
      08-17-2003, 04:39 PM

/dev/rob0 <(E-Mail Removed)> thus wrote:
> Did you try "rmmod $INTERFACE_DRIVER"? This will not work if the driver
> is compiled-in.
>
> I'm guessing you're using /proc/net/dev to try to accomplish something.
> If you tell us what that is, we might be able to suggest another
> approach.


I'm using /proc/net/dev to monitor the bandwidth consumption
of all interfaces.

<publicity level="blatant">
Its a utility which I've coded, called ibmonitor.
http://ibmonitor.sourceforge.net
</publicity>

I'm facing a problem (inconvenience, actually) with
interfaces (like ppp0), which over a long period
of time, fluctuate up || down quite frequently.

What i wanted was that, if an interface goes down,
shouldn't the entry vanish in /proc/net/dev ?
Or do I have to monitor the output of `ifconfig` command?

--
arc_of_descent






 
Reply With Quote
 
/dev/rob0
Guest
Posts: n/a

 
      08-17-2003, 05:47 PM
In article <(E-Mail Removed)> ,
Rohan Romanus Almeida wrote:
> What i wanted was that, if an interface goes down,
> shouldn't the entry vanish in /proc/net/dev ?
> Or do I have to monitor the output of `ifconfig` command?


Well, since ifconfig reads somewhere in /proc for its information, you
would likely do best doing the same. Note that when an interface goes
down its routing table (/proc/net/route) entry is removed. You could
look in the ifconfig source to find from whence it reads interface
status flags.
--
/dev/rob0 - preferred_email=i$((28*28+28))@softhome.net
or put "not-spam" or "/dev/rob0" in Subject header to reply
 
Reply With Quote
 
Floyd Davidson
Guest
Posts: n/a

 
      08-18-2003, 02:27 AM
/dev/rob0 <(E-Mail Removed)> wrote:
>In article <(E-Mail Removed)> ,
> Rohan Romanus Almeida wrote:
>> What i wanted was that, if an interface goes down,
>> shouldn't the entry vanish in /proc/net/dev ?
>> Or do I have to monitor the output of `ifconfig` command?

>
>Well, since ifconfig reads somewhere in /proc for its information, you
>would likely do best doing the same. Note that when an interface goes


Ifconfig uses ioctl commands to obtain information.

If the OP needs a shell script, just using ifconfig and grep
will tell if a given interface is up or not:

#!/bin/sh
#
if [ $# -ne 1 ]; then
echo "No interface specified."
exit 6
fi

if ifconfig | grep -q "^${1}" ; then
echo -e "$1\t is up."
exit 0
fi

echo -e "$1\t is down."
exit 1

Note also that ifconfig with no arguments tells if the interface
is up, while "ifconfig -a", or "ifconfig interface_name" also
shows interfaces that have been configured but are currently
down.

If the OP needs a C program it isn't doesn't take much more.

>down its routing table (/proc/net/route) entry is removed. You could
>look in the ifconfig source to find from whence it reads interface
>status flags.


True, but it is a bit convoluted (to put it mildly) and trying
to figure out exactly how it works from netlib is probably not
the easiest way. The easy way... is google (of course). There
have been many examples posted. The C program below, while not
in exactly the same form provided this time, has been posted a
dozen times.

This is a program which demonstrates how to either get all
interfaces that are configured and up, or how to specify a
single interface and determine its status. Note that unlike
ifconfig, there is no way to distinguish between a previously
configured interface that is now down and one that has never
been configured at all or is non-existant.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <arpa/inet.h>

#define inaddrr(x) (*(struct in_addr *) &ifr->x[sizeof sa.sin_port])
#define IFRSIZE ((int)(size * sizeof (struct ifreq)))

int main(int argc, char *argv[])
{
int sockfd, size = 1;
struct sockaddr_in sa;
struct ifconf ifc;
struct ifreq *ifr;

if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) {
perror("socket");
exit(EXIT_FAILURE);
}

/* look for just one interface */
if (argv[1] && argv[1][0] ) {
struct ifreq ifreq;
struct sockaddr_in *sin = (struct sockaddr_in *)&ifreq.ifr_addr;

ifr = &ifreq;
memset(ifr, 0, sizeof *ifr);
strcpy(ifr->ifr_name, argv[1]);

/*
* this is unnecessary, and shown only to demonstrate that
* the SIOCGIFFLAGS ioctl command indicates whether the
* interface is up or down. (The SIOCGIFADDR command does
* likewise.)
*/
if (0 != ioctl(sockfd, SIOCGIFFLAGS, ifr)) {
printf("%-7s: is down\n", ifr->ifr_name);
}

if (0 == ioctl(sockfd, SIOCGIFADDR, ifr)) {
printf("%-7s: %s\n", ifr->ifr_name, inet_ntoa(sin->sin_addr));
exit(EXIT_SUCCESS);
}
exit(EXIT_FAILURE);
}

/* list all interfaces that are up */
ifc.ifc_len = IFRSIZE;
ifc.ifc_req = NULL;

do {
++size;
/* realloc buffer size until no overflow occurs */
if (NULL == (ifc.ifc_req = realloc(ifc.ifc_req, IFRSIZE))) {
fprintf(stderr, "Out of memory.\n");
exit(EXIT_FAILURE);
}
ifc.ifc_len = IFRSIZE;
if (ioctl(sockfd, SIOCGIFCONF, &ifc)) {
perror("ioctl SIOCFIFCONF");
exit(EXIT_FAILURE);
}
} while (IFRSIZE <= ifc.ifc_len);

ifr = ifc.ifc_req;
for (;(char *) ifr < (char *) ifc.ifc_req + ifc.ifc_len; ++ifr) {
if (!ioctl(sockfd, SIOCGIFFLAGS, ifr)) {
printf("%-7s: %s\n", ifr->ifr_name, inet_ntoa(inaddrr(ifr_addr.sa_data)));
}
}

return EXIT_SUCCESS;
}

--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is tw at /proc/net/sockstat?! bh98013@gmail.com Linux Networking 3 06-06-2006 10:38 AM
iptables problem (proc) Maaged Mazyek Linux Networking 3 03-28-2006 05:39 AM
Write on proc filesystem ValerioZ Linux Networking 3 02-09-2005 10:46 PM
/proc/net/ip_fprward?? Ishwar Rattan Linux Networking 4 07-17-2003 02:41 AM
/proc/net/ip_fprward?? Ishwar Rattan Linux Networking 1 07-16-2003 08:53 PM



1 2 3 4 5 6 7 8 9 10 11