On Sun, Nov 01, 2009 at 02:41:21PM +0100, Jan Engelhardt wrote: > > On Sunday 2009-11-01 14:07, Pierre Chifflier wrote: > > >> >+ ip = (struct iphdr *) data; > >> > >> If data is not aligned, later dereferencing can fail :( > > > >I remember some arches (sparc, arm ?) will send a signal (SIGBUS I > >think) in this case. > >How can I prevent data from being unaligned ? > >Adding some __attribute__((aligned(4)) will be enough ? > > __attribute__(aligned) only specifies the minimum requirement. > > What one would need is __attribute__((packed)), and it needs > to be on struct iphdr - in /usr/include/... - and that is the > problem because you cannot change it. > And gcc does not allow saying (ignored the attribute) > > struct iphdr __attribute__((packed)) *iph = data; > > So.. tough luck. It seems gcc does not appreciate: ulogd_inppkt_UNIXSOCK.c:352: warning: ‘packed’ attribute ignored I can see the problem, but I can't see any solution without memcpy'ing the data several times :( Generally speaking, what is the best way to deal with these kind of Key-Kength-Value protocols and alignment ? Since I do not not the size of the elements and that most of them are strings, it's very unlikely the result is going to be aligned. Should I memcpy each element before using it ? Or does a better (in terms of performance) solution ? Thanks, Pierre -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html