* Memory alignment issue in a network protocol header
@ 2008-04-18 3:08 Eus
0 siblings, 0 replies; only message in thread
From: Eus @ 2008-04-18 3:08 UTC (permalink / raw)
To: Linux Networking Mailing List
Hi Ho!
I am implementing a networking protocol (http://sourceforge.net/projects/atn).
This networking protocol has the following header:
struct clnphdr {
__u8 cnf_proto_id;
__u8 cnf_hdr_len;
__u8 cnf_vers;
__u8 cnf_ttl;
__u8 cnf_flag;
__be16 cnf_seglen;
__u8 cnf_cksum_msb;
__u8 cnf_cksum_lsb;
__u8 dest_len;
__u8 dest_addr[20];
__u8 src_len;
__u8 src_addr[20];
__u8 next_part[0];
};
Because of 4-byte memory alignment in i386, there will be 1-byte padding in
`cnf_seglen'.
This alignment prevents me from doing:
struct clnphdr clnph = (struct clnphdr *) skb->nh.raw;
because ntohs(clnph->cnf_seglen) will return the wrong result.
The wrong result will occur because in `skb->nh.raw' the data is packed (no
hole).
The easiest solution will be to put __attribute__((packed)) in the definition of
struct clnphdr, but this will incur performance penalty, won't this?
So, how should I handle this problem in the proper way as to permit portability
to 64-bit machines as well?
Thank you very much.
Best regards,
Eus
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-04-18 3:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-18 3:08 Memory alignment issue in a network protocol header Eus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).