Esempio n. 1
0
        public unsafe bool add(string interfaceName, string vlanid)
        {
            vlan_ioctl_args ifrequest = new vlan_ioctl_args();

            ifrequest.cmd     = (int)vlan_ioctl_cmds.ADD_VLAN_CMD;
            ifrequest.device1 = new char[24];
            //ifrequest.device1 = (interfaceName/*+"\0"*/).ToCharArray() ;
            char[] interfaceNameCharArray = interfaceName.ToCharArray();
            Array.Copy(interfaceNameCharArray, ifrequest.device1, interfaceNameCharArray.Length);
            ifrequest.VID = int.Parse(vlanid);
            //AF_INET = 1, SOCK_STREAM = 1
            int fd = socket(1, 1, 1);           //UnixAddressFamily.AF_INET,UnixSocketType.SOCK_STREAM,  UnixSocketProtocol.SOL_SOCKET);

            if (fd == -1)
            {
                throw new Exception("Fuckup couldnt open socket");
            }

            //IntPtr requestPointer = Marshal.AllocHGlobal(Marshal.SizeOf(ifrequest));
            //Marshal.StructureToPtr (ifrequest, requestPointer, true);

            //if (ioctl (fd, SIOCSIFVLAN,requestPointer) < 0) {
            if (ioctl(fd, SIOCSIFVLAN, ref ifrequest) < 0)
            {
                Console.WriteLine("Couldn't add vlan:" + vlanid + " to interface " + interfaceName);
                return(false);
            }
            else
            {
                Console.WriteLine("Added VLAN " + interfaceName + "." + vlanid);
                return(true);
            }
        }
Esempio n. 2
0
        public bool rem(string interfaceName)
        {
            vlan_ioctl_args ifrequest = new vlan_ioctl_args();

            ifrequest.cmd     = (int)vlan_ioctl_cmds.DEL_VLAN_CMD;
            ifrequest.device1 = interfaceName.ToCharArray();
            //ifrequest.VID = int.Parse (vlanid);

            int fd = socket(1, 1, 1);             //UnixAddressFamily.AF_INET,UnixSocketType.SOCK_STREAM,  UnixSocketProtocol.SOL_SOCKET);

            if (fd == -1)
            {
                throw new Exception("Fuckup couldnt open socket");
            }

            //IntPtr requestPointer = new IntPtr ();
            //Marshal.StructureToPtr (ifrequest, requestPointer, true);

            if (ioctl(fd, SIOCSIFVLAN, ref ifrequest) < 0)
            {
                Console.WriteLine("Couldn't rem vlan:" + interfaceName);
                return(false);
            }
            else
            {
                Console.WriteLine("Removed VLAN " + interfaceName);
                return(true);
            }
        }
Esempio n. 3
0
 static extern int ioctl(int __fd, int dunnoWTF, ref vlan_ioctl_args __request);