types.c revision 160423
1327952Sdim 2193326Sed/* 3353358Sdim * types.c 4353358Sdim * 5353358Sdim * Copyright (c) 1996-1999 Whistle Communications, Inc. 6193326Sed * All rights reserved. 7193326Sed * 8193326Sed * Subject to the following obligations and disclaimer of warranty, use and 9193326Sed * redistribution of this software, in source or object code forms, with or 10193326Sed * without modifications are expressly permitted by Whistle Communications; 11193326Sed * provided, however, that: 12193326Sed * 1. Any and all reproductions of the source or object code must include the 13327952Sdim * copyright notice above and the following disclaimer of warranties; and 14193326Sed * 2. No rights are granted, in any manner or form, to use Whistle 15193326Sed * Communications, Inc. trademarks, including the mark "WHISTLE 16193326Sed * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 17219077Sdim * such appears in the above copyright notice or in the software. 18344779Sdim * 19193326Sed * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 20327952Sdim * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 21193326Sed * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 22219077Sdim * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 23327952Sdim * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 24327952Sdim * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 25327952Sdim * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 26327952Sdim * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 27327952Sdim * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 28327952Sdim * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 29327952Sdim * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 30327952Sdim * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 31193326Sed * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32327952Sdim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33193326Sed * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34327952Sdim * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35327952Sdim * OF SUCH DAMAGE. 36193326Sed * 37193326Sed * $FreeBSD: head/usr.sbin/ngctl/types.c 160423 2006-07-17 08:35:47Z stefanf $ 38193326Sed */ 39193326Sed 40218893Sdim#include <err.h> 41193326Sed#include <netgraph.h> 42193326Sed#include <stdio.h> 43193326Sed#include <stdlib.h> 44193326Sed#include <unistd.h> 45276479Sdim 46198092Srdivacky#include "ngctl.h" 47193326Sed 48193326Sedstatic int TypesCmd(int ac, char **av); 49314564Sdim 50314564Sdimconst struct ngcmd types_cmd = { 51193326Sed TypesCmd, 52193326Sed "types", 53193326Sed "Show information about all installed node types", 54193326Sed NULL, 55193326Sed { NULL } 56193326Sed}; 57193326Sed 58218893Sdimstatic int 59218893SdimTypesCmd(int ac, char **av __unused) 60193326Sed{ 61198092Srdivacky struct ng_mesg *resp; 62193326Sed struct typelist *tlist; 63193326Sed int rtn = CMDRTN_OK; 64193326Sed u_int k; 65219077Sdim 66193326Sed /* Get arguments */ 67193326Sed switch (ac) { 68193326Sed case 1: 69193326Sed break; 70193326Sed default: 71218893Sdim return (CMDRTN_USAGE); 72249423Sdim } 73249423Sdim 74193326Sed /* Get list of types */ 75198092Srdivacky if (NgSendMsg(csock, ".", NGM_GENERIC_COOKIE, 76276479Sdim NGM_LISTTYPES, NULL, 0) < 0) { 77276479Sdim warn("send msg"); 78193326Sed return (CMDRTN_ERROR); 79193326Sed } 80193326Sed if (NgAllocRecvMsg(csock, &resp, NULL) < 0) { 81280031Sdim warn("recv msg"); 82249423Sdim return (CMDRTN_ERROR); 83193326Sed } 84193326Sed 85193326Sed /* Show each type */ 86193326Sed tlist = (struct typelist *) resp->data; 87218893Sdim printf("There are %d total types:\n", tlist->numtypes); 88341825Sdim if (tlist->numtypes > 0) { 89219077Sdim printf("%15s Number of living nodes\n", "Type name"); 90219077Sdim printf("%15s ----------------------\n", "---------"); 91219077Sdim } 92276479Sdim for (k = 0; k < tlist->numtypes; k++) { 93276479Sdim struct typeinfo *const ti = &tlist->typeinfo[k]; 94219077Sdim printf("%15s %5d\n", ti->type_name, ti->numnodes); 95219077Sdim } 96219077Sdim 97280031Sdim /* Done */ 98219077Sdim free(resp); 99219077Sdim return (rtn); 100219077Sdim} 101219077Sdim 102219077Sdim