473,287 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Accessing raw TCP packet payload data

Hi All,

Does anyone know if it's possible to grab the raw payload data from
a TCP packet, using .NET (C# to be exact).

I'm writing a piece of software that communicates to a networked
device using a protocol encapsulated inside TCP. The structure of
the protocol is such that stream semantics aren't really appropiate
for communication; all the data for an encapsulated packet has to
fit inside a single TCP packet. I just want to be able to pickup
the payload for each TCP packet that comes in from the device, on
the established connection.

--
Chris Crowther
Developer
J&M Crowther Ltd.
Jun 30 '06 #1
10 3667
Check out this article:

http://www.c-sharpcorner.com/Network...fferInCSLM.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
"Chris Crowther" <hi****@newsgroups.nospam> wrote in message
news:OV**************@TK2MSFTNGP02.phx.gbl...
Hi All,

Does anyone know if it's possible to grab the raw payload data from
a TCP packet, using .NET (C# to be exact).

I'm writing a piece of software that communicates to a networked
device using a protocol encapsulated inside TCP. The structure of
the protocol is such that stream semantics aren't really appropiate
for communication; all the data for an encapsulated packet has to
fit inside a single TCP packet. I just want to be able to pickup
the payload for each TCP packet that comes in from the device, on
the established connection.

--
Chris Crowther
Developer
J&M Crowther Ltd.

Jun 30 '06 #2
As has already been mentioned you can use raw sockets etc to access this
information. I would however have to wonder the point of using TCP in such a
scenario.
"Chris Crowther" <hi****@newsgroups.nospamwrote in message
news:OV**************@TK2MSFTNGP02.phx.gbl...
Hi All,

Does anyone know if it's possible to grab the raw payload data from
a TCP packet, using .NET (C# to be exact).

I'm writing a piece of software that communicates to a networked
device using a protocol encapsulated inside TCP. The structure of
the protocol is such that stream semantics aren't really appropiate
for communication; all the data for an encapsulated packet has to
fit inside a single TCP packet. I just want to be able to pickup
the payload for each TCP packet that comes in from the device, on
the established connection.

--
Chris Crowther
Developer
J&M Crowther Ltd.

Jul 2 '06 #3
Greg Young wrote:
As has already been mentioned you can use raw sockets etc to access this
information. I would however have to wonder the point of using TCP in such a
scenario.
Given I'd have to re-implement the mechanics of TCP myself, there
isn't much point at all. If I could just pick up the payloads then
it would have been slightly more error tolerant without requiring
any extra work on my part.

I may as well just use the UDP version of the protocol - there's
session registration within the encapsulated protocol anyway.
Actually there's session registration within the encapsulated
protocol and the protocol that the encapsulation is encapsulating.

--
Chris Crowther
Developer
J&M Crowther Ltd.
Jul 2 '06 #4
Hi Chris,

There are some code samples on code project for network sniffers. Here is
one of them which is coded with C#.

http://www.codeproject.com/cs/internet/hssniffer.asp

HTH.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 3 '06 #5
Kevin Yu [MSFT] wrote:
There are some code samples on code project for network sniffers. Here is
one of them which is coded with C#.

http://www.codeproject.com/cs/internet/hssniffer.asp
I shall have a wade through it at some point; I don't suppose you
know if has the answer to my current quandary in it?

If I set SocketOptionName.HeaderIncluded to true on the socket I'm
using, then SendTo() throws the follow SocketException:

"A blocking operation was interrupted by a call to
WSACancelBlockingCall"

It's a mite annoying, to say the least; if only because I don't see
how setting HeaderIncluded to true would affect that. And of course
the fact that I have Blocking set to false as well.
Kevin Yu
Microsoft Online Community Support
--
Chris Crowther
Developer
J&M Crowther Ltd.
Jul 5 '06 #6
Hi Chris,

Are you developing on a Windows XP SP2 machine? If so, Windows XP SP2
disables most of the RAW sockets support. You can check the following links
for more infromation.

http://blogs.msdn.com/michael_howard...12/213611.aspx ,
http://www.kayodeok.co.uk/weblog/200...w_sockets.html

Check out http://www.thecodeproject.com/csharp/SendRawPacket.asp for
how to do it with an NDIS protocol driver.

Some one has also come to this problem.

http://groups.google.com/group/micro...es.csharp/brow
se_thread/thread/234f946345470fc3/a036f8dc5e371a78?lnk=st&q=%22A+blocking+op
eration+was+interrupted+by+a+call+to+WSACancelBloc kingCall%22+SocketOptionNa
me.HeaderIncluded&rnum=2&hl=en#a036f8dc5e371a78

HTH.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 6 '06 #7
Kevin Yu [MSFT] wrote:
Are you developing on a Windows XP SP2 machine? If so, Windows XP SP2
disables most of the RAW sockets support. You can check the following links
for more infromation.
Developing on XP SP2, deploying on a Windows 2003 Standard Edition
server. Though I suspect it would have the same limitation?

I've come at it from a slightly different angle; using a TcpClient
to handle the TCP connection and sending data (as I can just poke a
Byte[] at the Socket directly) and using the raw socket on a
seperate thread to grab the incoming packets.

I shall now return to trying to remember how to resolve what I
suspect is a threading problem (damn events).
Kevin Yu
Microsoft Online Community Support
--
Chris Crowther
Developer
J&M Crowther Ltd.
Jul 6 '06 #8
Hi Chris,

Yes, they have the same limitaitions. I think you have to change the raw
socket communication on the seperate thread.

If anything is unclear, please feel free to let me know.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 7 '06 #9
Kevin Yu [MSFT] wrote:
Yes, they have the same limitaitions. I think you have to change the raw
socket communication on the seperate thread.
It's working fine now; grabbing packets on a seperate thread and
discarding the ones I don't need.

Thanks for the pointers.
Kevin Yu
Microsoft Online Community Support
--
Chris Crowther
Developer
J&M Crowther Ltd.
Jul 11 '06 #10
You're welcome, Chris. Thanks for sharing your experience with all the
people here. If you have any questions, please feel free to post them in
the community.

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 12 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: David Sworder | last post by:
Hi, I'm writing an application in which a client (C#/WinForms) and server (C#/service) interact with one another. The client establishes a "session" with the server but for scalability reasons...
1
by: spammersarevermin | last post by:
I'm trying to put some hex values in a UDP packet & I don't have a clue how to accomplish this. Using the code below results in a packet going out w/ the right buffer length but all 00's as the...
2
by: kali | last post by:
this is kali a new member to this forum.. iam an undergrad studd and wrking with a opacket sniffer to capture data transmitted using a hardware... the file saved in the sniffer is a binary file...
0
by: jtrades | last post by:
I have a question concerning the retrieval of a multicast packet's contents. I need to translate the network packets that I have been getting via multicast protocol. Each packet has a binary...
3
by: nexus024 | last post by:
I am trying to write a program that will continuously sniff eth0 for a specific UDP packet thats being sent to a specific destination IP, alter the data of the packet, and finally transmit it to the...
0
by: cs02lk1 | last post by:
Hi, I need to stream audio and/or video to a PDA device. There is a trick here which is: The PDA must receive the stream from a multicast address. For this I have implemented a Bridge application...
10
by: stars14u | last post by:
i have written a code for packet capturing in "C". now i need to save the packets and extract its payload from the packets. once extracted i do some changes to the payload and reform the packet...
3
by: stars14u | last post by:
I AM STRUCK at a point... i need to change payload inf. i have done it..but now i need to reform the packet. MY IDEA is To store the whole frame structure replace the payload nd crc i...
0
by: neeru29 | last post by:
I'm using Pcapy and impacket module for packet sniffer. I'm able to capture the whole data in a variable and display it. I want extract the IP addresses , Port no's and Payload data into separate...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.