1f8307e12SArchie Cobbs 2f8307e12SArchie Cobbs /* 3f8307e12SArchie Cobbs * msg.c 4f8307e12SArchie Cobbs * 5f8307e12SArchie Cobbs * Copyright (c) 1999 Whistle Communications, Inc. 6f8307e12SArchie Cobbs * All rights reserved. 7f8307e12SArchie Cobbs * 8f8307e12SArchie Cobbs * Subject to the following obligations and disclaimer of warranty, use and 9f8307e12SArchie Cobbs * redistribution of this software, in source or object code forms, with or 10f8307e12SArchie Cobbs * without modifications are expressly permitted by Whistle Communications; 11f8307e12SArchie Cobbs * provided, however, that: 12f8307e12SArchie Cobbs * 1. Any and all reproductions of the source or object code must include the 13f8307e12SArchie Cobbs * copyright notice above and the following disclaimer of warranties; and 14f8307e12SArchie Cobbs * 2. No rights are granted, in any manner or form, to use Whistle 15f8307e12SArchie Cobbs * Communications, Inc. trademarks, including the mark "WHISTLE 16f8307e12SArchie Cobbs * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 17f8307e12SArchie Cobbs * such appears in the above copyright notice or in the software. 18f8307e12SArchie Cobbs * 19f8307e12SArchie Cobbs * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 20f8307e12SArchie Cobbs * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 21f8307e12SArchie Cobbs * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 22f8307e12SArchie Cobbs * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 23f8307e12SArchie Cobbs * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 24f8307e12SArchie Cobbs * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 25f8307e12SArchie Cobbs * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 26f8307e12SArchie Cobbs * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 27f8307e12SArchie Cobbs * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 28f8307e12SArchie Cobbs * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 29f8307e12SArchie Cobbs * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 30f8307e12SArchie Cobbs * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 31f8307e12SArchie Cobbs * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32f8307e12SArchie Cobbs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33f8307e12SArchie Cobbs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34f8307e12SArchie Cobbs * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35f8307e12SArchie Cobbs * OF SUCH DAMAGE. 36f8307e12SArchie Cobbs * 37f8307e12SArchie Cobbs * $Whistle: msg.c,v 1.2 1999/11/29 23:38:35 archie Exp $ 38f8307e12SArchie Cobbs * $FreeBSD$ 39f8307e12SArchie Cobbs */ 40f8307e12SArchie Cobbs 41f8307e12SArchie Cobbs #include "ngctl.h" 42f8307e12SArchie Cobbs 43f8307e12SArchie Cobbs #define BUF_SIZE 1024 44f8307e12SArchie Cobbs 45f8307e12SArchie Cobbs static int MsgCmd(int ac, char **av); 46f8307e12SArchie Cobbs 47f8307e12SArchie Cobbs const struct ngcmd msg_cmd = { 48f8307e12SArchie Cobbs MsgCmd, 49f8307e12SArchie Cobbs "msg path command [args ... ]", 50f8307e12SArchie Cobbs "Send a netgraph control message to the node at \"path\"", 51f8307e12SArchie Cobbs "The msg command constructs a netgraph control message from the" 52f8307e12SArchie Cobbs " command name and ASCII arguments (if any) and sends that message" 53f8307e12SArchie Cobbs " to the node. It does this by first asking the node to convert" 54f8307e12SArchie Cobbs " the ASCII message into binary format, and resending the result." 55f8307e12SArchie Cobbs " The typecookie used for the message is assumed to be the typecookie" 56f8307e12SArchie Cobbs " corresponding to the target node's type.", 57f8307e12SArchie Cobbs { "cmd" } 58f8307e12SArchie Cobbs }; 59f8307e12SArchie Cobbs 60f8307e12SArchie Cobbs static int 61f8307e12SArchie Cobbs MsgCmd(int ac, char **av) 62f8307e12SArchie Cobbs { 63f8307e12SArchie Cobbs char buf[BUF_SIZE]; 64f8307e12SArchie Cobbs char *path, *cmdstr; 65f8307e12SArchie Cobbs int i; 66f8307e12SArchie Cobbs 67f8307e12SArchie Cobbs /* Get arguments */ 68f8307e12SArchie Cobbs if (ac < 3) 69f8307e12SArchie Cobbs return(CMDRTN_USAGE); 70f8307e12SArchie Cobbs path = av[1]; 71f8307e12SArchie Cobbs cmdstr = av[2]; 72f8307e12SArchie Cobbs 73f8307e12SArchie Cobbs /* Put command and arguments back together as one string */ 74f8307e12SArchie Cobbs for (*buf = '\0', i = 3; i < ac; i++) { 75f8307e12SArchie Cobbs snprintf(buf + strlen(buf), 76f8307e12SArchie Cobbs sizeof(buf) - strlen(buf), " %s", av[i]); 77f8307e12SArchie Cobbs } 78f8307e12SArchie Cobbs 79f8307e12SArchie Cobbs /* Send it */ 80f8307e12SArchie Cobbs if (NgSendAsciiMsg(csock, path, "%s%s", cmdstr, buf) < 0) { 81f8307e12SArchie Cobbs warn("send msg"); 82f8307e12SArchie Cobbs return(CMDRTN_ERROR); 83f8307e12SArchie Cobbs } 84f8307e12SArchie Cobbs 85f8307e12SArchie Cobbs /* Done */ 86f8307e12SArchie Cobbs return(CMDRTN_OK); 87f8307e12SArchie Cobbs } 88f8307e12SArchie Cobbs 89