You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
String dInfo = "tun1";
TunTapDevice Device = new TunTapDevice(dInfo);
Device.ConfigTun(IPAddress.Parse("10.2.2.2"), IPAddress.Parse("10.2.2.1"), IPAddress.Parse("255.255.255.0"));
Device.SetConnectionState(ConnectionStatus.Connected);
Device.CreateDeviceIOStream(1500);
FileStream DeviceIOStream = Device.TunTapDeviceIOStream;
while (true)
{
var bytes = new byte[0xFFFF];
var length = DeviceIOStream.Read(bytes);
int version = bytes[0] >> 4;
int IHL = bytes[0] & 0x0F;
if (version == 4 && IHL == 5) // IPv4 Packet with no options field
{
IPv4Packet received = new IPv4Packet(bytes);
Console.WriteLine($"{received.Protocol} {received.SourceIP}-{received.DestIP}");
}
}
DeviceIOStream.Close();
Console.WriteLine();
Unhandled exception. System.IO.IOException: The process cannot access the file because it is being used by another process.
at System.IO.Strategies.FileStreamHelpers.CheckFileCall(Int64 , String , Boolean )
at System.IO.RandomAccess.ReadAtOffset(SafeFileHandle , Span1 , Int64 ) at System.IO.Strategies.OSFileStreamStrategy.Read(Span1 )
at System.IO.Strategies.BufferedFileStreamStrategy.ReadSpan(Span1 , ArraySegment1 )
at System.IO.Strategies.BufferedFileStreamStrategy.Read(Span1 ) at System.IO.FileStream.Read(Span1 )
at ConsoleApp28.Program.Main(String[] args)
at ConsoleApp28.Program.
(String[] args)
Aborted (core dumped)
The text was updated successfully, but these errors were encountered:
Emmm. It seems like the TUN device assigned to this program was occupied by other process. I'm a little confused about what platform are you using. The code to make it work varies from OS to OS.
On Windows, you are suppose to use Device GUID to initialize instead of it's name like tun1.
On Linux, please make sure tun1 device has been created and open properly. Currently, function ConfigTun() and SetConnectionState() can only be used on Windows, so you need to do it on Linux manually.
Could you please provide me more info about your platform like OS and it's version.
String dInfo = "tun1";
TunTapDevice Device = new TunTapDevice(dInfo);
Device.ConfigTun(IPAddress.Parse("10.2.2.2"), IPAddress.Parse("10.2.2.1"), IPAddress.Parse("255.255.255.0"));
Device.SetConnectionState(ConnectionStatus.Connected);
Device.CreateDeviceIOStream(1500);
FileStream DeviceIOStream = Device.TunTapDeviceIOStream;
while (true)
{
var bytes = new byte[0xFFFF];
var length = DeviceIOStream.Read(bytes);
int version = bytes[0] >> 4;
int IHL = bytes[0] & 0x0F;
if (version == 4 && IHL == 5) // IPv4 Packet with no options field
{
IPv4Packet received = new IPv4Packet(bytes);
Console.WriteLine($"{received.Protocol} {received.SourceIP}-{received.DestIP}");
}
}
DeviceIOStream.Close();
Console.WriteLine();
Unhandled exception. System.IO.IOException: The process cannot access the file because it is being used by another process.
(String[] args)at System.IO.Strategies.FileStreamHelpers.CheckFileCall(Int64 , String , Boolean )
at System.IO.RandomAccess.ReadAtOffset(SafeFileHandle , Span
1 , Int64 ) at System.IO.Strategies.OSFileStreamStrategy.Read(Span
1 )at System.IO.Strategies.BufferedFileStreamStrategy.ReadSpan(Span
1 , ArraySegment
1 )at System.IO.Strategies.BufferedFileStreamStrategy.Read(Span
1 ) at System.IO.FileStream.Read(Span
1 )at ConsoleApp28.Program.Main(String[] args)
at ConsoleApp28.Program.
Aborted (core dumped)
The text was updated successfully, but these errors were encountered: