Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: [Wireshark-dev] Help with pointer to unions

From: Alex Lindberg <alindber@xxxxxxxxx>
Date: Mon, 18 Apr 2011 09:09:55 -0700 (PDT)
I am working on a dissector that is version dependent.  I have created a union that contains the structs of both versions:

typedef struct _proto_struct {
  STRUCT_1 s1;
  STRUCT_2 s2;
} s_t;
s_t *s;

Memory for s is created based on version and sizeof(s1) or sizeof(s2).

Thus, to reference V1 it would be s->s1, V2 would bes->s2.  Both s1 and s2 have much in common.  I would like to create a single pointer ptr,  that would point to s1 or s2 as necessary that would be used to simplify the access to the structs without having to specifically cast ptr to the struct.

How could this be done?

Thanks as always.
Alex Lindberg