Beispiel #1
0
        public FileStream Open(NetworkInterface networkInterface, IPAddressConfiguration address, DeviceConfiguration configuration)
        {
            var bufferSize = configuration.BufferSize ?? 4096;
            var handle     = CreateFile(@"\\.\Global\" + networkInterface.Id + ".tap",
                                        WinFileAccess.GenericRead | WinFileAccess.GenericWrite,
                                        0,
                                        IntPtr.Zero,
                                        WinFileCreation.OpenExisting,
                                        WinFileAttributes.System | WinFileAttributes.Overlapped,
                                        IntPtr.Zero
                                        );

            if (handle.IsInvalid)
            {
                throw new PcapException("Failed to open device");
            }

            if (address.Address != null)
            {
                ConfigureDhcp(
                    handle,
                    address.Address,
                    address.IPv4Mask,
                    IPAddress.Parse("0.0.0.0"),
                    TimeSpan.FromHours(24)
                    );
            }

            SetMediaStatus(handle, true);
            return(new FileStream(handle, FileAccess.ReadWrite, bufferSize, true));
        }
Beispiel #2
0
        private static TunnelDevice GetTunnelDevice(NetworkInterface nic)
        {
            var config = new IPAddressConfiguration
            {
                // Pick a range that no CI is likely to use
                Address  = IPAddress.Parse("10.225.255.100"),
                IPv4Mask = IPAddress.Parse("255.255.255.0"),
            };

            return(new TunnelDevice(nic, config));
        }
Beispiel #3
0
 public FileStream Open(NetworkInterface networkInterface, IPAddressConfiguration address, DeviceConfiguration configuration)
 {
     var bufferSize = configuration.BufferSize ?? 4096;
     var stream     = new FileStream("/dev/net/tun", FileMode.Open, FileAccess.ReadWrite, default, bufferSize);