Guy Harris wrote:
Andy Howell wrote:
How about having a generic list of options? Something like:
typedef enum {
END_OF_OPTS,
PARAM_1,
PARAM_2,
} pcap_opts;
typedef union {
void *p;
unsigned int u;
} pcap_opt_value;
That assumes that an option will either be an "unsigned int" or a pointer.
I didn't mean to limit it to those. In fact, it should have at least a
long long as well. However, for the pointer option we'd probable want a
length associated with it.
I'd be inclined to have something more like
typedef struct {
bpf_u_int32 option;
bpf_u_int32 optlen;
} pcap_opthdr;
with the buffer being a sequence of pcap_opthdr structures followed by
option values. "option" is the code for the option type (with 0 being
the "end of option list" option), and "optlen" is the length of the
option value (so an application can skip options it doesn't understand).
"pcap_opthdr" is 64 bits long, so as long as the option buffer is
aligned on a {32-bit,64-bit} boundary, the options will be aligned on
that boundary as well (and if the option buffer is mallocated, it'll be
aligned on the strictest boundary required for C data types).
My two concerns here are the alignment and ease of use. If you have a
64bit value then all option buffers it have to be 64 bit aligned. Either
that or the open function has memcpy the values out. While its not while
not too difficult to build up the options by mallocing the memory and
manually laying out the values, it does seem a bit cumbersome.
How about:
typedef struct {
bpf_u_int32 option;
bpf_u_int32 optlen;
void * option;
} pcap_opthdr;
Then its easy to create the options list ether by initializing an array
of pcap_opthdr's or mallocing the memory and setting the values.
Regards,
Andy
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.