473,549 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Raw Socket Issues starting TCP Connections

I am working on starting and managing TCP connections manually. I build
the IP headers and TCP packets manually and send them on my own. The
problems I run into seems to be related to the Sockets. Maybe someone
can help me out.

1) I can build the packets and put them out fine, however, I can only
read incomming data if I use IOControl and set the socket SIO_RCVALL.
But doing this seems to apply to other sockets I maybe running in a
diffrent thread.

2) The biggest problem I have seems to be starting a TCP connection. If
I send a SYN, I get a SYN/ACK or SYN/RST like I am suppose to, but for
some reason the Socket replys with a RST with out me doing anything.

Here is how I am building the socket and sending the data...
Socket remote = new Socket(AddressF amily.InterNetw ork, SocketType.Raw,
ProtocolType.IP );
remote.Bind(thi s.l_ipep);
remote.SetSocke tOption(SocketO ptionLevel.Sock et,
SocketOptionNam e.ReceiveTimeou t, this.timeout_ti me);
remote.SetSocke tOption(SocketO ptionLevel.IP,
SocketOptionNam e.HeaderInclude d, 1);
int ret = remote.IOContro l(SIO_RCVALL, oin, oout);

if (BitConverter.T oInt32(oout, 0) != 0) {
return error;
}

....

this.remote.Sen dTo(ip_packet.g et_packet(), this.r_ipep);

What am I doing wrong??? Why does the socket send a RST without me
doing anything? Why can't I read data without setting the socket in
promiscious mode. And why is it that when I do set the socket to
promiscious mode that it seems to apply to other sockets running in
diffrent threads? Thanks.

Nov 16 '05 #1
2 15658
Hi,
just in case you still have this problem.

here is an explanation:

Since you are using raw sockets (SOCK_RAW) and not TCP/Stream sockets
(SOCK_STREAM) the TCP stack has no information about what you are doing
at program level. And since the IP_HDRINCL allows you to build any type
of IP packet and send it along with the data, you can build a SYN packet
and send it to the TCP server program which is actively listening. But
the point is that the SYN packet is being sent from your program and not
the stack. In other words the TCP stack of your machine has no idea how
of sending the SYN packet.

On the other side the SYN packet is received by the stack at the remote
machine and not exactly by the program. As with the case of the arrival
of any SYN packet, the stack at the remote machine responds with a
SYN/ACK packet. This packet is now received by the TCP stack of your
machine. In other words, the incoming TCP packet (SYN/ACK) will be
processed by the stack. Since it has no information of the previous sent
SYN packet, it responds with a RST packet, as in the case of any
improper or unacceptable packet for a connection.
..
..

full article can be found at
http://www.codeguru.com/forum/showthread.php?t=320739

regards,
b
banduraj schrieb:
I am working on starting and managing TCP connections manually. I build
the IP headers and TCP packets manually and send them on my own. The
problems I run into seems to be related to the Sockets. Maybe someone
can help me out.

1) I can build the packets and put them out fine, however, I can only
read incomming data if I use IOControl and set the socket SIO_RCVALL.
But doing this seems to apply to other sockets I maybe running in a
diffrent thread.

2) The biggest problem I have seems to be starting a TCP connection. If
I send a SYN, I get a SYN/ACK or SYN/RST like I am suppose to, but for
some reason the Socket replys with a RST with out me doing anything.

Here is how I am building the socket and sending the data...
Socket remote = new Socket(AddressF amily.InterNetw ork, SocketType.Raw,
ProtocolType.IP );
remote.Bind(thi s.l_ipep);
remote.SetSocke tOption(SocketO ptionLevel.Sock et,
SocketOptionNam e.ReceiveTimeou t, this.timeout_ti me);
remote.SetSocke tOption(SocketO ptionLevel.IP,
SocketOptionNam e.HeaderInclude d, 1);
int ret = remote.IOContro l(SIO_RCVALL, oin, oout);

if (BitConverter.T oInt32(oout, 0) != 0) {
return error;
}

...

this.remote.Sen dTo(ip_packet.g et_packet(), this.r_ipep);

What am I doing wrong??? Why does the socket send a RST without me
doing anything? Why can't I read data without setting the socket in
promiscious mode. And why is it that when I do set the socket to
promiscious mode that it seems to apply to other sockets running in
diffrent threads? Thanks.

Nov 17 '05 #2
jolay
1 New Member
So,I can't recieve the respond myself,can I?
May 14 '06 #3

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

Similar topics

2
1465
by: Dilip | last post by:
Gurus I didn't personally encounter these problems but some friends of mine who are doing some deep heavy-metal C#/Networking application have run into these problems. Does anybody have any idea if these are addressed for a future release? thanks --Dilip
4
3768
by: Ken Foster | last post by:
I have a Socket based application using the asynchronous Sends and Receives of the Socket class. I send out XML strings using BeginSend/EndSend from a client end point, the server side does a BeginReceive/EndReceive. I knew a message could be split up between Receives and I look for an end of message marker (and continue receiving if not...
2
1689
by: Ian Frawley | last post by:
Hi all I am running a standard client server socket type thing and I have started getting this exception Exception: System.IO.IOException Message: Unable to read data from the transport connection. Source: System at System.Net.Sockets.NetworkStream.Read(Byte buffer, Int32 offset, Int32 size)
2
2511
by: CHRISM | last post by:
Hiya, Been trying to figure this one out. I've written a very simple server in VB.NET that listens for client connections, then spits out a bunch of text and then closes the connection. Much like an HTTP server might do when you request a web page. The server socket listens for connections using BeginAccept(); and here's the simple...
5
4748
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a set of sensor data per second to a socket server. The socket server will do two things: 1. write data into a file via bsddb; 2. forward the data to...
11
8584
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling mechanisms. I use a non-blocking approach for this, using the call to 'poll' to support the async mechanism - rather than the 'begin' and 'end'...
2
5337
by: Jack | last post by:
Hi all I need some help. I have 10 machines here and I want to write a peer to peer tcp connection between them. So I have a main server that all the machine's login to and get each other's IP address. As implied by 'peer to peer' I need these machines to talk to each other directly. So my question is since in order to create a tcp connection...
1
1037
by: littlerobothead | last post by:
Hmm. Yeah, as I mentioned I didn't want to clobber folks with 300+ lines of PHP. I was more asking if there were any general gotchas with doing this sort of thing. For what's it's worth I fixed this issue by extending the life of the cookie and changing the times when PHP does session garbage collection.
1
1058
by: Scott McNair | last post by:
Hi, I'm trying to write a simple webproxy based upon some code I found on the web. However the application hangs upon trying to send data back to the user. Rather than post the whole code block, I've included a link to a zip file containing the code. I realize that there are some weaknesses at this point such as the fact that it only...
0
7527
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7726
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7967
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7485
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1953
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.