netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eus <eus@member.fsf.org>
To: Linux Networking Mailing List <netdev@vger.kernel.org>
Subject: Memory alignment issue in a network protocol header
Date: Thu, 17 Apr 2008 20:08:41 -0700 (PDT)	[thread overview]
Message-ID: <695248.45047.qm@web37605.mail.mud.yahoo.com> (raw)

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

                 reply	other threads:[~2008-04-18  3:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=695248.45047.qm@web37605.mail.mud.yahoo.com \
    --to=eus@member.fsf.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).