Quellcode-Bibliothek reuseaddr_conflict.c
Sprache: C
/* * Test for the regression introduced by * * b9470c27607b ("inet: kill smallest_size and smallest_port") * * If we open an ipv4 socket on a port with reuseaddr we shouldn't reset the tb * when we open the ipv6 conterpart, which is what was happening previously.
*/ #include <errno.h> #include <error.h> #include <arpa/inet.h> #include <netinet/in.h> #include <stdbool.h> #include <stdio.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h>
#define PORT 9999
int open_port(int ipv6, int any)
{ int fd = -1; int reuseaddr = 1; int v6only = 1; int addrlen; int ret = -1; struct sockaddr *addr; int family = ipv6 ? AF_INET6 : AF_INET;
fprintf(stderr, "Opening 127.0.0.1:%d\n", PORT);
listenfd = open_port(0, 0); if (listenfd < 0)
error(1, errno, "Couldn't open listen socket");
fprintf(stderr, "Opening INADDR_ANY:%d\n", PORT);
fd1 = open_port(0, 1); if (fd1 >= 0)
error(1, 0, "Was allowed to create an ipv4 reuseport on a already bound non-reuseport socket");
fprintf(stderr, "Opening in6addr_any:%d\n", PORT);
fd1 = open_port(1, 1); if (fd1 < 0)
error(1, errno, "Couldn't open ipv6 reuseport");
fprintf(stderr, "Opening INADDR_ANY:%d\n", PORT);
fd2 = open_port(0, 1); if (fd2 >= 0)
error(1, 0, "Was allowed to create an ipv4 reuseport on a already bound non-reuseport socket");
close(fd1);
fprintf(stderr, "Opening INADDR_ANY:%d after closing ipv6 socket\n", PORT);
fd1 = open_port(0, 1); if (fd1 >= 0)
error(1, 0, "Was allowed to create an ipv4 reuseport on an already bound non-reuseport socket with no ipv6");
fprintf(stderr, "Success\n"); return 0;
}
Messung V0.5
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.1Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.