[<prev] [next>] [day] [month] [year] [list]
Message-ID: <695248.45047.qm@web37605.mail.mud.yahoo.com>
Date: Thu, 17 Apr 2008 20:08:41 -0700 (PDT)
From: Eus <eus@...ber.fsf.org>
To: Linux Networking Mailing List <netdev@...r.kernel.org>
Subject: Memory alignment issue in a network protocol header
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
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists