alignment requirement when compiling TCP/IP implementation

Hi

I am reading TCP/IP Illustrated, Vol. 2 by Stevens. In page 215, it says

'In C, the easiest way to process data located in an untyped area of memory is to overlay a structure on the area of memory and process the structure members instead of raw bytes...'

In the source code, it's like this:

Code:
struct ip *ip;
struct mbuf *m;

...

ip = mtod(m, struct ip*);

//then use ip member w/o parsing the header
ip->ip_sum ..

My question is struct ip has the same bytes layout of ip protocol header only when alignment is 1, but this would hurt performance, or even not allowed on certain CPUs

Can someone help me understand this?

Thanks,
Baihao
 
Packet duplication to an aligned structure would hurt performance more than reading unaligned data using register shifting.
 
Back
Top