mirror of https://github.com/omar-polo/gmid.git
accept both ipv4 and ipv6
This commit is contained in:
parent
709d6e5ead
commit
33756bd235
|
@ -1,6 +1,7 @@
|
|||
2021-01-10 Omar Polo <op@omarpolo.com>
|
||||
|
||||
* gmid.c (logs): log also the port of the client
|
||||
(loop): accept both ipv4 and ipv6
|
||||
|
||||
2020-12-26 Omar Polo <op@omarpolo.com>
|
||||
|
||||
|
|
25
gmid.c
25
gmid.c
|
@ -771,7 +771,7 @@ goodbye(struct pollfd *pfd, struct client *c)
|
|||
}
|
||||
|
||||
void
|
||||
loop(struct tls *ctx, int sock)
|
||||
loop(struct tls *ctx, int sock4, int sock6)
|
||||
{
|
||||
int i;
|
||||
struct client clients[MAX_USERS];
|
||||
|
@ -783,7 +783,8 @@ loop(struct tls *ctx, int sock)
|
|||
bzero(&clients[i], sizeof(struct client));
|
||||
}
|
||||
|
||||
fds[0].fd = sock;
|
||||
fds[0].fd = sock4;
|
||||
fds[1].fd = sock6;
|
||||
|
||||
for (;;) {
|
||||
if (poll(fds, MAX_USERS, INFTIM) == -1) {
|
||||
|
@ -812,11 +813,11 @@ loop(struct tls *ctx, int sock)
|
|||
}
|
||||
}
|
||||
|
||||
if (i == 0) { /* new client */
|
||||
do_accept(sock, ctx, fds, clients);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fds[i].fd == sock4)
|
||||
do_accept(sock4, ctx, fds, clients);
|
||||
else if (fds[i].fd == sock6)
|
||||
do_accept(sock6, ctx, fds, clients);
|
||||
else
|
||||
handle(&fds[i], &clients[i]);
|
||||
}
|
||||
}
|
||||
|
@ -852,7 +853,7 @@ main(int argc, char **argv)
|
|||
const char *cert = "cert.pem", *key = "key.pem";
|
||||
struct tls *ctx = NULL;
|
||||
struct tls_config *conf;
|
||||
int sock, ch;
|
||||
int sock4, sock6, ch;
|
||||
connected_clients = 0;
|
||||
|
||||
if ((dir = absolutify_path("docs")) == NULL)
|
||||
|
@ -944,7 +945,8 @@ main(int argc, char **argv)
|
|||
if (tls_configure(ctx, conf) == -1)
|
||||
errx(1, "tls_configure: %s", tls_error(ctx));
|
||||
|
||||
sock = make_socket(port, AF_INET);
|
||||
sock4 = make_socket(port, AF_INET);
|
||||
sock6 = make_socket(port, AF_INET6);
|
||||
|
||||
if ((dirfd = open(dir, O_RDONLY | O_DIRECTORY)) == -1)
|
||||
err(1, "open: %s", dir);
|
||||
|
@ -962,9 +964,10 @@ main(int argc, char **argv)
|
|||
if (cgi == NULL && pledge("stdio rpath inet", NULL) == -1)
|
||||
err(1, "pledge");
|
||||
|
||||
loop(ctx, sock);
|
||||
loop(ctx, sock4, sock6);
|
||||
|
||||
close(sock);
|
||||
close(sock4);
|
||||
close(sock6);
|
||||
tls_free(ctx);
|
||||
tls_config_free(conf);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue