Connecting Tech Pros Worldwide Help | Site Map

C# Raw Sockets

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 16th, 2005, 06:40 AM
Adam Clauss
Guest
 
Posts: n/a
Default C# Raw Sockets

I am (attempting) to move an existing socket application to use raw sockets.

Right now, my application is essentially a port forwarder. Upon receiving a
connection, it will open a connection to an "internal" server and simply
relay all information back and forth (when the client sends something, my
app sends that to the server, when server sends something, my app sends that
to the client).

While what I have right DOES work, the downside is that to the server, all
connections appear to come from the IP address where my program is running.
I want it to instead appear as if it came from the original client IP (as a
true port forwarding router/etc would).

I understand to do this I will have to use Raw sockets, and that I will need
to recreate the IP header. But beyond this, I am not sure where to go.

Partly in a conceptual sense - (HOW to actually create the IP header) and
partly in a literal sense - I tried creating a raw socket:
serverSocket = new Socket(AddressFamily.InterNetwork,
System.Net.Sockets.SocketType.Raw, ProtocolType.Raw);

and then connected to the server as I do for the normal sockets - but the
server did not even register the connection.

Any advise? Examples or good articles on this would be greatly
appreciated!!

Thanks,
Adam Clauss
cabadam@tamu.edu



  #2  
Old November 16th, 2005, 06:41 AM
Roy Fine
Guest
 
Posts: n/a
Default Re: C# Raw Sockets

Adam,

at the very least, you will need to include the IP_HDRINCL socket option
with a value of TRUE. Something like this:

Socket sok = new
Socket(AddressFamily.InterNetwork,System.Net.Socke ts.SocketType.Raw,
ProtocolType.Raw);

sok.SetSocketOption(SocketOptionLevel.IP,SocketOpt ionName.HeaderIncluded,tru
e);

and then you MUST send the 28 bytes of IP header information.

Note - the IP_HDRINCL option, and raw sockets in general are a security
issue in Windows NT and later - and you need to be a member of the
administrators group to create sockes of this type. To disable this
restriction, the value of this registry variable to the value of 1 as DWORD
type:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Servic es\Afd\Parameters\DisableR
awSecurity

regards
roy fine

"Adam Clauss" <cabadam@tamu.edu> wrote in message
news:eTRoO6rZEHA.2388@TK2MSFTNGP09.phx.gbl...[color=blue]
> I am (attempting) to move an existing socket application to use raw[/color]
sockets.[color=blue]
>
> Right now, my application is essentially a port forwarder. Upon receiving[/color]
a[color=blue]
> connection, it will open a connection to an "internal" server and simply
> relay all information back and forth (when the client sends something, my
> app sends that to the server, when server sends something, my app sends[/color]
that[color=blue]
> to the client).
>
> While what I have right DOES work, the downside is that to the server, all
> connections appear to come from the IP address where my program is[/color]
running.[color=blue]
> I want it to instead appear as if it came from the original client IP (as[/color]
a[color=blue]
> true port forwarding router/etc would).
>
> I understand to do this I will have to use Raw sockets, and that I will[/color]
need[color=blue]
> to recreate the IP header. But beyond this, I am not sure where to go.
>
> Partly in a conceptual sense - (HOW to actually create the IP header) and
> partly in a literal sense - I tried creating a raw socket:
> serverSocket = new Socket(AddressFamily.InterNetwork,
> System.Net.Sockets.SocketType.Raw, ProtocolType.Raw);
>
> and then connected to the server as I do for the normal sockets - but the
> server did not even register the connection.
>
> Any advise? Examples or good articles on this would be greatly
> appreciated!!
>
> Thanks,
> Adam Clauss
> cabadam@tamu.edu
>
>[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.