ifcmds.c revision 108684
1108684Sphk/*
2108684Sphk * Copyright (c) 2003, Trent Nelson, <trent@arpa.com>.
3108684Sphk * All rights reserved.
4108684Sphk *
5108684Sphk * Redistribution and use in source and binary forms, with or without
6108684Sphk * modification, are permitted provided that the following conditions
7108684Sphk * are met:
8108684Sphk * 1. Redistributions of source code must retain the above copyright
9108684Sphk *    notice, this list of conditions and the following disclaimer.
10108684Sphk * 2. Redistributions in binary form must reproduce the above copyright
11108684Sphk *    notice, this list of conditions and the following disclaimer in the
12108684Sphk *    documentation and/or other materials provided with the distribution.
13108684Sphk * 3. The name of the author may not be used to endorse or promote products
14108684Sphk *    derived from this software without specific prior written permission.
15108684Sphk *
16108684Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17108684Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18108684Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19108684Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20108684Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21108684Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22108684Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23108684Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24108684Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25108684Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26108684Sphk * SUCH DAMAGE.
27108684Sphk *
28108684Sphk * $FreeBSD: head/usr.bin/systat/ifcmds.c 108684 2003-01-04 22:07:24Z phk $
29108684Sphk */
30108684Sphk
31108684Sphk#include <sys/types.h>
32108684Sphk#include <sys/socket.h>
33108684Sphk#include <sys/sysctl.h>
34108684Sphk#include <sys/time.h>
35108684Sphk#include <sys/queue.h>
36108684Sphk#include <net/if.h>
37108684Sphk#include <net/if_mib.h>
38108684Sphk#include <net/if_types.h>	/* For IFT_ETHER */
39108684Sphk
40108684Sphk#include <stdio.h>
41108684Sphk#include <stdlib.h>
42108684Sphk#include <unistd.h>
43108684Sphk#include <float.h>
44108684Sphk#include <err.h>
45108684Sphk
46108684Sphk#include "systat.h"
47108684Sphk#include "extern.h"
48108684Sphk#include "mode.h"
49108684Sphk#include "convtbl.h"
50108684Sphk
51108684Sphkint	curscale = SC_AUTO;
52108684Sphk
53108684Sphkstatic	int selectscale(const char *);
54108684Sphk
55108684Sphkint
56108684Sphkifcmd(const char *cmd, const char *args)
57108684Sphk{
58108684Sphk	if (prefix((char *)cmd, (char *)"scale")) {
59108684Sphk		if (*args != '\0' && selectscale(args) != -1)
60108684Sphk			;
61108684Sphk		else {
62108684Sphk			move(CMDLINE, 0);
63108684Sphk			clrtoeol();
64108684Sphk			addstr("what scale? kbit, kbyte, mbit, mbyte, " \
65108684Sphk			       "gbit, gbyte, auto");
66108684Sphk		}
67108684Sphk	}
68108684Sphk	return 1;
69108684Sphk}
70108684Sphk
71108684Sphkstatic int
72108684Sphkselectscale(const char *args)
73108684Sphk{
74108684Sphk	int	retval = 0;
75108684Sphk
76108684Sphk#define streq(a,b)	(strcmp(a,b) == 0)
77108684Sphk	if (streq(args, "default") || streq(args, "auto"))
78108684Sphk		curscale = SC_AUTO;
79108684Sphk	else if (streq(args, "kbit"))
80108684Sphk		curscale = SC_KILOBIT;
81108684Sphk	else if (streq(args, "kbyte"))
82108684Sphk		curscale = SC_KILOBYTE;
83108684Sphk	else if (streq(args, "mbit"))
84108684Sphk		curscale = SC_MEGABIT;
85108684Sphk	else if (streq(args, "mbyte"))
86108684Sphk		curscale = SC_MEGABYTE;
87108684Sphk	else if (streq(args, "gbit"))
88108684Sphk		curscale = SC_GIGABIT;
89108684Sphk	else if (streq(args, "gbyte"))
90108684Sphk		curscale = SC_GIGABYTE;
91108684Sphk	else
92108684Sphk		retval = -1;
93108684Sphk
94108684Sphk	return retval;
95108684Sphk}
96