I am writing a proxy application for iSCSI to do some diagnostic work (think Fiddler for iSCSI). I try to capture data one packet at a time, I don’t want to read arbitrary sizes and as a result I get all of one iSCSI packet and half of the other - I really want to see the same data as, for example, Wireshark. In doing so, I use Socket.ReceiveMessageFrom().
However, one of the parameters is called the "endpoint", and I'm not quite sure what to do with it. Any clues? Here is my code, can you tell me if I'm completely out of the database:
Tuple<byte[], int> readOnePacket(TcpClient conn) {
var flags = SocketFlags.None;
EndPoint endpoint = null;
byte[] buffer = new byte[10 * 0x100000];
int offset = 0;
int bytes_received;
do {
IPPacketInformation packet_information;
bytes_received = conn.Client.ReceiveMessageFrom(buffer, offset, BufferSize,
ref flags, ref endpoint, out packet_information);
if (flags == SocketFlags.Partial) {
offset = bytes_received;
continue;
}
} while (false);
return new Tuple<byte[], int>(buffer, bytes_received + offset );
}
source
share