Subject: Re: struct route
To: None <tech-net@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-net
Date: 07/13/2000 12:44:12
>>> struct route {
>>> 	struct rtentry *ro_rt;
>>> 	union {
>>> 		struct sockaddr roun_dst_sa;
>>> 		struct sockaddr_storage roun_dst_ss;
>>> 	} ro_un;
>>> #define	ro_dst		ro_un.roun_dst_sa	/* compatiblity */
>>> #define	ro_dst_sa	ro_un.roun_dst_ss
>>> };

This still doesn't address the alignment issue.  (There's no guarantee
that either sockaddr or sockaddr_storage is aligned sufficiently
stringently for sockaddr_foo for any other foo - or is that part of
sockaddr_storage's interface contract?)

>> 	we tried the above already.  it choked sys/netiso (ro_dst is
>> 	used as the name of struct member, and chokes with #define).

We really really need transparent unions:

struct route {
	struct rtentry *ro_rt;
	union {
		struct sockaddr ro_dst;
		struct sockaddr_storage ro_dst_sa;
	};
};

or perhaps union { ... } __transparent__; or some such.  The idea is to
hoist the union member names up a level, so they behave syntactically
like direct members of struct route.

Of course, I have no idea how hard it would be to make gcc do this.
(It'd also make the code hell on other compilers....)

					der Mouse

			       mouse@rodents.montreal.qc.ca
		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B