Download raw body.
gotwebd: listen on localhost by default
On Fri, Aug 19, 2022 at 06:55:02PM +0200, Stefan Sperling wrote: > On Fri, Aug 19, 2022 at 06:52:11PM +0200, Stefan Sperling wrote: > > And now, without an explicit port number set in the config file, > > gotwebd listens on the wrong port number because of a byte-swap bug. > > > > I forgot to include netstat output. > > Before: > tcp 0 0 127.0.0.1.10275 *.* LISTEN > tcp6 0 0 ::1.10275 *.* LISTEN > > After: > tcp 0 0 127.0.0.1.9000 *.* LISTEN > tcp6 0 0 ::1.9000 *.* LISTEN > > > Fix below. ok? Tracey OK'd my patch on IRC, and I have also committed this follow-up fix: ----------------------------------------------- commit 859aa9f48371a84128b60e2c2ba9f873a4ea70cf (main, origin/main) from: Stefan Sperling <stsp@stsp.name> date: Fri Aug 19 17:06:28 2022 UTC fix previous: store port number in host byte order, convert for struct sockaddr With the previous patch the listen port was correct, but the debug log output was still displaying the swapped port number. Now both listen behaviour and debug log output agree. diff d72940a3a166aaa6620b4b444af1fa16b5e216f5 859aa9f48371a84128b60e2c2ba9f873a4ea70cf commit - d72940a3a166aaa6620b4b444af1fa16b5e216f5 commit + 859aa9f48371a84128b60e2c2ba9f873a4ea70cf blob - b23d9fe465844dc654c2dce903331128cc7ae3f1 blob + 601286fd54eb92e666ed42a52b7d7a851eb91940 --- gotwebd/parse.y +++ gotwebd/parse.y @@ -1037,10 +1037,10 @@ getservice(const char *n) s = getservbyname(n, "udp"); if (s == NULL) return (-1); - return htons(s->s_port); + return ntohs(s->s_port); } - return (htons((unsigned short)llval)); + return (unsigned short)llval; } struct address * blob - 836377578903d72f44f5cc1ae1fecf1e440af00c blob + 25fab90e6eb901da603fae558a1308fabac74bf1 --- gotwebd/sockets.c +++ gotwebd/sockets.c @@ -486,10 +486,10 @@ sockets_create_socket(struct address *a, in_port_t por switch (a->ss.ss_family) { case AF_INET: - ((struct sockaddr_in *)(&a->ss))->sin_port = port; + ((struct sockaddr_in *)(&a->ss))->sin_port = htons(port); break; case AF_INET6: - ((struct sockaddr_in6 *)(&a->ss))->sin6_port = port; + ((struct sockaddr_in6 *)(&a->ss))->sin6_port = htons(port); break; default: log_warnx("%s: unknown address family", __func__);
gotwebd: listen on localhost by default