How detect TCP/IP socket shutdown when ethernet cable is disconnected | Unix Linux Forums | Programming

  Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

How detect TCP/IP socket shutdown when ethernet cable is disconnected

Programming


Tags
disconnection, tcp/ip

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-06-2010
jeje_clb jeje_clb is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 30 July 2010, 1:36 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
How detect TCP/IP socket shutdown when ethernet cable is disconnected

Hi,

I want to code TCP/IP client/server in linux application capable to fastly detect ethernet cable disconnection in any condition.

So I have activate SO_KEEPALIVE options and set TCP_KEEPCNT, TCP_KEEPIDLE and TCP_KEEPINTVL to 1.

When I disconnect ethernet cable I have the following behaviour :
- If I wasn't sending data when I disconnect the cable, the TCP Keepavlie start and detect disconnection : expected behaviour.
- If I was sending data when I disconnect ethernet cable, I was notify that connection is down only after about 16 minutes : not expected behaviour, time very too long.

I have look with tcpdump the packet on the device. If I was sending data when I disconnect the ethernet cable, I packet is resend 8 times (normal behaviour of TCP) but after the last TCP request without acknoledge, I wasn't notify that the connection is down

Could you help me to solve this behaviour please?

Regards
Sponsored Links
    #2  
Old 07-07-2010
gratuitous_arp gratuitous_arp is offline
Registered User
 
Join Date: Jul 2009
Last Activity: 21 February 2012, 8:07 AM EST
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Try taking a look at the SIOCETHTOOL ioctl. This can be used to check if a physical connection is present on an Ethernet port.
Sponsored Links
    #3  
Old 07-08-2010
jeje_clb jeje_clb is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 30 July 2010, 1:36 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Hi gratuitous_arp

SIOCETHTOOL ioctl command allow to know is physical connection is present.

I my case, I have physical connection with a switch but the connection between the distant equipment will be broken during exchange. So, the TCP acknowledge will not be receive, TCP request will be resend as soon as tcp_retry is reach. After these retry, even if I have asked to send more data with the send command, no more data will be send from my computer to the distant computer (no more traces with tcpdump). After about 15 minutes, the recv command return with error "no route to host". But, I wanted to detect the socket disconnection after some secondes.

If you have any other idea, don't hesitate to propose it.

Regards
    #4  
Old 07-08-2010
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 October 2014, 9:55 PM EDT
Location: Saskatchewan
Posts: 19,685
Thanks: 824
Thanked 3,352 Times in 3,139 Posts
TCP does best-effort delivery, which is why it has such obnoxiously long timeouts. I've seen it survive 10-minute network outages. It's really not designed to do what you want. Try pinging your host to see if it responds or not.
Sponsored Links
    #5  
Old 07-09-2010
jeje_clb jeje_clb is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 30 July 2010, 1:36 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Corona688,

How can I ping the host in C++ application?

Thanks in advance for your response.
Sponsored Links
    #6  
Old 07-09-2010
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 26 October 2014, 12:01 AM EDT
Location: NM
Posts: 10,252
Thanks: 283
Thanked 803 Times in 747 Posts
ping uses icmp, port 5813 (as I remember)

It is far easier simply to call popen() with a ping command ( [code]/usr/bin/ping [remote address] [code]), read the return code, than to try to rewrite ping.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to change ethernet cable of iscsi initiator (iscsi client)? pankajd UNIX for Dummies Questions & Answers 0 05-24-2010 02:16 PM
Two Servers via ethernet crossover cable jrodriguez365 IP Networking 3 05-08-2010 11:23 AM
How to handle unplugging ethernet cable in socket programming JagadishB IP Networking 0 02-15-2010 12:52 AM
[RHEL4.5] server shutdown when I unplug the ethernet cable flekzout Red Hat 3 10-16-2009 02:14 PM
Monitor displays Cable disconnected venuavula Solaris 1 02-23-2006 02:08 PM



All times are GMT -4. The time now is 01:09 AM.