1 /*-
2 * Copyright (c) 2010-2011 Monthadar Al Jaberi, TerraNet AB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
15 *
16 * NO WARRANTY
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
28 */
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <fcntl.h>
32 #include <sys/ioctl.h>
33
34 /*
35 * From the driver itself
36 */
37 #include <plugins/visibility_ioctl.h>
38
39 static int dev = -1;
40
41 static void
toggle_medium(int op)42 toggle_medium(int op)
43 {
44 if (ioctl(dev, VISIOCTLOPEN, &op) < 0) {
45 printf("error opening/closing medium\n");
46 }
47 }
48
49 static void
link_op(struct link * l)50 link_op(struct link *l)
51 {
52 if (ioctl(dev, VISIOCTLLINK, l) < 0) {
53 printf("error making a link operation\n");
54 }
55 }
56
57 static void
usage(const char * argv[])58 usage(const char *argv[])
59 {
60 printf("usage: %s [o | c | [ [a|d] wtap_id1 wtap_id2]]\n",
61 argv[0]);
62 }
63
64 int
main(int argc,const char * argv[])65 main(int argc, const char* argv[])
66 {
67 struct link l;
68 char cmd;
69
70 if (argc < 2) {
71 usage(argv);
72 exit(1);
73 }
74
75 dev = open("/dev/visctl", O_RDONLY);
76 if (dev < 0) {
77 printf("error opening visctl cdev\n");
78 exit(1);
79 }
80
81 cmd = (char)*argv[1];
82
83 switch (cmd) {
84 case 'o':
85 toggle_medium(1);
86 break;
87 case 'c':
88 toggle_medium(0);
89 break;
90 case 'a':
91 if (argc < 4) {
92 usage(argv);
93 exit(1);
94 }
95 l.op = 1;
96 l.id1 = atoi(argv[2]);
97 l.id2 = atoi(argv[3]);
98 link_op(&l);
99 break;
100 case 'd':
101 if (argc < 4) {
102 usage(argv);
103 exit(1);
104 }
105 l.op = 0;
106 l.id1 = atoi(argv[2]);
107 l.id2 = atoi(argv[3]);
108 link_op(&l);
109 break;
110 default:
111 printf("wtap ioctl: unknown command '%c'\n", *argv[1]);
112 exit(1);
113 }
114 exit(0);
115 }
116