-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The process cannot access the file because it is being used by another process. #1
Comments
Hello sauceCruet, 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. 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: