152419Sjulian 252419Sjulian/* 352419Sjulian * types.c 452419Sjulian * 552419Sjulian * Copyright (c) 1996-1999 Whistle Communications, Inc. 652419Sjulian * All rights reserved. 752419Sjulian * 852419Sjulian * Subject to the following obligations and disclaimer of warranty, use and 952419Sjulian * redistribution of this software, in source or object code forms, with or 1052419Sjulian * without modifications are expressly permitted by Whistle Communications; 1152419Sjulian * provided, however, that: 1252419Sjulian * 1. Any and all reproductions of the source or object code must include the 1352419Sjulian * copyright notice above and the following disclaimer of warranties; and 1452419Sjulian * 2. No rights are granted, in any manner or form, to use Whistle 1552419Sjulian * Communications, Inc. trademarks, including the mark "WHISTLE 1652419Sjulian * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 1752419Sjulian * such appears in the above copyright notice or in the software. 1852419Sjulian * 1952419Sjulian * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 2052419Sjulian * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 2152419Sjulian * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 2252419Sjulian * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 2352419Sjulian * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 2452419Sjulian * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 2552419Sjulian * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 2652419Sjulian * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 2752419Sjulian * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 2852419Sjulian * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 2952419Sjulian * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 3052419Sjulian * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 3152419Sjulian * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 3252419Sjulian * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3352419Sjulian * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3452419Sjulian * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 3552419Sjulian * OF SUCH DAMAGE. 3652419Sjulian * 3752419Sjulian * $FreeBSD$ 3852419Sjulian */ 3952419Sjulian 40158882Sglebius#include <err.h> 41158882Sglebius#include <netgraph.h> 42158882Sglebius#include <stdio.h> 43158882Sglebius#include <stdlib.h> 44158882Sglebius#include <unistd.h> 45158882Sglebius 4652419Sjulian#include "ngctl.h" 4752419Sjulian 4852419Sjulianstatic int TypesCmd(int ac, char **av); 4952419Sjulian 5052419Sjulianconst struct ngcmd types_cmd = { 5152419Sjulian TypesCmd, 5252419Sjulian "types", 5352419Sjulian "Show information about all installed node types", 54125011Sru NULL, 55160423Sstefanf { NULL } 5652419Sjulian}; 5752419Sjulian 5852419Sjulianstatic int 59125011SruTypesCmd(int ac, char **av __unused) 6052419Sjulian{ 61125115Sru struct ng_mesg *resp; 62125115Sru struct typelist *tlist; 63125011Sru int rtn = CMDRTN_OK; 64125011Sru u_int k; 6552419Sjulian 6652419Sjulian /* Get arguments */ 6752419Sjulian switch (ac) { 6852419Sjulian case 1: 6952419Sjulian break; 7052419Sjulian default: 71160002Sglebius return (CMDRTN_USAGE); 7252419Sjulian } 7352419Sjulian 7452419Sjulian /* Get list of types */ 7552419Sjulian if (NgSendMsg(csock, ".", NGM_GENERIC_COOKIE, 7652419Sjulian NGM_LISTTYPES, NULL, 0) < 0) { 7752419Sjulian warn("send msg"); 78160002Sglebius return (CMDRTN_ERROR); 7952419Sjulian } 80125115Sru if (NgAllocRecvMsg(csock, &resp, NULL) < 0) { 8152419Sjulian warn("recv msg"); 82160002Sglebius return (CMDRTN_ERROR); 8352419Sjulian } 8452419Sjulian 8552419Sjulian /* Show each type */ 86125115Sru tlist = (struct typelist *) resp->data; 8752419Sjulian printf("There are %d total types:\n", tlist->numtypes); 8852419Sjulian if (tlist->numtypes > 0) { 8952419Sjulian printf("%15s Number of living nodes\n", "Type name"); 9052419Sjulian printf("%15s ----------------------\n", "---------"); 9152419Sjulian } 9252419Sjulian for (k = 0; k < tlist->numtypes; k++) { 9352419Sjulian struct typeinfo *const ti = &tlist->typeinfo[k]; 9459880Sarchie printf("%15s %5d\n", ti->type_name, ti->numnodes); 9552419Sjulian } 9652419Sjulian 9752419Sjulian /* Done */ 98125115Sru free(resp); 9952419Sjulian return (rtn); 10052419Sjulian} 10152419Sjulian 102