[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.00.1002190053260.16302@melkinpaasi.cs.helsinki.fi>
Date: Fri, 19 Feb 2010 01:09:09 +0200 (EET)
From: "Ilpo Järvinen" <ilpo.jarvinen@...sinki.fi>
To: Bruce Cran <bruce@...n.org.uk>
cc: netdev@...r.kernel.org
Subject: Re: connect() sometimes succeeds when it shouldn't
On Thu, 18 Feb 2010, Bruce Cran wrote:
> I've found that if I run a program that does lots of calls to connect() then
> it will eventually succeed when there's no server listening. For SCTP it takes
> a few thousand, for TCP up to a couple of million. I first came across the
> problem in Windows, where the connection was being processed so quickly that
> by the time the handler function had finished, the 'connecting' flag had
> already been reset, which wasn't expected. I've not checked the Linux sources
> to see if something similar is happening though.
>
> The machine I tested it on was running a 2.6.32 i686 kernel.
>
> The test code can be found at
> http://www.cran.org.uk/~brucec/linux/badconnect.c
Perhaps you just managed to dial your own number? ...Please try with
my improved version of badconnect.c below. :-)
--
i.
--
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <netinet/in.h>
#include <errno.h>
int main(void)
{
struct sockaddr_in sa;
int fd;
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd <= 0)
err(1, "socket");
memset(&sa, 0, sizeof(sa));
sa.sin_addr.s_addr = INADDR_ANY;
sa.sin_family = AF_INET;
sa.sin_port = htons(60234);
if (bind(fd, (struct sockaddr*)&sa, sizeof(sa))) {
perror("bind");
exit(1);
}
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_port = htons(60234);
if (inet_aton("127.0.0.1", &(sa.sin_addr)) != 1)
exit(1);
if (connect(fd, (struct sockaddr*)&sa, sizeof(sa)) == 0) {
printf("bad connect on iter %d\n", 1);
exit(1);
}
close(fd);
return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists