config.c revision 125011
1139776Simp/*
21541Srgrimes * config.c
31541Srgrimes *
41541Srgrimes * Copyright (c) 1996-1999 Whistle Communications, Inc.
51541Srgrimes * All rights reserved.
61541Srgrimes *
71541Srgrimes * Subject to the following obligations and disclaimer of warranty, use and
81541Srgrimes * redistribution of this software, in source or object code forms, with or
91541Srgrimes * without modifications are expressly permitted by Whistle Communications;
101541Srgrimes * provided, however, that:
111541Srgrimes * 1. Any and all reproductions of the source or object code must include the
121541Srgrimes *    copyright notice above and the following disclaimer of warranties; and
131541Srgrimes * 2. No rights are granted, in any manner or form, to use Whistle
141541Srgrimes *    Communications, Inc. trademarks, including the mark "WHISTLE
151541Srgrimes *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
161541Srgrimes *    such appears in the above copyright notice or in the software.
171541Srgrimes *
181541Srgrimes * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
191541Srgrimes * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
201541Srgrimes * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
211541Srgrimes * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
221541Srgrimes * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
231541Srgrimes * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
241541Srgrimes * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
251541Srgrimes * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
261541Srgrimes * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
271541Srgrimes * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
281541Srgrimes * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
291541Srgrimes * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
301541Srgrimes * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
311541Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3222521Sdyson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
331541Srgrimes * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
3422521Sdyson * OF SUCH DAMAGE.
3522521Sdyson *
3622521Sdyson * $FreeBSD: head/usr.sbin/ngctl/config.c 125011 2004-01-26 10:27:18Z ru $
3722521Sdyson */
3822521Sdyson
3950477Speter#include "ngctl.h"
401541Srgrimes
411541Srgrimes#define NOCONFIG	"<no config>"
421541Srgrimes
431541Srgrimesstatic int ConfigCmd(int ac, char **av);
441541Srgrimes
4577130Sruconst struct ngcmd config_cmd = {
461541Srgrimes	ConfigCmd,
4796755Strhodes	"config <path> [arguments]",
481541Srgrimes	"get or set configuration of node at <path>",
4996755Strhodes	NULL,
501541Srgrimes	{}
5135256Sdes};
521541Srgrimes
531541Srgrimesstatic int
541541SrgrimesConfigCmd(int ac, char **av)
551541Srgrimes{
5696755Strhodes	u_char sbuf[sizeof(struct ng_mesg) + NG_TEXTRESPONSE];
571541Srgrimes	struct ng_mesg *const resp = (struct ng_mesg *) sbuf;
581541Srgrimes	char *const status = (char *) resp->data;
5996755Strhodes	char *path;
601541Srgrimes	char buf[NG_TEXTRESPONSE];
611541Srgrimes	int nostat = 0, i;
621541Srgrimes
631541Srgrimes	/* Get arguments */
641541Srgrimes	if (ac < 2)
651541Srgrimes		return(CMDRTN_USAGE);
661541Srgrimes	path = av[1];
671541Srgrimes
6877130Sru	*buf = '\0';
6977130Sru	for (i = 2; i < ac; i++) {
701541Srgrimes		if (i != 2)
711541Srgrimes			strcat(buf, " ");
721541Srgrimes		strcat(buf, av[i]);
731541Srgrimes	}
741541Srgrimes
751541Srgrimes	/* Get node config summary */
761541Srgrimes	if (*buf != '\0')
771541Srgrimes		i = NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
7896755Strhodes	            NGM_TEXT_CONFIG, buf, strlen(buf) + 1);
791541Srgrimes	else
801541Srgrimes		i = NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
8126963Salex	            NGM_TEXT_CONFIG, NULL, 0);
821541Srgrimes	if (i < 0) {
831541Srgrimes		switch (errno) {
841541Srgrimes		case EINVAL:
851541Srgrimes			nostat = 1;
861541Srgrimes			break;
871541Srgrimes		default:
881541Srgrimes			warn("send msg");
891541Srgrimes			return(CMDRTN_ERROR);
901541Srgrimes		}
911541Srgrimes	} else {
9222521Sdyson		if (NgRecvMsg(csock, resp, sizeof(sbuf), NULL) < 0
9322521Sdyson		    || (resp->header.flags & NGF_RESP) == 0)
9422521Sdyson			nostat = 1;
9522521Sdyson	}
9622521Sdyson
971541Srgrimes	/* Show it */
9822521Sdyson	if (nostat)
9922521Sdyson		printf("No config available for \"%s\"\n", path);
10022521Sdyson	else
10122521Sdyson		printf("Config for \"%s\":\n%s\n", path, status);
10222521Sdyson	return(CMDRTN_OK);
10322521Sdyson}
10422521Sdyson
10522521Sdyson