So I made a sniffer to suit my needs but now I want to try something more ambitious, I want to send back a packet that I filtered exactly the same, this is trickier than I thought.
Once I captured a packet that I want to resend I first write it to be sure that i got it and then try to send it.
Thing is it doesn't send any packets nor does it result in an error, i have no clue what's the problem and there seems to be no documentation on C# raw packet sending on the internet.
Code:
IPAddress ip = IPAddress.Parse("192.168.2.100");
m_clientSocket = new Socket(ip.AddressFamily, SocketType.Raw, ProtocolType.Ip);
m_clientSocket.Bind(new IPEndPoint(ip, 0));
m_clientSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);
Once I captured a packet that I want to resend I first write it to be sure that i got it and then try to send it.
Code:
byte[] dat = tcph.Data;
if (tcph.DataLength > 0)
{
char x = (char)dat[tcph.DataLength - 2];
string y = "" + x;
this.Invoke(new UpdateStatusCallback(this.UpdateStatus), new object[] { y + "\n" });
IPEndPoint ipEnd = new IPEndPoint(header.DestinationAddress, 8687);
try
{
m_clientSocket.SendTo(data, ipEnd);
}
catch (SocketException e)
{
MessageBox.Show(e.Message);
}
}
Thing is it doesn't send any packets nor does it result in an error, i have no clue what's the problem and there seems to be no documentation on C# raw packet sending on the internet.