166458Sdfr/*- 266458Sdfr * Copyright (c) 2010-2011 Monthadar Al Jaberi, TerraNet AB 366458Sdfr * All rights reserved. 4141085Simp * 566458Sdfr * Redistribution and use in source and binary forms, with or without 666458Sdfr * modification, are permitted provided that the following conditions 766458Sdfr * are met: 866458Sdfr * 1. Redistributions of source code must retain the above copyright 966458Sdfr * notice, this list of conditions and the following disclaimer, 1066458Sdfr * without modification. 1166458Sdfr * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1266458Sdfr * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 1366458Sdfr * redistribution must be conditioned upon including a substantially 1466458Sdfr * similar Disclaimer requirement for further binary redistribution. 1566458Sdfr * 1666458Sdfr * NO WARRANTY 1766458Sdfr * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1866458Sdfr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1966458Sdfr * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 2066458Sdfr * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 2166458Sdfr * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 2266458Sdfr * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2366458Sdfr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2466458Sdfr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 2566458Sdfr * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2666458Sdfr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 2766458Sdfr * THE POSSIBILITY OF SUCH DAMAGES. 2866458Sdfr * 2966458Sdfr * $FreeBSD: releng/10.3/tools/tools/wtap/wtap/wtap.c 229972 2012-01-11 17:51:56Z adrian $ 3066458Sdfr */ 3166458Sdfr#include <stdio.h> 3266458Sdfr#include <stdlib.h> 3366458Sdfr#include <fcntl.h> 3466458Sdfr#include <sys/ioctl.h> 3566458Sdfr 3666458Sdfr#include "if_wtapioctl.h" 3766458Sdfr 3866458Sdfrstatic int dev = -1; 3966458Sdfr 4066458Sdfrstatic void create(int id) 4166458Sdfr{ 4266458Sdfr if(ioctl(dev, WTAPIOCTLCRT, &id) < 0){ 4366458Sdfr printf("error creating wtap with id=%d\n", id); 4466458Sdfr } 4566458Sdfr} 46209618Smarcel 47134287Smarcelstatic void delete(int id) 48134287Smarcel{ 49134287Smarcel if(ioctl(dev, WTAPIOCTLDEL, &id) < 0){ 50134287Smarcel printf("error deleting wtap with id=%d\n", id); 51134287Smarcel } 52134287Smarcel} 5366458Sdfr 54134287Smarcelint main( int argc, const char* argv[]) 5566458Sdfr{ 5666458Sdfr if(argc != 3){ 5766458Sdfr printf("usage: %s [c | d] wtap_id\n", argv[0]); 5866633Sdfr return -1; 5966458Sdfr } 6066458Sdfr int id = atoi(argv[2]); 6166458Sdfr if(!(id >= 0 && id < 64)){ 6266633Sdfr printf("wtap_id must be between 0 and 7\n"); 6366458Sdfr return -1; 64198338Smarcel } 6566458Sdfr dev = open("/dev/wtapctl", O_RDONLY); 6666458Sdfr if(dev < 0){ 67134287Smarcel printf("error opening wtapctl cdev\n"); 6866458Sdfr return -1; 6966458Sdfr } 7066633Sdfr switch((char)*argv[1]){ 7166458Sdfr case 'c': 72198338Smarcel create(id); 7366458Sdfr break; 7466458Sdfr case 'd': 7566458Sdfr delete(id); 7666458Sdfr break; 7766458Sdfr default: 7866633Sdfr printf("wtap ioctl: unkown command '%c'\n", *argv[1]); 7966458Sdfr return -1; 8066458Sdfr } 8166633Sdfr return 0; 82198338Smarcel} 8366458Sdfr