Example #1
0
        public Stream Open()
        {
            var descriptor = Syscall.open("/dev/net/tun", OpenFlags.O_RDWR);

            if (descriptor < 0)
            {
                logger.Error($"/dev/net/tun open error: ret: {descriptor}; LastError: {Marshal.GetLastWin32Error()}");
                return(null);
            }
            currentInterfaceInfo = new IfReq
            {
                Flags = tapIff | noPiIff
            };
            var ioctlRetCode = IoCtl(descriptor, 0x400454CA, ref currentInterfaceInfo);

            if (ioctlRetCode < 0)
            {
                logger.Error($"ioctl error: ret: {ioctlRetCode}; LastError: {Marshal.GetLastWin32Error()}");
                return(null);
            }
            currentPhysicalAddress = NetworkInterface.GetAllNetworkInterfaces().First(x => x.Description == currentInterfaceInfo.Name).GetPhysicalAddress();
            logger.Info($"Opened TAP device: FD #{descriptor}; Name '{currentInterfaceInfo.Name}'; HW address: {currentPhysicalAddress}");
            RenewDhcp(currentInterfaceInfo.Name);
            currentStream = new RawUnixStream(descriptor);
            return(currentStream);
        }
Example #2
0
 private static extern int IoCtl(int descriptor, uint request, ref IfReq ifreq);