⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 devls.c

📁 MIPS处理器的bootloader,龙芯就是用的修改过的PMON2
💻 C
字号:
/*	$Id: devls.c,v 1.4 2003/08/13 19:08:02 pefo Exp $ *//* * Copyright (c) 2001 Opsycon AB  (www.opsycon.se) *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by Opsycon AB, Sweden. * 4. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */#include <stdio.h>#include <string.h>#include <stdlib.h>#include <sys/device.h>#include <sys/queue.h>#include <sys/socket.h>#include <sys/socketvar.h>#include <net/if.h>#include <net/if_dl.h>#include <net/if_types.h>#include <net/radix.h>#include <net/route.h>#include <netinet/in.h>#include <netinet/in_var.h>#include <netinet/if_ether.h>#include <pmon.h>/* *  List known devices. */int cmd_devls(int, char *[]);void printnetinfo(char *);char *devclass[] = {	"DULL", "CPU", "DISK", "IFNET", "TAPE", "TTY"};intcmd_devls(ac, av)	int ac;	char *av[];{extern int optind;//extern char *optarg;	int	opt_a = 0;	int	opt_n = 0;	int	c;	struct device *dev, *next_dev;	optind = 0;	while((c = getopt(ac, av, "an")) != EOF) {		switch(c) {		case 'a':		/* Show network devices */			opt_a = 1;			break;		case 'n':		/* Show network devices */			opt_n = 1;			break;		default:			return(-1);	/* catch -p when not enabled */		}	}	if(optind < ac) {		return(-1);	/* Argument error */	}	printf("Name   Type   Info\n");	for (dev  = TAILQ_FIRST(&alldevs); dev != NULL; dev = next_dev) {		next_dev = TAILQ_NEXT(dev, dv_list);		if(!opt_a && dev->dv_class < DV_DISK) {			continue;		}		printf("%-6s %-7s", dev->dv_xname, devclass[dev->dv_class]);		if (dev->dv_class == DV_IFNET) {			printnetinfo(dev->dv_xname);		}		printf("\n");	}	return(1);}voidprintnetinfo(char * name){	struct ifnet *ifp;	struct ifaddr *ifa;	struct arpcom *arpcomp;	ifp = ifunit(name);	arpcomp = (struct arpcom *)ifp;	if (!ifp) {		printf("not available");		return;	}	printf("%-5sea=%-18s", (ifp->if_flags & IFF_UP ? "up" : "down"),		ether_sprintf(arpcomp->ac_enaddr));	for (ifa = ifp->if_addrlist.tqh_first; ifa;	    ifa = ifa->ifa_list.tqe_next) {		if (ifa->ifa_addr->sa_family == AF_INET)			printf("ip=%s",		inet_ntoa(((struct sockaddr_in *)ifa->ifa_addr)->sin_addr));	}}/* *  Command table registration *  ========================== */const Optdesc cmd_devls_opts[] = {	{ "-a",	"show all device types" },	{ "-n",	"show network devices" },	{ 0 }};static const Cmd Cmds[] ={	{"Misc"},	{"devls",	"[-an]",			cmd_devls_opts,			"list devices",			cmd_devls, 1, 99,			0},	{0, 0}};static void init_cmd __P((void)) __attribute__ ((constructor));voidinit_cmd(){	cmdlist_expand(Cmds, 1);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -