connect.c revision 158882
1204076Spjd
2204076Spjd/*
3219351Spjd * connect.c
4204076Spjd *
5204076Spjd * Copyright (c) 1996-1999 Whistle Communications, Inc.
6204076Spjd * All rights reserved.
7204076Spjd *
8204076Spjd * Subject to the following obligations and disclaimer of warranty, use and
9204076Spjd * redistribution of this software, in source or object code forms, with or
10204076Spjd * without modifications are expressly permitted by Whistle Communications;
11204076Spjd * provided, however, that:
12204076Spjd * 1. Any and all reproductions of the source or object code must include the
13204076Spjd *    copyright notice above and the following disclaimer of warranties; and
14204076Spjd * 2. No rights are granted, in any manner or form, to use Whistle
15204076Spjd *    Communications, Inc. trademarks, including the mark "WHISTLE
16204076Spjd *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
17204076Spjd *    such appears in the above copyright notice or in the software.
18204076Spjd *
19204076Spjd * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
20204076Spjd * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
21204076Spjd * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
22204076Spjd * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
23204076Spjd * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24204076Spjd * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
25204076Spjd * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
26204076Spjd * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
27204076Spjd * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
28204076Spjd * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
29204076Spjd * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30204076Spjd * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
31204076Spjd * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32204076Spjd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33204076Spjd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34204076Spjd * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35204076Spjd * OF SUCH DAMAGE.
36204076Spjd *
37204076Spjd * $FreeBSD: head/usr.sbin/ngctl/connect.c 158882 2006-05-24 14:46:55Z glebius $
38204076Spjd */
39204076Spjd
40204076Spjd#include <err.h>
41204076Spjd#include <netgraph.h>
42204076Spjd#include <stdio.h>
43204076Spjd
44204076Spjd#include "ngctl.h"
45204076Spjd
46204076Spjdstatic int ConnectCmd(int ac, char **av);
47204076Spjd
48211982Spjdconst struct ngcmd connect_cmd = {
49204076Spjd	ConnectCmd,
50204076Spjd	"connect [path] <relpath> <hook> <peerhook>",
51204076Spjd	"Connects hook <peerhook> of the node at <relpath> to <hook>",
52204076Spjd	"The connect command creates a link between the two nodes at"
53204076Spjd	" \"path\" and \"relpath\" using hooks \"hook\" and \"peerhook\","
54204076Spjd	" respectively. The \"relpath\", if not absolute, is specified"
55204076Spjd	" relative to the node at \"path\"."
56204076Spjd	" If \"path\" is omitted then \".\" is assumed.",
57204076Spjd	{ "join" }
58204076Spjd};
59204076Spjd
60212038Spjdstatic int
61204076SpjdConnectCmd(int ac, char **av)
62204076Spjd{
63204076Spjd	struct ngm_connect con;
64211886Spjd	const char *path = ".";
65204076Spjd
66204076Spjd	/* Get arguments */
67204076Spjd	switch (ac) {
68204076Spjd	case 5:
69204076Spjd		path = av[1];
70204076Spjd		ac--;
71210886Spjd		av++;
72210886Spjd		/* FALLTHROUGH */
73210886Spjd	case 4:
74204076Spjd		snprintf(con.path, sizeof(con.path), "%s", av[1]);
75204076Spjd		snprintf(con.ourhook, sizeof(con.ourhook), "%s", av[2]);
76204076Spjd		snprintf(con.peerhook, sizeof(con.peerhook), "%s", av[3]);
77204076Spjd		break;
78204076Spjd	default:
79204076Spjd		return(CMDRTN_USAGE);
80204076Spjd	}
81204076Spjd
82204076Spjd	/* Send message */
83204076Spjd	if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
84204076Spjd	    NGM_CONNECT, &con, sizeof(con)) < 0) {
85204076Spjd		warn("send msg");
86204076Spjd		return(CMDRTN_ERROR);
87204076Spjd	}
88204076Spjd	return(CMDRTN_OK);
89219818Spjd}
90204076Spjd
91204076Spjd