Reputation: 6573
I have an ipv4 server that only accepts connections over localhost (using INADDR_LOOPBACK
). I'd like to convert this server to be dual-stack ipv6/ipv4. However, using in6addr_loopback
only accepts connections to ::1
.
I've found that I can accept ipv4 and ipv6 connections simultaneously using in6addr_any
, but as this also allows connections from anywhere it's not useful for my particular case.
Is it possible to bind to ipv6 localhost (::1
) and ipv4 localhost (127.0.0.1
) simultaneously?
Upvotes: 5
Views: 4264
Reputation: 76581
AFAIK, that is not possible.
What you will need to do is create two sockets, one bound to INADDR_LOOPBACK and one bound to in6addr_loopback. You can then wait on both of them simultaneously using your multiplexer of choice (poll, select, epoll, etc0).
Update
Just came up with some work-arounds that you may want to consider. In both of these work-arounds, you bind to in6addr_any
.
Upvotes: 4
Reputation: 17728
Just because your server is dual-stack, does your localhost-only app really need to be? Can you just pick one and go with it?
Upvotes: -4