[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] Adding ipv6 support.
On 2011-02-07 12:53, Dave Hart wrote:
> If you only care about IPv4 and IPv6 sockets, consider using a union
> of the useful types:
>
> typedef struct union_saddr_tag {
> struct sockaddr sa;
> struct sockaddr_in sin;
> struct sockaddr_in6 sin6;
> } union_saddr;
>
> Then use union_saddr as your generic type, distinguishing variants
> using sa.sa_family. When calling functions that take a sockaddr *,
> use &my_saddr.sa and no potentially-bug-hiding cast is required.
Bad idea. You're substituting an explicit cast with an implicit cast.
An implicit cast is no less "potentially-bug-hiding". An explicit cast
at least *looks* like a cast, so that you can be extra careful when you
see one. When casting, you *want* the code to look ugly, to force you to
think about what you're doing.
Furthermore, you're ignoring alignment issues.
The best current practice is to use sockaddr_storage. See e.g.
http://www.kame.net/newsletter/19980604/ for more info.
Simon
--
DTN made easy, lean, and smart --> http://postellation.viagenie.ca
NAT64/DNS64 open-source --> http://ecdysis.viagenie.ca
STUN/TURN server --> http://numb.viagenie.ca
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.