Raw Socket Sender

From: KevJB (KevJB_at_discussions.microsoft.com)
Date: 09/18/04


Date: Sat, 18 Sep 2004 01:49:01 -0700

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



Relevant Pages

  • Re: Http server implementation for Windows Media Server
    ... On that level that already extra raw data even not ... similar problem applies to me as would happen with raw sockets. ... I'm assuming you are using a raw TCP ... the packets aren't ACKed because ...
    (microsoft.public.win32.programmer.networks)
  • Re: Error in send, while using IP_HDRINCL
    ... > Arkady Frenkel wrote: ... >>> And MS could do exactly the same precautions for an app that uses raw ... >>> sockets. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Error in send, while using IP_HDRINCL
    ... > Arkady Frenkel wrote: ... >>> And MS could do exactly the same precautions for an app that uses raw ... >> network students move to linux", at the end they leave the UDP ... BTW the Sudesh wrote that they can't read with raw sockets and that due to ...
    (microsoft.public.win32.programmer.networks)
  • Re: Problem with unix sockets: SOCK_DGRAM ignores MSG_TRUNC
    ... message truncation due to insufficient buffer size. ... What part of "Only valid for packet sockets" from the manual page ... It's a feature which only was meant to be valid for AF_PACKET sockets. ...
    (Linux-Kernel)
  • Re: Question on select() and sockets
    ... For sockets there are many more potential ... A common one that I've personally experienced involves UDP ... which tries to copy the packet ...
    (comp.unix.programmer)