]>
The Tcpdump Group git mirrors - libpcap/blob - pcap-options.c
2 * Copyright (c) 1993, 1994, 1995, 1996, 1998
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 #include <sys/types.h>
35 * Private data for storing sets of options.
36 * This is to be used by functions which seem to grow additional options
37 * This is avoid ABI explosion of do_thing, and do_thing_with_opt_bar(),
38 * and then do_thing_with_opt_bar_baz(...). Instead a "pcap_option" should be
39 * created to which get/set shall be done.
41 * each option shall have an element in enum pcap_option_name {}.
45 const char *io_read_plugin
;
46 const char *io_write_plugin
;
49 pcap_options
*pcap_alloc_option(void)
51 pcap_options
*po
= malloc(sizeof(struct pcap_options
));
52 memset(po
, 0, sizeof(struct pcap_options
));
53 return po
; // caller has to check for NULL anyway.
56 void pcap_free_option(pcap_options
*po
)
59 if(po
->io_read_plugin
) free((void *)po
->io_read_plugin
);
60 if(po
->io_write_plugin
) free((void *)po
->io_write_plugin
);
65 /* Return 0 on success, -1 on failure invalid option, -2 on type mismatch */
66 int pcap_set_option_string(pcap_options
*po
,
67 enum pcap_option_name pon
,
70 const char *saved
= strdup(value
);
72 case PON_TSTAMP_PRECISION
:
76 case PON_IO_READ_PLUGIN
:
77 po
->io_read_plugin
= saved
;
79 case PON_IO_WRITE_PLUGIN
:
80 po
->io_write_plugin
= saved
;
89 /* Return 0 on success, -1 on failure invalid option, -2 on type mismatch */
90 int pcap_set_option_int(pcap_options
*po
,
91 enum pcap_option_name pon
,
95 case PON_TSTAMP_PRECISION
:
96 po
->tstamp_precision
= value
;
99 case PON_IO_READ_PLUGIN
:
100 case PON_IO_WRITE_PLUGIN
:
108 const char *pcap_get_option_string(pcap_options
*po
,
109 enum pcap_option_name pon
)
112 case PON_TSTAMP_PRECISION
:
115 case PON_IO_READ_PLUGIN
:
116 return po
->io_read_plugin
;
117 case PON_IO_WRITE_PLUGIN
:
118 return po
->io_write_plugin
;
124 /* return int value, or zero for not-found, mis-type */
125 int pcap_get_option_int(pcap_options
*po
,
126 enum pcap_option_name pon
)
129 case PON_TSTAMP_PRECISION
:
130 return po
->tstamp_precision
;
133 case PON_IO_READ_PLUGIN
:
134 case PON_IO_WRITE_PLUGIN
: