The only guaranteed way to avoid compiler padding (that I know of,
anyway) is to avoid using non-byte values in structures. Make the
holding_timer and pdu_length structures into guint8[2] instead of
guint16.
The functions pntohs|l are useful in this context, because you can do
something like this
...
guint8 holding_timer_array[2]
... and then
i = pntohs(&struct->holding_timer_array[0]);
If you're lucky enough to have a structure where the multibyte
primitives start on 32-bit boundaries (and you're running on a 32-bit
machine) then you may be in luck. Doesn't seem true in your case,
however - I count 7 bytes in your structure before holding_timer.
-Ashok
Stuart Stanley writes:
>
> Hello,
>
> I am working on adding IS-IS protocol unpacking. Given that OSI loves to
> use lots of packed bytes, I ran into a packing problem pretty much right
> off the bat. The question is, what is the "official" way for doing
> structure overlays onto the PDU without having the compiler play with
> the alignment. For example:
>
> typedef struct {
> guint8 isis_hello_circuit_reserved; /* circuit type & reserved */
> guint8 isis_hello_source_id[6]; /* source id */
> guint16 isis_hello_holding_timer; /* holding timer */
> guint16 isis_hello_pdu_length; /* full length, includ. hdr */
> guint8 isis_hello_priority_reserved; /* priority & reserved */
> guint8 isis_hello_lan_id[7]; /* LAN id */
> } isis_hello_t;
>
> Later, I was planning on doing a (in a dissector)
>
> isis_hello_t *ihd;
>
> ihd = (isis_hello_t) *pd;
>
>
> Now, when I access ihd->isis_hello_holding_timer, I am missing an octet.
> After playing around, I found isis_hello_t has an extra octet stuck
> between the source_id and the holding timer. ooops.
>
> I can see a couple of routes to do this, but what is the best "style"
> for this. I guess on a similar note, which dissector would make a good
> example of current good dissector coding style?
>
> Thanks for the great framework on this, BTW!
>
>
>
> Life is something set to music; I can hear it | Stuart Stanley
> when I'm sad. There's a chord in every muscle, | stuarts@xxxxxxxxxx
> every kiss you've ever had -- Heather Nova | Lucent Technologies,
> | Eden Prairie, MN
> | 612.996.6829
>
--
--- Asok the Intern ----------------------------------------
IOS Network Protocols, Cisco Systems
250 Apollo Drive, Chelmsford, MA 01824
Ph: 978-244-8387