473,566 Members | 2,908 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 5232
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*****@homech oice.co.ukwrote in message
news:45******** @news1.homechoi ce.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.co mwrote in message
news:11******** *************@m 58g2000cwm.goog legroups.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
14497
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 headers). I can see this because I'm running Ethereal and watching the packets. I'm defining the packets as shown below: $text_msg = "Hello,...
1
6941
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 questions about the implementation of Python sockets. (both methods use blocking sockets) Method 1: Calls socket.sendall(data) for each device in...
5
4568
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 other information and then be able to break it apart when I recieve it at the other end. These packets can be of Varible length but would always have...
4
8193
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 TcpClient, NetworkStream and StreamWriter classes. but with low level socket it doesn't work (When using the Socket class Send method).
4
5390
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) to the c++ client. In c++ client I have "recv" (winsock) function through which I receive everything. Now there is a need to pass a "struct" of C#...
7
2677
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. So, I used a packet sniffer and saw the protocol (TCP), the port, IP address, etc. All is good. I tried 2 different versions of .NET code to...
9
17966
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 ;) My problem now, is that I need to send certain binary data over a socket. That is, I want to make some bytes, and stuff them in a TCP packet, send...
9
4888
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 strReturnData As String = _ System.Text.Encoding.ASCII.GetString(receiveBytes)
2
3045
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 (http://msdn.microsoft.com/en-us/library/ms740148(VS.85).aspx) subsequent calls of sendto function should result in returning WSAECONNRESET error code caused by returning ICMP...
0
7673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6263
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2085
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 we have to send another system
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.