162473Sphk/* 262473Sphk * config.c 362473Sphk * 462473Sphk * Copyright (c) 1996-1999 Whistle Communications, Inc. 562473Sphk * All rights reserved. 662473Sphk * 762473Sphk * Subject to the following obligations and disclaimer of warranty, use and 862473Sphk * redistribution of this software, in source or object code forms, with or 962473Sphk * without modifications are expressly permitted by Whistle Communications; 1062473Sphk * provided, however, that: 1162473Sphk * 1. Any and all reproductions of the source or object code must include the 1262473Sphk * copyright notice above and the following disclaimer of warranties; and 1362473Sphk * 2. No rights are granted, in any manner or form, to use Whistle 1462473Sphk * Communications, Inc. trademarks, including the mark "WHISTLE 1562473Sphk * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 1662473Sphk * such appears in the above copyright notice or in the software. 1762473Sphk * 1862473Sphk * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 1962473Sphk * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 2062473Sphk * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 2162473Sphk * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 2262473Sphk * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 2362473Sphk * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 2462473Sphk * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 2562473Sphk * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 2662473Sphk * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 2762473Sphk * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 2862473Sphk * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 2962473Sphk * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 3062473Sphk * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 3162473Sphk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3262473Sphk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3362473Sphk * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 3462473Sphk * OF SUCH DAMAGE. 3562473Sphk * 3662473Sphk * $FreeBSD$ 3762473Sphk */ 3862473Sphk 39158882Sglebius#include <err.h> 40158882Sglebius#include <errno.h> 41158882Sglebius#include <netgraph.h> 42158882Sglebius#include <stdio.h> 43158882Sglebius#include <string.h> 44158882Sglebius#include <unistd.h> 45158882Sglebius 4662473Sphk#include "ngctl.h" 4762473Sphk 4862473Sphk#define NOCONFIG "<no config>" 4962473Sphk 5062473Sphkstatic int ConfigCmd(int ac, char **av); 5162473Sphk 5262473Sphkconst struct ngcmd config_cmd = { 5362473Sphk ConfigCmd, 5462473Sphk "config <path> [arguments]", 5562473Sphk "get or set configuration of node at <path>", 56125011Sru NULL, 57160423Sstefanf { NULL } 5862473Sphk}; 5962473Sphk 6062473Sphkstatic int 6162473SphkConfigCmd(int ac, char **av) 6262473Sphk{ 6362473Sphk u_char sbuf[sizeof(struct ng_mesg) + NG_TEXTRESPONSE]; 6462473Sphk struct ng_mesg *const resp = (struct ng_mesg *) sbuf; 6562473Sphk char *const status = (char *) resp->data; 6662473Sphk char *path; 6762473Sphk char buf[NG_TEXTRESPONSE]; 6863673Sarchie int nostat = 0, i; 6962473Sphk 7062473Sphk /* Get arguments */ 7162473Sphk if (ac < 2) 72160002Sglebius return (CMDRTN_USAGE); 7362473Sphk path = av[1]; 7462473Sphk 7562473Sphk *buf = '\0'; 7662473Sphk for (i = 2; i < ac; i++) { 7762473Sphk if (i != 2) 7862473Sphk strcat(buf, " "); 7962473Sphk strcat(buf, av[i]); 8062473Sphk } 8162473Sphk 8262473Sphk /* Get node config summary */ 8362473Sphk if (*buf != '\0') 8462473Sphk i = NgSendMsg(csock, path, NGM_GENERIC_COOKIE, 8562473Sphk NGM_TEXT_CONFIG, buf, strlen(buf) + 1); 8662473Sphk else 8762473Sphk i = NgSendMsg(csock, path, NGM_GENERIC_COOKIE, 8862473Sphk NGM_TEXT_CONFIG, NULL, 0); 8962473Sphk if (i < 0) { 9062473Sphk switch (errno) { 9162473Sphk case EINVAL: 9262473Sphk nostat = 1; 9362473Sphk break; 9462473Sphk default: 9562473Sphk warn("send msg"); 96160002Sglebius return (CMDRTN_ERROR); 9762473Sphk } 9862473Sphk } else { 9962473Sphk if (NgRecvMsg(csock, resp, sizeof(sbuf), NULL) < 0 10062473Sphk || (resp->header.flags & NGF_RESP) == 0) 10162473Sphk nostat = 1; 10262473Sphk } 10362473Sphk 10462473Sphk /* Show it */ 10562473Sphk if (nostat) 10662473Sphk printf("No config available for \"%s\"\n", path); 10762473Sphk else 10862473Sphk printf("Config for \"%s\":\n%s\n", path, status); 109160002Sglebius return (CMDRTN_OK); 11062473Sphk} 11162473Sphk 112