473,320 Members | 1,724 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,320 software developers and data experts.

Raw Socket Sender

I must say I'm new to these Raw sockets in C# and unfortunantly I haven't met
anyone who is a expert in them which makes trying to develop any rather
difficult.

What I've been doing is trying to create some sort of NAT Server to work as
a ADSL gateway and share internet access. Yes I know I can use ICS, No I'm
not going to. I want to learn shomething by doing this not just use a
standard out of the box solution.

Anyway, I set up my packet reciever which recieves RAW IP packets and dumps
them all onto my processing functions which change around the Source Address
and send the pack off for it's trip onto the internet. However my RAW IP
sender is not happy and I *think* it has something to do with sockets and
blocking and the idea that sends should not overlap or somthing. Anyway the
code goes something like:

sender = new Socket(AddressFamily.InterNetwork, SocketType.Raw,
ProtocolType.IP);
sender.Blocking = true;
sender.Bind(new IPEndPoint(IPAddress.Parse(IP), port));
sender.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.HeaderIncluded, 1);
// Code to make the packet as a byte buffer and finally:
sender.SendTo(send_buf_bytes, args.totallength,
System.Net.Sockets.SocketFlags.DontRoute, new IPEndPoint(args.destination,
0));

At which point the system dies and gives me a cryptic error message saying:

An unhandled exception of type 'System.Net.Sockets.SocketException' occurred
in system.dll

Additional information: A blocking operation was interrupted by a call to
WSACancelBlockingCall

Can anyone see what I missed. I think I maybe need to turn the socket into
non-blocking by use of sender.IOControl but I have no idea what the actuall
call is or what the correct iocontrolcode would be.

Anyone got any ideas? Or does someone know that I am on the compleatly wrong
track and can suggest what I should in fact be doing?

Thanks in advance,
Kevin-John Beasley
Nov 16 '05 #1
2 8134
On Sat, 18 Sep 2004 01:49:01 -0700, "KevJB"
<Ke***@discussions.microsoft.com> wrote:
I must say I'm new to these Raw sockets in C# and unfortunantly I haven't met
anyone who is a expert in them which makes trying to develop any rather
difficult.

What I've been doing is trying to create some sort of NAT Server to work as
a ADSL gateway and share internet access. Yes I know I can use ICS, No I'm
not going to. I want to learn shomething by doing this not just use a
standard out of the box solution.

Anyway, I set up my packet reciever which recieves RAW IP packets and dumps
them all onto my processing functions which change around the Source Address
and send the pack off for it's trip onto the internet. However my RAW IP
sender is not happy and I *think* it has something to do with sockets and
blocking and the idea that sends should not overlap or somthing. Anyway the
code goes something like:

sender = new Socket(AddressFamily.InterNetwork, SocketType.Raw,
ProtocolType.IP);
sender.Blocking = true;
sender.Bind(new IPEndPoint(IPAddress.Parse(IP), port));
sender.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.HeaderIncluded, 1);
// Code to make the packet as a byte buffer and finally:
sender.SendTo(send_buf_bytes, args.totallength,
System.Net.Sockets.SocketFlags.DontRoute, new IPEndPoint(args.destination,
0));

<snip>

I don't know if it's related, but XP SP2 disables most of the RAW
sockets support (see
http://blogs.msdn.com/michael_howard...12/213611.aspx ,
http://www.kayodeok.co.uk/weblog/200...w_sockets.html
for more info).

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

Austin
Nov 16 '05 #2
Well that's a complete disaster. Surveyed Applications did they, didn't
survey enough is my response. You want a valid use of Raw Sockets. NAT. Three
letters and a RFC just blew your concept to hell. Remove RAW Sockets, who the
hell at microsoft seggested that? Whoever it was needs to be fired. This is
so typical of Microsoft, find a security issue and they kill off the thing
that lets people exploit the issue because developing some other form of
protection for affected applications is too hard. Sure people will write
Attack Tools using Raw Sockets, Take it away from Windows and they will go
use Linux anyway. You don't solve anything In fact you encourage the idjits
who write those programs because their first thought is "MS Blocked RAW
Sockets, they must have something to hide". In addition you break the
fundamental concept of TCP that ports should be visiable and can recieve or
send packets. What the hell use is an application that can recieve raw
packets but can't send them. That's like disabling the ability of people to
initiate calls on the telephone network because they could call people and
annoy them with telemarketing. The whole idea of the Operating System is to
ensure that ports that arn't bound to some propper application can't be used
as a security hole. If you want to stealth ports from the internet there is a
great tool called a firewall. People who are too stupid to use one don't
deserve to have an internet connection. Sorry maybe that's the line of
thought for XP Home but for XP Professional it's not acceptable.

So since Microsoft is so commited to developers how about we remove this
stupid feature from SP2 right now. Or maybe I should sue Microsoft for
screwing over my development project which I spent the last 12 months on.
Microsoft says C#.NET is surposed to be the future of internet applications
and here they are ripping out core components cause someone *might* use it
for "attack tools". I would have thought that after gettings it's ass kicked
for monopolising Internet Explorer microsoft would have smartened up.
Obviously not cause here they are remove more parts of Windows that
competitors can use to make Home/Small Office applications. Sounds like they
might be trying to force everyone to use ISA Server or ICS. I'm sure a lawyer
would consider that highly likely.

I guess Microsoft factored the conversion back to unix of a bunch of script
kiddies + some annoyed developers into the cost of their next release of
Windows. Maybe microsoft should change their slogan to "What Functionality
will we remove Today".

Anyway thanks for the tip Austin, some company executives head is going to
expload when I tell them we need to move ourselves down to the ethernet layer
to finalise our program for production release. The only good thing is that
MS owes us several thousand for support incidents that were due to a removed
feature that noone at the support centre conveniently knew about.
Kevin

"Austin Ehlers" wrote:
On Sat, 18 Sep 2004 01:49:01 -0700, "KevJB"
<Ke***@discussions.microsoft.com> wrote:
I must say I'm new to these Raw sockets in C# and unfortunantly I haven't met
anyone who is a expert in them which makes trying to develop any rather
difficult.

What I've been doing is trying to create some sort of NAT Server to work as
a ADSL gateway and share internet access. Yes I know I can use ICS, No I'm
not going to. I want to learn shomething by doing this not just use a
standard out of the box solution.

Anyway, I set up my packet reciever which recieves RAW IP packets and dumps
them all onto my processing functions which change around the Source Address
and send the pack off for it's trip onto the internet. However my RAW IP
sender is not happy and I *think* it has something to do with sockets and
blocking and the idea that sends should not overlap or somthing. Anyway the
code goes something like:

sender = new Socket(AddressFamily.InterNetwork, SocketType.Raw,
ProtocolType.IP);
sender.Blocking = true;
sender.Bind(new IPEndPoint(IPAddress.Parse(IP), port));
sender.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.HeaderIncluded, 1);
// Code to make the packet as a byte buffer and finally:
sender.SendTo(send_buf_bytes, args.totallength,
System.Net.Sockets.SocketFlags.DontRoute, new IPEndPoint(args.destination,
0));

<snip>

I don't know if it's related, but XP SP2 disables most of the RAW
sockets support (see
http://blogs.msdn.com/michael_howard...12/213611.aspx ,
http://www.kayodeok.co.uk/weblog/200...w_sockets.html
for more info).

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

Austin

Nov 16 '05 #3

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

Similar topics

4
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
2
by: zhebincong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting...
2
by: Craig | last post by:
Hi I listen on a port, when data is received I raise an event (OnMessageReceived) in the while loop as follows: private void WaitForConnection() { TcpListener listener = new...
5
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of...
1
by: Jonathan Woods | last post by:
Hi there, Please find file for illustrating infrastructure --> http://test.thipparath.com/GPRS/GPRS.jpg . Gateway receives packets from Trucks for processing Route/GPS position. When Truck and...
0
by: Jonathan Woods | last post by:
Hi there, Please find file for illustrating infrastructure --> http://test.thipparath.com/GPRS/GPRS.jpg . Gateway receives packets from Trucks for processing Route/GPS position. When Truck and...
3
by: fniles | last post by:
I am using ThreadPool to call a sub in a class. The first time the ThreadPool is called, I created a socket in the thread. I can connect a client to the socket and send a message to the client (in...
0
by: ChopDown | last post by:
Hi, I want to send/receive a serializable object in socket: ==========sender========== Dim MyMessage As New MessageClass.Message() Dim client As New TcpClient...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.