473,499 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending packets over raw sockets

I can send data over a raw socket in C#. The part that is currently a
problem is constructing the packet to be sent. To construct the packet,
is it necessary to construct the packet 'by hand' and store it as a
byte[] array, computing the checksum etc before sending? I can't find
any C# classes that deal with packets.
Jan 18 '07 #1
6 5225
White Spirit wrote:
I can send data over a raw socket in C#. The part that is currently a
problem is constructing the packet to be sent. To construct the packet,
is it necessary to construct the packet 'by hand' and store it as a
byte[] array, computing the checksum etc before sending? I can't find
any C# classes that deal with packets.
Why do you need to construct the packets by hand? Are you using TCP or
UDP? TCP is stream-based, so normally you just ask the socket to write
data and it splits it into packets as it sees fit.

Jon

Jan 18 '07 #2
I should add that the purpose is to write a security application that
scans a range of IP addresses using a SYN scan. The problem with raw
sockets being blocked in certain versions of Windows isn't a problem as
I'm using the Mono C# development environment under Linux.
Jan 18 '07 #3
White Spirit wrote:
I should add that the purpose is to write a security application that
scans a range of IP addresses using a SYN scan. The problem with raw
sockets being blocked in certain versions of Windows isn't a problem as
I'm using the Mono C# development environment under Linux.
Okay - I'm not sure there are any managed classes which give you the
raw access to that extent, at least not in .NET itself. You may find a
third party one, or possibly use P/Invoke to call through to the "raw
C" functions.

Jon

Jan 18 '07 #4

"White Spirit" <ws*****@homechoice.co.ukwrote in message
news:45********@news1.homechoice.co.uk...
>I should add that the purpose is to write a security application that scans
a range of IP addresses using a SYN scan. The problem with raw
Why would you expect a class library to take care of domain-specific
behavior? The reason you need to create the packets yourself, is because
the behavior you want is different from what the libraries create, not
because the libraries don't exist.

Of course, it's possible to write a class to expose all the standard
elements of the IP and TCP header... but it becomes quite difficult if you
need to handle arbitrary options. It will also be quite inefficient
compared to direct bit manipulation.

The best would probably to use gather sends to collect the various headers
and payload... C# is just a poor choice for this. Under windows, you could
mix C++/CLI for the lowest layers with C# for business logic. Under mono,
there's nothing like MS IJW. The sooner you switch to a different platform,
one designed for low-level system control, the better.
sockets being blocked in certain versions of Windows isn't a problem as
I'm using the Mono C# development environment under Linux.

Jan 18 '07 #5
Hi,

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11*********************@m58g2000cwm.googlegro ups.com...
| White Spirit wrote:
| I should add that the purpose is to write a security application that
| scans a range of IP addresses using a SYN scan. The problem with raw
| sockets being blocked in certain versions of Windows isn't a problem as
| I'm using the Mono C# development environment under Linux.
|
| Okay - I'm not sure there are any managed classes which give you the
| raw access to that extent, at least not in .NET itself. You may find a
| third party one, or possibly use P/Invoke to call through to the "raw
| C" functions.

I don't think that P/invoke is included in Mono.

OP:
You should better use C in this case, as you are working in Linux you will
have a big pool of source code you can use.
--
Ignacio Machin
machin AT laceupsolutions com
Jan 18 '07 #6
Ignacio Machin ( .NET/ C# MVP ) wrote:
| Okay - I'm not sure there are any managed classes which give you the
| raw access to that extent, at least not in .NET itself. You may find a
| third party one, or possibly use P/Invoke to call through to the "raw
| C" functions.

I don't think that P/invoke is included in Mono.
I can't say I've used it myself, but it's there:

http://www.mono-project.com/Interop_...tive_Libraries

Jon

Jan 18 '07 #7

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

Similar topics

1
14479
by: coder_1024 | last post by:
I'm trying to send a packet of binary data to a UDP server. If I send a text string, it works fine. If I attempt to send binary data, it sends a UDP packet with 0 bytes of data (just the...
1
6914
by: Tim Black | last post by:
My application requires sending a large piece (~2MB) of data to several devices on a network via TCP sockets. I have experimented with different methods for doing this and this has raised some...
5
4562
by: Glenn Wilson | last post by:
I am writing a network system for project I am working on. How would I send a class or structure to the clients and recieve one back. Or how would I go about building a packet with a header and...
4
8188
by: yaron | last post by:
Hi, I have a problem when sending data over TCP socket from c# client to java server. the connection established ok, but i can't send data from c# client to java server. it's work ok with...
4
5377
by: Abubakar | last post by:
Hi, I am writing a server in C# and client in C++ (pure, not managed). The communication goes on through sockets. In C# I am using NetworkStream to send text data (by converting it to byte array)...
7
2671
by: D. Patrick | last post by:
I need to duplicate the functionality of a java applet, and how it connects to a remote server. But, I don't have the protocol information or the java source code which was written years ago. ...
9
17946
by: thorley | last post by:
Greetings, since there was no reponse to my previous post about an existing FastCGI server in python, I've taken to writing my own. (which of course I'll share--*if* there's something to share ;) ...
9
4878
by: Miro | last post by:
VB 2003 at the end of the code, this works great. bytCommand = Encoding.ASCII.GetBytes("testing hello send text") udpClient.Send(bytCommand, bytCommand.Length) and this recieves it Dim...
2
3038
by: =?Utf-8?B?R3JlZ0lJ?= | last post by:
Hi All, I have some problems with sending UDP packets using Winsock. I tried to send some to a closed port, and according to the documentation on Microsoft MSDN site...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.