Re: [mongrel2] Question for IPv6 Experts
- From:
- Samuel Tardieu
- Date:
- 2010-12-08 @ 22:47
2010/12/8 Zed A. Shaw <zedshaw@zedshaw.com>
> I've been trying for a while now to find out why, when I use ipv4, do
> the access logs not show the remote host. I've figured out that
> inet_ntop and/or accept don't fill in the sockaddr_in6 structure right,
> so the address is all screwed up. I'm having to do this lame hack:
>
> http://mongrel2.org/info/976df1d3c6
>
> But I know this can't be correct. Can someone check out what I've done
> here and make it right?
>
This is expected. If you look at the definitions of sockaddr_in and
sockaddr_in6 in netinet/in.h on Linux for example, you'll notice that the
offset of sin_addr (for IPv4) and of sin6_addr (for IPv6) are different.
Also, "*port = ntohs(sa.sin6_port);" happens to work by chance only, as it
could be wrong for an IPv4 address (nothing guarantees that the port will be
stored at the same place for both address families). The only guarantee you
can count on is that sin_addr and sin6_addr will be at the same offset (or
you wouldn't be able to check the family otherwise).
You can get something more elegant by declaring both your structures in a
union and using address family checks. See
https://gist.github.com/734054for a possible solution (totally
untested).
Sam
--
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/blog/
Re: [mongrel2] Question for IPv6 Experts
- From:
- Zed A. Shaw
- Date:
- 2010-12-08 @ 23:44
On Wed, Dec 08, 2010 at 11:47:31PM +0100, Samuel Tardieu wrote:
> You can get something more elegant by declaring both your structures in a
> union and using address family checks. See
> https://gist.github.com/734054for a possible solution (totally
> untested).
Alright, redid this so that IPv6 or IPv4 addresses show up in the logs.
If anyone with IPv6 can test the latest code I'd appreciate it.
--
Zed A. Shaw
http://zedshaw.com/