SO_REUSEADDR problem with 2.2.10-ac11?

Wichert Akkerman (wichert@soil.nl)
Tue, 20 Jul 1999 16:51:54 +0200


--iJXiJc/TAIT2rh2r
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

I upgraded my system from 2.2.6 to 2.2.10-ac11 yesterday and noticed
an interesting problem: multiple sockets can now bind to the same
port on the same interface. I noticed this when I suddenly had 10
ircd running and client connections were getting accepted by the wrong
server (ie not the first one). I've been told this also happens with
2.2.10-ac10.

Below is a simple test-program to demonstrate the problem.

Wichert.

#include <sys/socket.h>
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int createsock(int argc, char **argv)
{
struct sockaddr_in addr,maddr;
int sock;
int len =3D sizeof(maddr);
int err;
char *saddr;

sock =3D socket(AF_INET, SOCK_STREAM, 0);
if(sock < 0) perror("socket");

if(argc < 3) {
err =3D 1;
err =3D setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &err, sizeof(err));
if (err) perror("setsockopt");
}=09

inet_aton((argc > 1) ? argv[1] : "127.0.0.1" , &addr.sin_addr);
addr.sin_port =3D htons(9001);
addr.sin_family =3D AF_INET;

err =3D bind(sock, &addr, sizeof(addr));
if(err) perror("bind"), exit(1);

err =3D listen(sock, 10);
if(err) perror("listen"), exit(1);

return 0;
}

main(int argc, char **argv)
{
createsock(argc, argv);
createsock(argc,argv);
}

--iJXiJc/TAIT2rh2r
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia

iQB1AwUBN5SNCqjZR/ntlUftAQGDgQL7B5GKB9TWSMbabiyhyVHNZG/vV89otdod
TRNTSAsIsOFPgjaE7Y2EZCA88kfQDXSrWTo0nb0TQPm8Xlg124Cc6cM8oYLLdWfH
rXVZMJXnHRN5/bU0ivDHVsdsoasDowkS
=wZWG
-----END PGP SIGNATURE-----

--iJXiJc/TAIT2rh2r--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/