ifcmds.c revision 126775
189674Sarchie/*
289674Sarchie * Copyright (c) 2003, Trent Nelson, <trent@arpa.com>.
389674Sarchie * All rights reserved.
489674Sarchie *
589674Sarchie * Redistribution and use in source and binary forms, with or without
689674Sarchie * modification, are permitted provided that the following conditions
789674Sarchie * are met:
889674Sarchie * 1. Redistributions of source code must retain the above copyright
989674Sarchie *    notice, this list of conditions and the following disclaimer.
1089674Sarchie * 2. Redistributions in binary form must reproduce the above copyright
1189674Sarchie *    notice, this list of conditions and the following disclaimer in the
1289674Sarchie *    documentation and/or other materials provided with the distribution.
1389674Sarchie * 3. The name of the author may not be used to endorse or promote products
1489674Sarchie *    derived from this software without specific prior written permission.
1589674Sarchie *
1689674Sarchie * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1789674Sarchie * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1889674Sarchie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1989674Sarchie * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2089674Sarchie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2189674Sarchie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2289674Sarchie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2389674Sarchie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2489674Sarchie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2589674Sarchie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2689674Sarchie * SUCH DAMAGE.
2789674Sarchie *
2889674Sarchie * $FreeBSD: head/usr.bin/systat/ifcmds.c 126775 2004-03-09 11:57:28Z dwmalone $
2989674Sarchie */
3089674Sarchie
3189674Sarchie#include <sys/types.h>
3289674Sarchie#include <sys/socket.h>
3389674Sarchie#include <sys/sysctl.h>
3489674Sarchie#include <sys/time.h>
3589674Sarchie#include <sys/queue.h>
36158882Sglebius#include <net/if.h>
37158882Sglebius#include <net/if_mib.h>
38158882Sglebius#include <net/if_types.h>	/* For IFT_ETHER */
39158882Sglebius
40158882Sglebius#include <stdio.h>
41158882Sglebius#include <stdlib.h>
42158882Sglebius#include <string.h>
43158882Sglebius#include <unistd.h>
44158882Sglebius#include <float.h>
45158882Sglebius#include <err.h>
4689674Sarchie
4789674Sarchie#include "systat.h"
4889674Sarchie#include "extern.h"
4989674Sarchie#include "mode.h"
5089674Sarchie#include "convtbl.h"
5189674Sarchie
5289674Sarchieint	curscale = SC_AUTO;
5389674Sarchie
5489674Sarchiestatic	int selectscale(const char *);
5589674Sarchie
5689674Sarchieint
5789674Sarchieifcmd(const char *cmd, const char *args)
5889674Sarchie{
5989674Sarchie	if (prefix(cmd, "scale")) {
6089674Sarchie		if (*args != '\0' && selectscale(args) != -1)
6189674Sarchie			;
6289674Sarchie		else {
6389674Sarchie			move(CMDLINE, 0);
6489674Sarchie			clrtoeol();
6589674Sarchie			addstr("what scale? kbit, kbyte, mbit, mbyte, " \
6689674Sarchie			       "gbit, gbyte, auto");
6789674Sarchie		}
6889674Sarchie	}
6989674Sarchie	return 1;
7089674Sarchie}
7189674Sarchie
7289674Sarchiestatic int
7389674Sarchieselectscale(const char *args)
7489674Sarchie{
75160002Sglebius	int	retval = 0;
7689674Sarchie
7789674Sarchie#define streq(a,b)	(strcmp(a,b) == 0)
7889674Sarchie	if (streq(args, "default") || streq(args, "auto"))
7989674Sarchie		curscale = SC_AUTO;
8089674Sarchie	else if (streq(args, "kbit"))
81160002Sglebius		curscale = SC_KILOBIT;
8289674Sarchie	else if (streq(args, "kbyte"))
8389674Sarchie		curscale = SC_KILOBYTE;
84160002Sglebius	else if (streq(args, "mbit"))
8589674Sarchie		curscale = SC_MEGABIT;
8689674Sarchie	else if (streq(args, "mbyte"))
8789674Sarchie		curscale = SC_MEGABYTE;
8889674Sarchie	else if (streq(args, "gbit"))
8989674Sarchie		curscale = SC_GIGABIT;
9089674Sarchie	else if (streq(args, "gbyte"))
9189674Sarchie		curscale = SC_GIGABYTE;
92160002Sglebius	else
9389674Sarchie		retval = -1;
9489674Sarchie
9589674Sarchie	return retval;
9689674Sarchie}
9789674Sarchie