diff --git a/src/net.c b/src/net.c index 307976f..370368c 100644 --- a/src/net.c +++ b/src/net.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "net.h" #include "server.h" @@ -19,9 +20,11 @@ struct client { int fd; - char buf[BUFSIZ]; int bufend; int linetoolong; + int port; + char hostname[NI_MAXHOST]; + char buf[BUFSIZ]; }; int servsock; @@ -45,19 +48,24 @@ parse_linetoolong(int clientid, char *line) { void net_server(int port) { - struct sockaddr_in serveraddr; - serveraddr.sin_family = AF_INET; - serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); - serveraddr.sin_port = htons(port); + struct sockaddr_in6 serveraddr = { + .sin6_family = AF_INET6, + .sin6_addr = IN6ADDR_ANY_INIT, + .sin6_port = htons(port) }; - servsock=socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + servsock=socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP); if (servsock<0) errx(1, "socket: %s\n", strerror(errno)); - int i=1; - if (setsockopt(servsock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)) < 0) + int opt; + opt=1; + if (setsockopt(servsock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) errx(1, "setsockopt SO_REUSEADDR: %s\n", strerror(errno)); + opt=0; + if (setsockopt(servsock, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt)) < 0) + errx(1, "setsockopt IPV6_V6ONLY: %s\n", strerror(errno)); + if (bind(servsock, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0) errx(1, "bind port %d: %s\n", port, strerror(errno)); @@ -143,7 +151,7 @@ net_poll() { void net_client_accept(int servsock) { - struct sockaddr_in clientaddr; + struct sockaddr_in6 clientaddr; int cfd; socklen_t slen; cfd=accept(servsock, (struct sockaddr *)&clientaddr, &slen); @@ -159,7 +167,6 @@ net_client_accept(int servsock) { for (clientid=0; clientid