473,486 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Create 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(AddressFamily.InterNetwork, SocketType.Raw,
ProtocolType.IP);
remote.Bind(this.l_ipep);
remote.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, this.timeout_time);
remote.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.HeaderIncluded, 1);
int ret = remote.IOControl(SIO_RCVALL, oin, oout);

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

....

this.remote.SendTo(ip_packet.get_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 15651
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(AddressFamily.InterNetwork, SocketType.Raw,
ProtocolType.IP);
remote.Bind(this.l_ipep);
remote.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, this.timeout_time);
remote.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.HeaderIncluded, 1);
int ret = remote.IOControl(SIO_RCVALL, oin, oout);

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

...

this.remote.SendTo(ip_packet.get_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
1447
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...
4
3759
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...
2
1687
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...
2
2486
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...
5
4739
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...
11
8578
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...
2
5331
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...
1
1035
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...
1
1055
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...
0
7175
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...
1
6842
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
7330
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
5434
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,...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
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 ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
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...

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.