473,405 Members | 2,310 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,405 software developers and data experts.

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
ca*****@tamu.edu
Nov 16 '05 #1
1 20146
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add...
1
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for...
0
by: mrpolitics | last post by:
So I'm working with PureIRCD (http://sourceforge.net/projects/pure-ircd) and everything was fine untill yesterday when the server crashed. So I did a cold restart and staretd the server back up...
3
by: Logan McKinley | last post by:
I have a C# program that uses blocking sockets and want to allow the user to stop the server. The problem I am having is the socket blocks on...
4
by: BadOmen | last post by:
Hi, What is the different between 'System.Net.Sockets.Socket' and 'System.Net.Sockets.TcpClient'? When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket?? Yours, Jonas
3
by: Michael Maercker | last post by:
hi! i'm really not into networking at all and have now been asigned the task of porting a vb6-code into vb.net (compact framework, in this case) and the code uses the winsock-control. i quickly...
3
by: J C | last post by:
Hi, I'm using UDPClient to make a simple DNS server. I notice that intermittently and unpredictibly I get: Unhandled Exception: System.Net.Sockets.SocketException: An existing connection...
7
by: Adam01 | last post by:
Im using cygwin to test the code of a server I am writing. I've included sys/types.h, sys/socket.h, netdb.h, and arpa/inet.h. And this is the output.. ../../../sockets.cpp: In constructor...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.