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