On Wed, 19 Jan 2022 08:57:51 +0100 "Dr. Arne Babenhauserheide" <arne_...@web.de> wrote: > Hi, > > > with both fibers server and (web server) there is a split between IPv4 > and IPv6: > > IPv4: > > (fibers:run-server handler-with-path #:family AF_INET #:port port #:addr > INADDR_ANY) > > (run-server handler-with-path 'http `(#:host "localhost" #:family > ,AF_INET #:addr ,INADDR_ANY #:port ,port)) > > IPv6: > > (define s > (let ((s (socket AF_INET6 SOCK_STREAM 0))) > (setsockopt s SOL_SOCKET SO_REUSEADDR 1) > (bind s AF_INET6 (inet-pton AF_INET6 ip) port) > s)) > (fibers:run-server handler-with-path #:family AF_INET6 #:port port #:addr > (inet-pton AF_INET6 ip) #:socket s) > > (define s > (let ((s (socket AF_INET6 SOCK_STREAM 0))) > (setsockopt s SOL_SOCKET SO_REUSEADDR 1) > (bind s AF_INET6 (inet-pton AF_INET6 ip) port) > s)) > (run-server handler-with-path 'http `(#:family ,AF_INET6 #:addr > (inet-pton AF_INET6 ip) #:port ,port #:socket ,s)) > > > Is there a way to bind to both IPv6 and IPv4, so my server will react to > requests regardless of whether a client reaches my computer over IPv4 or > IPv6?
As I understand it, with linux IPv6 sockets are dual stack capable, and in earlier kernel versions this was be enabled by default. I believe with current versions that is no longer the case, and that you have to specifically enable dual stack by turning off IPV6_V6ONLY using setsockopt before binding on the socket. Then, if receiving a IPv4 connection from address 1.2.3.4, this would be mapped as ::::ffff:1.2.3.4. I do not know about other OSes. I have half a memory that some earlier versions of windows did not support dual stack sockets (XP?).