LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-07-2010, 10:44 PM   #1
johnbach
LQ Newbie
 
Registered: Jul 2009
Posts: 3

Rep: Reputation: 0
false tcp connection


Why this happens?
How to solve this?

Code:
$netstat -na |grep 9325
tcp        0      0 127.0.0.1:9325              127.0.0.1:9325              ESTABLISHED
When a client socket repeatedly tries to connect to an inactive(no server socket is listening on this port) local port,connect succeeds.
Both the endpoints(port and ip) are same


System Information
Code:
$uname -a
Linux pztest.locadomain 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:15 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
 
Old 03-07-2010, 11:50 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Clearly a "Ghost in the Machine"

Use "lsof" to see if you can figure out which process(es) are using the port.

If you were on Windows, and if it were udp/9325, then I might be worried. But you aren't, and it isn't - so I doubt there's any problem...

Last edited by paulsm4; 03-07-2010 at 11:54 PM.
 
Old 03-08-2010, 12:42 AM   #3
johnbach
LQ Newbie
 
Registered: Jul 2009
Posts: 3

Original Poster
Rep: Reputation: 0
This happens for all port(server in localhost)
I noticed this with stunnel and here is a sample c++ program to simulate it
Code:
int main(int argc, char *argv[])
{
        int sockfd, portno, n;
        struct sockaddr_in serv_addr;
        struct hostent *server;
        int stat,ctr=50000;

        char buffer[256];
        portno = 28888;
        sockfd = socket(AF_INET, SOCK_STREAM, 0);
        if (sockfd < 0)
                throw string(strerror(errno));
        server = gethostbyname(argv[1]);
        if (server == NULL)
                throw string(strerror(errno));

        bzero((char *) &serv_addr, sizeof(serv_addr));
        serv_addr.sin_family = AF_INET;
        bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
        serv_addr.sin_port = htons(portno);
        system("netstat -nap |grep 28888");

        while(ctr--)
                if ( (stat=connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr))) < 0)
                        ;//retry
                else
                {
                        cout<<"Connected ,stat="<<stat<<",ctr="<<ctr<<", Error:"<<strerror(errno)<<";";
                        system("netstat -nap |grep 28888");
                        break;
                }
}
and the output
Code:
$./a.out localhost
tcp        0      0 127.0.0.1:28888             127.0.0.1:28888             ESTABLISHED 11099/a.out
Connected ,stat=0,ctr=36047, Error:Connection refused;
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Age of a TCP connection? acid_kewpie Linux - General 2 11-21-2009 01:19 PM
Replay tcp connection Tex-Twil Linux - Networking 2 06-24-2009 07:12 AM
log for TCP/IP (TCP) connection? fireball003 Linux - Server 4 12-04-2008 01:58 PM
how do i kill a tcp connection sunlinux Linux - Security 1 08-24-2007 07:33 AM
hijacking tcp connection atul_mehrotra Linux - Networking 4 04-30-2005 12:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration