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 * $FreeBSD$ 30 */ 31 #include <stdio.h> 32 #include <stdlib.h> 33 #include <fcntl.h> 34 #include <sys/ioctl.h> 35 36 #include "if_wtapioctl.h" 37 38 static int dev = -1; 39 40 static void create(int id) 41 { 42 if(ioctl(dev, WTAPIOCTLCRT, &id) < 0){ 43 printf("error creating wtap with id=%d\n", id); 44 } 45 } 46 47 static void delete(int id) 48 { 49 if(ioctl(dev, WTAPIOCTLDEL, &id) < 0){ 50 printf("error deleting wtap with id=%d\n", id); 51 } 52 } 53 54 int main( int argc, const char* argv[]) 55 { 56 if(argc != 3){ 57 printf("usage: %s [c | d] wtap_id\n", argv[0]); 58 return -1; 59 } 60 int id = atoi(argv[2]); 61 if(!(id >= 0 && id < 64)){ 62 printf("wtap_id must be between 0 and 7\n"); 63 return -1; 64 } 65 dev = open("/dev/wtapctl", O_RDONLY); 66 if(dev < 0){ 67 printf("error opening wtapctl cdev\n"); 68 return -1; 69 } 70 switch((char)*argv[1]){ 71 case 'c': 72 create(id); 73 break; 74 case 'd': 75 delete(id); 76 break; 77 default: 78 printf("wtap ioctl: unknown command '%c'\n", *argv[1]); 79 return -1; 80 } 81 return 0; 82 } 83