]>
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.
24 #include <sys/types.h>
33 * Private data for storing sets of options.
34 * This is to be used by functions which seem to grow additional options
35 * This is avoid ABI explosion of do_thing, and do_thing_with_opt_bar(),
36 * and then do_thing_with_opt_bar_baz(...). Instead a "pcap_option" should be
37 * created to which get/set shall be done.
39 * each option shall have an element in enum pcap_option_name {}.
43 const char *io_read_plugin
;
44 const char *io_write_plugin
;
47 pcap_options
*pcap_alloc_option(void)
49 pcap_options
*po
= malloc(sizeof(struct pcap_options
));
50 memset(po
, 0, sizeof(struct pcap_options
));
51 return po
; // caller has to check for NULL anyway.
54 void pcap_free_option(pcap_options
*po
)
57 if(po
->io_read_plugin
) free((void *)po
->io_read_plugin
);
58 if(po
->io_write_plugin
) free((void *)po
->io_write_plugin
);
63 /* Return 0 on success, -1 on failure invalid option, -2 on type mismatch */
64 int pcap_set_option_string(pcap_options
*po
,
65 enum pcap_option_name pon
,
68 const char *saved
= strdup(value
);
70 case PON_TSTAMP_PRECISION
:
74 case PON_IO_READ_PLUGIN
:
75 po
->io_read_plugin
= saved
;
77 case PON_IO_WRITE_PLUGIN
:
78 po
->io_write_plugin
= saved
;
87 /* Return 0 on success, -1 on failure invalid option, -2 on type mismatch */
88 int pcap_set_option_int(pcap_options
*po
,
89 enum pcap_option_name pon
,
93 case PON_TSTAMP_PRECISION
:
94 po
->tstamp_precision
= value
;
97 case PON_IO_READ_PLUGIN
:
98 case PON_IO_WRITE_PLUGIN
:
106 const char *pcap_get_option_string(pcap_options
*po
,
107 enum pcap_option_name pon
)
110 case PON_TSTAMP_PRECISION
:
113 case PON_IO_READ_PLUGIN
:
114 return po
->io_read_plugin
;
115 case PON_IO_WRITE_PLUGIN
:
116 return po
->io_write_plugin
;
122 /* return int value, or zero for not-found, mis-type */
123 int pcap_get_option_int(pcap_options
*po
,
124 enum pcap_option_name pon
)
127 case PON_TSTAMP_PRECISION
:
128 return po
->tstamp_precision
;
131 case PON_IO_READ_PLUGIN
:
132 case PON_IO_WRITE_PLUGIN
: