Fabian Hugelshofer wrote: > Patrick McHardy wrote: >> Fabian Hugelshofer wrote: >>> Aligns buffers to maximum alignment of architecture to make the cast of >>> char pointers to struct pointers more portable. >>> >>> Signed-off-by: Fabian Hugelshofer >> >> They all seem fine to me, but a union might make it look >> a bit nicer :) > > In libnfnetlink the union does not make sense, because multiple casts > are done from the same buffer at different locations. > > For libnetfilter-(conntrack|log) the union would be possible: > > Original (aligned): > << code begin >> > char buf[...] __attribute__ ((aligned)); > struct nlmsghdr *nmh = (struct nlmsghdr *) buf; > > nfnl_fill_hdr(h->nfnlssh, nmh, 0, pf, queuenum, ...); > << code end >> > > Union style: > << code begin >> > union { > char buf[...]; > struct nlmsghdr nmh; > } u; > > nfnl_fill_hdr(h->nfnlssh, &u.nmh, 0, pf, queuenum, ...); > << code end >> > > I can rewrite it like this, if desired... Please, use union wherever it is possible. BTW, it seems to me that the conntrack-tools may suffer from the same portability problem. The (supposed) fix, which is attached, is ugly but union does not help since the size of struct nf_conntrack is not known. I do not find a way to do this cleanly without removing the use of the stack for temporary object allocation. -- "Los honestos son inadaptados sociales" -- Les Luthiers