Author Topic: TCP socket connection  (Read 14792 times)

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
TCP socket connection
« on: April 01, 2008, 04:49:23 PM »
Hi Mark, I am using the non buffered mode and try to connect to
a TCP host from uTasker. uTasker is set to IP 10.1.2.38
and the remote host has IP 10.1.2.47. After connecting the listener
gets an EVENT_ABORT. Here's the Wireshark log. It looks like uTasker
sends an ARP broadcast out asking who is 10.1.2.47, then 10.1.2.47
send out 3 ARP broadcasts asking who 10.1.2.38 is then stops.
It looks like uTasker is not sening back the ARP request to
10.1.2.47.

 The connect code returns OK. I got a valid socket number, 6,
and I'm using remote port 9002.
 
Code: [Select]
if  (fnTCP_Connect(IMS_TCP_socket, ipIMS, IMS_HOST_PORT, 0, 0)       >= 0)


 I can ping uTasker from 10.1.2.251 Ok and acces the uTasker web
server with no problems.


 Thanks,
 John
 
 
 

No.     Time        Source                Destination           Protocol Info
      4 10.032296   Advantec_37:40:40     Broadcast             ARP      Who has 10.1.2.38?  Tell 10.1.2.47


No.     Time        Source                Destination           Protocol Info
      5 294.297014  Phonetic_00:1f:30     Broadcast             ARP      Who has 10.1.2.47?  Tell 10.1.2.38

Address Resolution Protocol (request)

No.     Time        Source                Destination           Protocol Info
      6 302.262124  Advantec_37:40:40     Broadcast             ARP      Who has 10.1.2.38?  Tell 10.1.2.47


No.     Time        Source                Destination           Protocol Info
      7 303.298232  Advantec_37:40:40     Broadcast             ARP      Who has 10.1.2.38?  Tell 10.1.2.47


No.     Time        Source                Destination           Protocol Info
      8 304.294644  Advantec_37:40:40     Broadcast             ARP      Who has 10.1.2.38?  Tell 10.1.2.47

No.     Time        Source                Destination           Protocol Info
      9 406.338065  Vmware_26:8d:5d       Broadcast             ARP      Who has 10.1.2.38?  Tell 10.1.2.251

Frame 9 (42 bytes on wire, 42 bytes captured)
Ethernet II, Src: Vmware_26:8d:5d (00:0c:29:26:8d:5d), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
Address Resolution Protocol (request)

No.     Time        Source                Destination           Protocol Info
     10 406.338440  Vmware_26:8d:5d       Broadcast             ARP      Who has 10.1.2.38?  Tell 10.1.2.251


No.     Time        Source                Destination           Protocol Info
     11 406.338644  Phonetic_00:1f:30     Vmware_26:8d:5d       ARP      10.1.2.38 is at 00:07:f9:00:1f:30


No.     Time        Source                Destination           Protocol Info
     12 406.338789  10.1.2.251            10.1.2.38             ICMP     Echo (ping) request

Frame 12 (74 bytes on wire, 74 bytes captured)
Ethernet II, Src: Vmware_26:8d:5d (00:0c:29:26:8d:5d), Dst: Phonetic_00:1f:30 (00:07:f9:00:1f:30)
Internet Protocol, Src: 10.1.2.251 (10.1.2.251), Dst: 10.1.2.38 (10.1.2.38)
Internet Control Message Protocol

No.     Time        Source                Destination           Protocol Info
     13 406.339256  10.1.2.38             10.1.2.251            ICMP     Echo (ping) reply


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: TCP socket connection
« Reply #1 on: April 01, 2008, 05:43:54 PM »
Hi John

Are you sure that you can see all frames? It looks as though only broadcasts and some others to the local PC are visible. Do you have a switch in between which is stopping you seeing the others?

Try connected to a hub if possible. What happens when you run the uTasker project in the simulator on the PC you are using for the recording? - this should allow all to be seem.

Regards

Mark

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: TCP socket connection
« Reply #2 on: April 02, 2008, 07:07:06 PM »
Mark, I connected the uTasker device, the host it's trying to connect to
and the PC running Wireshark to the same Netgear hub.
uTasker has IP 10.1.2.38 and is trying to connect to 10.1.2.95, port
9002. I log the fnConnectTCP and it returns OK. Here's the
Wireshark dump.

  I can't run the current project in the simulator since it has too many
changes in it that prevent it from compiling under VC.

 Thanks,
 John

 Here's my log
0 - fnSetNextIMS_state connected OK
1 - fnIMSListener() TCP_EVENT_ABORT



Wireshark log using filter host 10.1.2.38

Code: [Select]
No.     Time        Source                Destination           Protocol Info
      1 0.000000    Phonetic_00:1f:30     Broadcast             ARP      Who has 10.1.2.95?  Tell 10.1.2.38
      2 0.000058    Advantec_56:82:52     Phonetic_00:1f:30     ARP      10.1.2.95 is at 00:d0:c9:56:82:52
      3 0.000068    10.1.2.38             10.1.2.95             TCP      56278 > 9002 [SYN] Seq=0 Len=0 MSS=1460
      4 0.000075    10.1.2.95             10.1.2.38             TCP      9002 > 56278 [ACK] Seq=0 Ack=1 Win=16060 Len=0
      5 0.000079    10.1.2.38             10.1.2.95             TCP      56278 > 9002 [RST] Seq=0 Len=0
      6 5.015432    Advantec_56:82:52     Phonetic_00:1f:30     ARP      Who has 10.1.2.38?  Tell 10.1.2.95
      7 5.015451    Phonetic_00:1f:30     Advantec_56:82:52     ARP      10.1.2.38 is at 00:07:f9:00:1f:30
« Last Edit: April 02, 2008, 07:11:40 PM by johnr »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: TCP socket connection
« Reply #3 on: April 02, 2008, 08:16:35 PM »
Hi John

The ARP looks good - I think it was always OK but with the filtering performed by the switch only the broadcast parts could be seen.

Now to the TCP connection issue:
The reason why the connection is being reset is due to the fact that the server is not sending a (SYN + ACK) back in response to the client's SYN. In your case the uTasker side is performing an active open by sending the SYN to the port 9002. The server on this port is responding with an ACK rather than the expected passive open - the passive open consists of the ACK to the SYN plus its own SYN.
If you look in the TCP code you will find the following in state TCP_STATE_SYN_SENT:

if ((rx_tcp_packet.usHeaderLengthAndFlags & (TCP_FLAG_SYN | TCP_FLAG_ACK)) == (TCP_FLAG_SYN | TCP_FLAG_ACK)) {
... send final ACK in three-way handschake and we are connected...
}
else if (rx_tcp_packet.usHeaderLengthAndFlags & TCP_FLAG_ACK) {
    fnCloseTCPSession(ptr_TCP); // this happens when we have a previous non-correctly disconnected session - we will try to close it
}


My explanation is that the close is due to this. I can't explain why the server seems to always send an ACK without a SYN. What kind of server is this?

Regards

Mark


Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: TCP socket connection
« Reply #4 on: April 02, 2008, 09:01:08 PM »
Mark, the host we're trying to connect to is running linux ver
2.2.25. I did a test connecting to our SMTP server and it
worked OK. Here's the log.
  I'll try to connect to the telnet port on the linux host giving us the problem.

 Thanks,
 John


Code: [Select]
1 0.000000    Phonetic_00:1f:30     Broadcast             ARP      Who has 10.1.2.111?  Tell 10.1.2.38
      2 0.000056    CompaqCo_8e:06:8a     Phonetic_00:1f:30     ARP      10.1.2.111 is at 00:50:8b:8e:06:8a
      3 0.002083    10.1.2.38             10.1.2.111            TCP      56278 > smtp [SYN] Seq=0 Len=0 MSS=1460
      4 0.002100    10.1.2.111            10.1.2.38             TCP      smtp > 56278 [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1460
      5 0.002123    10.1.2.38             10.1.2.111            TCP      56278 > smtp [ACK] Seq=1 Ack=1 Win=1460 Len=0
      6 0.011113    10.1.2.111            10.1.2.38             SMTP     Response: 220 ip226.sensaphone.us ESMTP Sendmail 8.12.11/8.12.11; Wed, 2 Apr 2008 15:38:57 -0400
      7 0.016719    10.1.2.38             10.1.2.111            TCP      56278 > smtp [ACK] Seq=1 Ack=89 Win=1460 Len=0
      8 60.136331   10.1.2.38             10.1.2.111            TCP      56278 > smtp [FIN, ACK] Seq=1 Ack=89 Win=1460 Len=0
      9 60.136379   10.1.2.111            10.1.2.38             TCP      smtp > 56278 [FIN, ACK] Seq=89 Ack=2 Win=5840 Len=0
     10 60.136411   10.1.2.38             10.1.2.111            TCP      56278 > smtp [ACK] Seq=2 Ack=90 Win=1460 Len=0

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: TCP socket connection
« Reply #5 on: April 02, 2008, 09:26:59 PM »
Mark , I was able to connect OK to the linux telnet port 23.
Here's the log. We can't connect to port 9002
on that box.


 Thanks,
 John

Here's my log. For some reason we're getting a CONREQ and
TCP_EVENT_REGENERATE events. I'm not sending any data, just
opening the connection.

Code: [Select]
- fnSetNextIMS_state connected OK
1 - fnIMSListener() TCP_EVENT_CONNECTED
3 - fnIMSListener() TCP_EVENT_CONREQ
3 - fnIMSListener() TCP_EVENT_DATA
3 - fnHandleData() state=4 len=12
603 - fnIMSListener() TCP_EVENT_REGENERATE
680 - fnIMSListener() TCP_EVENT_REGENERATE
719 - fnIMSListener() TCP_EVENT_CLOSED
720 - fnIMSListener() TCP_EVENT_REGENERATE

Code: [Select]
63 1029.794544 Phonetic_00:1f:30     Broadcast             ARP      Who has 10.1.2.47?  Tell 10.1.2.38
     64 1029.795157 Advantec_37:40:40     Phonetic_00:1f:30     ARP      10.1.2.47 is at 00:d0:c9:37:40:40
     65 1033.421818 10.1.2.38             10.1.2.47             TCP      56278 > telnet [FIN, ACK] Seq=1 Ack=13 Win=1460 Len=0
     66 1033.422652 10.1.2.47             10.1.2.38             TCP      telnet > 56278 [ACK] Seq=13 Ack=2 Win=16060 Len=0
     67 1033.430642 10.1.2.47             10.1.2.38             TCP      telnet > 56278 [FIN, ACK] Seq=13 Ack=2 Win=16060 Len=0
     68 1033.430843 10.1.2.38             10.1.2.47             TCP      [TCP Keep-Alive] 56278 > telnet [ACK] Seq=1 Ack=14 Win=1460 Len=0
     69 1033.431688 10.1.2.47             10.1.2.38             TCP      [TCP Keep-Alive ACK] telnet > 56278 [ACK] Seq=14 Ack=2 Win=16060 Len=0
     70 1033.737752 10.1.2.47             10.1.2.38             TCP      telnet > 56278 [FIN, ACK] Seq=13 Ack=2 Win=16060 Len=0
     71 1034.353423 10.1.2.47             10.1.2.38             TCP      telnet > 56278 [FIN, ACK] Seq=13 Ack=2 Win=16060 Len=0
     72 1035.590325 10.1.2.47             10.1.2.38             TCP      telnet > 56278 [FIN, ACK] Seq=13 Ack=2 Win=16060 Len=0
     73 1037.416811 Phonetic_00:1f:30     Broadcast             ARP      Who has 10.1.2.47?  Tell 10.1.2.38
     74 1037.417317 Advantec_37:40:40     Phonetic_00:1f:30     ARP      10.1.2.47 is at 00:d0:c9:37:40:40
     75 1038.104518 10.1.2.47             10.1.2.38             TCP      telnet > 56278 [FIN, ACK] Seq=13 Ack=2 Win=16060 Len=0
     76 1041.453627 Phonetic_00:1f:30     Broadcast             ARP      Who has 10.1.2.47?  Tell 10.1.2.38
     77 1041.454171 Advantec_37:40:40     Phonetic_00:1f:30     ARP      10.1.2.47 is at 00:d0:c9:37:40:40
     78 1043.063326 10.1.2.47             10.1.2.38             TCP      telnet > 56278 [FIN, ACK] Seq=13 Ack=2 Win=16060 Len=0
     79 1043.063339 10.1.2.38             10.1.2.47             TCP      56278 > telnet [RST] Seq=2 Len=0

« Last Edit: April 02, 2008, 09:38:58 PM by johnr »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: TCP socket connection
« Reply #6 on: April 02, 2008, 09:54:27 PM »
Hi John

The SMPT connection looks good - note that it answers to the SYN with SYN+ACK.

I only see the disconnect from the TELNET connection so I can't say anything about that, but if you say that it basically worked I assume that it also does the same.

When you say that the Server on port 9002 and the Telnet server are on the same Linux machine, why are the IP addresses different? Telnet server on 10.1.2.47; 9002 port server on 10.1.2.95?

Regards

Mark


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: TCP socket connection
« Reply #7 on: April 02, 2008, 11:23:22 PM »
John

You could try removing the close sent when the ACK is received after the SYN has been sent. Then you can see whether possibly the server sends a SYN later. I haven't ever seen or heard of this happening before but there are always new surprises waiting.

What you could also do is take the uTasker reference project and activate the time server demo. This will connect on start up to some time server addresses on the Internet until it gets an answer - this also serves as a reference to connecting. If you modify the port and IP (they are fixed values in the code in application.c) to match your server it will then try to connect on starting the simulator. This may help you debug easier.

Regards

Mark

PS. Is it possible to access the server from the internet? I couldn't ping it from here but you may be able to put this port in your router as a virtual server. Then I could also test it from here...

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: TCP socket connection
« Reply #8 on: April 03, 2008, 02:17:27 PM »
Hi Mark, IP's 10.1.2.95 and 10.1.2.47 are 2 of the in house linux hosts that use port 9002
for our application. Here's an IP of a linux host that is accessible from the Internet

 208.44.86.230 port 9002


 Thanks,
 John

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: TCP socket connection
« Reply #9 on: April 03, 2008, 04:14:36 PM »
Hi John

I just configured the project to connect to your server (208.44.86.230 - port 9002) but it doesn't receive any answer.
When I ping it from my PC it answers and also I can ping it via the ping function in the uTasker project using the simulator.
This suggests that the port 9002 is not open to the Internet.

Regards

Mark

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: TCP socket connection
« Reply #10 on: April 03, 2008, 09:59:40 PM »
Mark, The 208.44.86.230 box is outside of our firewall. When I
connect to it via uTasker, I get the following logs. Ill go back and compare this to connecting to the box that is on our switch.

 Thanks,
 John


0 - fnSetNextIMS_moving from OPENING to OPEN_REQUESTED
1 - fnIMSListener() Event=CONNECTED State=OPENING
1 - fnSetNextIMS_moving from OPENED to OPENED
610 - fnIMSListener() Event=CLOSED State=CLOSED
610 - fnSetNextIMS_moving from CLOSED to CLOSED



Code: [Select]
1 0.000000    Phonetic_00:1f:30     Broadcast             ARP      Who has 10.1.2.1?  Tell 10.1.2.38
      2 0.000181    Dell_20:79:a7         Phonetic_00:1f:30     ARP      10.1.2.1 is at 00:12:3f:20:79:a7
      3 0.000231    10.1.2.38             208.44.86.230         TCP      56278 > 9002 [SYN] Seq=0 Len=0 MSS=1460
      4 0.000238    10.1.2.11             10.1.2.38             ICMP     Redirect (Redirect for host)
      5 0.000242    208.44.86.230         10.1.2.38             TCP      9002 > 56278 [SYN, ACK] Seq=0 Ack=1 Win=16060 Len=0 MSS=1460
      6 0.000245    10.1.2.38             208.44.86.230         TCP      56278 > 9002 [ACK] Seq=1 Ack=1 Win=1460 Len=0
      7 5.013756    CompaqCo_30:3b:44     Phonetic_00:1f:30     ARP      Who has 10.1.2.38?  Tell 10.1.2.2
      8 5.013772    Phonetic_00:1f:30     CompaqCo_30:3b:44     ARP      10.1.2.38 is at 00:07:f9:00:1f:30
      9 5.017447    Dell_20:79:a7         Phonetic_00:1f:30     ARP      Who has 10.1.2.38?  Tell 10.1.2.11
     10 5.017551    Phonetic_00:1f:30     Dell_20:79:a7         ARP      10.1.2.38 is at 00:07:f9:00:1f:30
     11 60.146190   10.1.2.38             208.44.86.230         TCP      56278 > 9002 [FIN, ACK] Seq=1 Ack=1 Win=1460 Len=0
     12 60.146209   10.1.2.11             10.1.2.38             ICMP     Redirect (Redirect for host)
     13 60.147116   208.44.86.230         10.1.2.38             TCP      9002 > 56278 [ACK] Seq=1 Ack=2 Win=16060 Len=0
     14 61.053988   208.44.86.230         10.1.2.38             TCP      9002 > 56278 [FIN, ACK] Seq=1 Ack=2 Win=16060 Len=0
     15 61.054042   10.1.2.38             208.44.86.230         TCP      56278 > 9002 [ACK] Seq=2 Ack=2 Win=1460 Len=0
     16 61.054193   10.1.2.11             10.1.2.38             ICMP     Redirect (Redirect for host)
     17 65.101247   CompaqCo_30:3b:44     Phonetic_00:1f:30     ARP      Who has 10.1.2.38?  Tell 10.1.2.2
     18 65.101265   Phonetic_00:1f:30     CompaqCo_30:3b:44     ARP      10.1.2.38 is at 00:07:f9:00:1f:30
     19 65.106050   Dell_20:79:a7         Phonetic_00:1f:30     ARP      Who has 10.1.2.38?  Tell 10.1.2.11
     20 65.106156   Phonetic_00:1f:30     Dell_20:79:a7         ARP      10.1.2.38 is at 00:07:f9:00:1f:30


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: TCP socket connection
« Reply #11 on: April 03, 2008, 10:09:15 PM »
Hi John

I have just tried again from another location - it seemed that the firewall where I was when I first tested probably was blocking any answer from your server (possibly it only accepts certain ports).

Now I get a response and am connected. The connection looks normal (SYN + ACK) so I can't reproduce the problem you were having. Also your latest recording seems to show that this server is responding normally.

So this still leaves the open question as to why the other server is behaving as it is..!

Regards

Mark

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: TCP socket connection
« Reply #12 on: April 04, 2008, 02:12:39 AM »
Hi Mark, The only difference between those linux box's is that the 10.1.2.47 and 10.1.2.95 hosts I was having
problems with were located inside our firewall, so I had a direct TCP path to it. The 208.44.86.230 host is outside
of our firewall,  requiring we go through routers to access it.
 I'll do some more testing to clarify this. Maybe I'll try patching the TCP code that you mentioned earlier
that aborts when it doesn't see the SYN/ACK response and see what happens.


 Thanks,
 John