W
White Spirit
I have the following code to send a packet to a remote socket and
receive a response in return:
System.Net.Sockets.Socket locSocket = new System.Net.Sockets.Socket
(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Tcp);
System.Net.Sockets.Socket remSocket = new System.Net.Sockets.Socket
(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Tcp);
locSocket.Bind (new IPEndPoint (locIP, 2126));
/*
Code to create a packet of data (byte[] datagram) goes here
*/
byte[] receivedPacket = new byte[96];
Console.WriteLine ("Sending packet...");
remoteSocket.SendTo (datagram, remoteEndPoint);
Console.WriteLine ("Packet sent");
locSocket.Receive (receivedPacket);
So far, it seems to work for external hosts but when I try to send a
packet to a port on my computer (say, port 23 for example) I seem to
receive the original packet that I sent to port 2126. I've checked
with wireshark and the packet goes to port 23 as it should, whereupon
a response is sent to port 2126 as expected (I'm communicating with
the network layer and wireshark shows I get an ACK/RST as expected I
have no server listening on port 23).
Is there something I'm doing wrong? Because of the nature of the
application, I'm unable to use connection oriented transmission in
this part of the program.
receive a response in return:
System.Net.Sockets.Socket locSocket = new System.Net.Sockets.Socket
(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Tcp);
System.Net.Sockets.Socket remSocket = new System.Net.Sockets.Socket
(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Tcp);
locSocket.Bind (new IPEndPoint (locIP, 2126));
/*
Code to create a packet of data (byte[] datagram) goes here
*/
byte[] receivedPacket = new byte[96];
Console.WriteLine ("Sending packet...");
remoteSocket.SendTo (datagram, remoteEndPoint);
Console.WriteLine ("Packet sent");
locSocket.Receive (receivedPacket);
So far, it seems to work for external hosts but when I try to send a
packet to a port on my computer (say, port 23 for example) I seem to
receive the original packet that I sent to port 2126. I've checked
with wireshark and the packet goes to port 23 as it should, whereupon
a response is sent to port 2126 as expected (I'm communicating with
the network layer and wireshark shows I get an ACK/RST as expected I
have no server listening on port 23).
Is there something I'm doing wrong? Because of the nature of the
application, I'm unable to use connection oriented transmission in
this part of the program.