BUG or feature in SIOCGIFMETRIC

Richard B. Johnson (root@chaos.analogic.com)
Wed, 8 Dec 1999 13:21:30 -0500 (EST)


The included source shows that the SIOCGIFMETRIC ioctl returns 0
while the metric value returned by `ifconfig` returns 1.

Review of the ifconfig.c source shows that a hack like the following
is the reason why `ifconfig` returns 1.

ptr->metric?ptr->metric:1 (line 190)

#include <stdio.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <string.h>
#include <linux/netdevice.h>
#include <linux/if.h>
#include <linux/if_arp.h>
#include <linux/if_ether.h>

int main()
{
struct ifreq ifr;
int s;
if((s = socket(AF_INET, SOCK_DGRAM, 0)) <0)
{
perror("socket()");
exit(EXIT_FAILURE);
}
memset(&ifr, 0x00, sizeof(ifr));
strcpy(ifr.ifr_name, "eth0");
if(ioctl(s, SIOCGIFMETRIC, &ifr))
{
perror("ioctl()");
exit(EXIT_FAILURE);
}
printf("Metric = %d\n", ifr.ifr_metric);
return 0;
}

So; Is this ioctl being fixed or will `ifconfig` always remain hacked?
It is not very useful for a function to return a value that has to be
"adjusted" if it happens to be a certain value. Any adjustment should
have been made within the function itself.

Cheers,
Dick Johnson

Penguin : Linux version 2.3.13 on an i686 machine (400.59 BogoMips).
Warning : The end of the world as we know it requires a new calendar.
Seconds : 2025510 (until Y2K)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/