By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,201 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,201 IT Pros & Developers. It's quick & easy.

C# Raw Sockets

P: n/a
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
ca*****@tamu.edu
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <ca*****@tamu.edu> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
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
ca*****@tamu.edu

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.