PC Review


Reply
Thread Tools Rate Thread

C# Raw Socket Issues starting TCP Connections

 
 
banduraj
Guest
Posts: n/a
 
      17th Mar 2005
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.

 
Reply With Quote
 
 
 
 
Bernd
Guest
Posts: n/a
 
      24th Mar 2005
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.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
open socket connections Melv Windows XP New Users 3 14th Sep 2006 01:46 AM
Socket.Select() > 64 connections Stuart Microsoft C# .NET 9 7th Dec 2005 02:07 PM
Rdm Socket, Reliable Connections =?Utf-8?B?RmVsaXggTnlmZmVuZWdnZXI=?= Microsoft Dot NET Framework 0 27th Oct 2005 01:20 PM
SSL Socket connections Alexander Gnauck Microsoft Dot NET Compact Framework 3 25th Jul 2003 03:54 AM
Re: SSL/TLS socket connections Pieter Philippaerts Microsoft Dot NET 0 23rd Jul 2003 04:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:28 PM.