Re: structre object question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2005-01-31 at 16:20 +0530, cranium 2003 wrote:
> Hello,
>   In linux kernel source etheernet header is defined as structure as
> struct ethhdr
> {
>         unsigned char   h_dest[ETH_ALEN];       /* destination eth addr */
>         unsigned char   h_source[ETH_ALEN];     /* source ether addr    */
>         unsigned short  h_proto;                /* packet type ID field */
> } __attribute__((packed));
> I want to know what __attribute__((packed)) meance?
>        It is not looking as a structure object  then what is thati?

Your ethernet header is 14 bytes long so the "packed" attribute
tells the compiler to to pack the structure to 14 bytes and not
try to byte align it on a word boundary (as it would do without
specifying this keyword).

from "info gcc"

`packed'
     The `packed' attribute specifies that a variable or structure field
     should have the smallest possible alignment--one byte for a
     variable, and one bit for a field, unless you specify a larger
     value with the `aligned' attribute.

     Here is a structure in which the field `x' is packed, so that it
     immediately follows `a':

          struct foo
          {
            char a;
            int x[2] __attribute__ ((packed));
          };


HTH,
-mandeep

> regards,
> cranium
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux