emikulic / darkhttpd

When you need a web server in a hurry.
https://unix4lyfe.org/darkhttpd/
ISC License
1.03k stars 83 forks source link

Listen on IPv4 and IPv6 #37

Closed hhartzer closed 7 months ago

hhartzer commented 7 months ago

Hi,

Is it possible to listen on IPv4 and IPv6 at the same time? On Linux, the default is generally that IPv6 sockets also listen on IPv4. On FreeBSD this is not the default, so one would have to launch two servers to serve both.

Thank you!

emikulic commented 7 months ago

I haven't looked into how to do this on FreeBSD. I'd be willing to merge a patch that did this.

hhartzer commented 7 months ago

Sounds good!

I started working on this and noticed an interesting bug.

$ ./darkhttpd --ipv6
darkhttpd/1.15.from.git, copyright (c) 2003-2024 Emil Mikulic.
listening on: http://0.0.0.0:8080/
^C
$ ./darkhttpd . --ipv6
darkhttpd/1.15.from.git, copyright (c) 2003-2024 Emil Mikulic.
listening on: http://[::]:8080/
^C

I also wonder if the best behavior, down the road, might be accepting --listen arguments that would take IP and port pairs (or maybe just IP). Could also just be multiple --addr and IPv4/IPv6 support could be handled that way.