473,383 Members | 1,918 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,383 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 3675
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.