status.c revision 158882
1178476Sjb 2178476Sjb/* 3178476Sjb * status.c 4178476Sjb * 5178476Sjb * Copyright (c) 1996-1999 Whistle Communications, Inc. 6178476Sjb * All rights reserved. 7178476Sjb * 8178476Sjb * Subject to the following obligations and disclaimer of warranty, use and 9178476Sjb * redistribution of this software, in source or object code forms, with or 10178476Sjb * without modifications are expressly permitted by Whistle Communications; 11178476Sjb * provided, however, that: 12178476Sjb * 1. Any and all reproductions of the source or object code must include the 13178476Sjb * copyright notice above and the following disclaimer of warranties; and 14178476Sjb * 2. No rights are granted, in any manner or form, to use Whistle 15178476Sjb * Communications, Inc. trademarks, including the mark "WHISTLE 16178476Sjb * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 17178476Sjb * such appears in the above copyright notice or in the software. 18178476Sjb * 19178476Sjb * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 20178476Sjb * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 21178476Sjb * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 22178476Sjb * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 23178476Sjb * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 24178476Sjb * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 25178476Sjb * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 26178476Sjb * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 27178476Sjb * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 28178476Sjb * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 29178476Sjb * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 30178476Sjb * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 31178476Sjb * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32178476Sjb * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33178476Sjb * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34178476Sjb * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35178476Sjb * OF SUCH DAMAGE. 36178476Sjb * 37178476Sjb * $FreeBSD: head/usr.sbin/ngctl/status.c 158882 2006-05-24 14:46:55Z glebius $ 38178476Sjb */ 39178476Sjb 40178476Sjb#include <err.h> 41178476Sjb#include <errno.h> 42#include <netgraph.h> 43#include <stdio.h> 44 45#include "ngctl.h" 46 47#define NOSTATUS "<no status>" 48 49static int StatusCmd(int ac, char **av); 50 51const struct ngcmd status_cmd = { 52 StatusCmd, 53 "status <path>", 54 "Get human readable status information from the node at <path>", 55 NULL, 56 {} 57}; 58 59static int 60StatusCmd(int ac, char **av) 61{ 62 u_char sbuf[sizeof(struct ng_mesg) + NG_TEXTRESPONSE]; 63 struct ng_mesg *const resp = (struct ng_mesg *) sbuf; 64 char *const status = (char *) resp->data; 65 char *path; 66 int nostat = 0; 67 68 /* Get arguments */ 69 switch (ac) { 70 case 2: 71 path = av[1]; 72 break; 73 default: 74 return(CMDRTN_USAGE); 75 } 76 77 /* Get node status summary */ 78 if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, 79 NGM_TEXT_STATUS, NULL, 0) < 0) { 80 switch (errno) { 81 case EINVAL: 82 nostat = 1; 83 break; 84 default: 85 warn("send msg"); 86 return(CMDRTN_ERROR); 87 } 88 } else { 89 if (NgRecvMsg(csock, resp, sizeof(sbuf), NULL) < 0 90 || (resp->header.flags & NGF_RESP) == 0) 91 nostat = 1; 92 } 93 94 /* Show it */ 95 if (nostat) 96 printf("No status available for \"%s\"\n", path); 97 else 98 printf("Status for \"%s\":\n%s\n", path, status); 99 return(CMDRTN_OK); 100} 101 102