Remove entry from /proc/net/dev

Discussion in 'Linux Networking' started by Rohan Romanus Almeida, Aug 17, 2003.

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

    I tried all kinda stunts, but the only
    one which works is the faithful reboot!
    Rohan Romanus Almeida, Aug 17, 2003
    1. Advertisements

  2. Rohan Romanus Almeida

    beltorak Guest

    modprobe -r

    btw; why would you want to do that?

    beltorak, Aug 17, 2003
    1. Advertisements

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

    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?
    Rohan Romanus Almeida, Aug 17, 2003
  4. Rohan Romanus Almeida

    /dev/rob0 Guest

    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, Aug 17, 2003
  5. 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:

    if [ $# -ne 1 ]; then
    echo "No interface specified."
    exit 6

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

    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

    If the OP needs a C program it isn't doesn't take much more.
    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))) {

    /* 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));

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

    do {
    /* realloc buffer size until no overflow occurs */
    if (NULL == (ifc.ifc_req = realloc(ifc.ifc_req, IFRSIZE))) {
    fprintf(stderr, "Out of memory.\n");
    ifc.ifc_len = IFRSIZE;
    if (ioctl(sockfd, SIOCGIFCONF, &ifc)) {
    perror("ioctl SIOCFIFCONF");
    } 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 Davidson, Aug 18, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.