Damn qqq-bird. ;)
[obnox/wireshark/wip.git] / capture-pcap-util.h
1 /* capture-pcap-util.h
2  * Utility definitions for packet capture
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifndef __PCAP_UTIL_H__
26 #define __PCAP_UTIL_H__
27
28 #ifdef HAVE_LIBPCAP
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 #include <epan/address.h>
35
36 #include <pcap.h>
37
38 /*
39  * XXX - this is also the traditional default snapshot size in
40  * tcpdump - but, if IPv6 is enabled, it defaults to 96, to get an
41  * IPv6 header + TCP + 22 extra bytes.
42  *
43  * Some libpcap versions for particular capture devices might happen
44  * to impose a minimum, but it's not always 68.
45  */
46 #define MIN_PACKET_SIZE 68      /* minimum amount of packet data we can read */
47
48 /*
49  * The list of interfaces returned by "get_interface_list()" is
50  * a list of these structures.
51  */
52 typedef struct {
53         char    *name;          /* e.g. "eth0" */
54         char    *description;   /* from OS, e.g. "Local Area Connection" or NULL */
55         GSList  *ip_addr;       /* containing address values of if_addr_t */
56         gboolean loopback;      /* TRUE if loopback, FALSE otherwise */
57 } if_info_t;
58
59 /*
60  * An address in the "ip_addr" list.
61  */
62 typedef struct {
63         address_type type;      /* AT_IPv4 or AT_IPv6 */
64         union {
65                 guint32 ip4_addr;   /*  4 byte IP V4 address, or */
66                 guint8 ip6_addr[16];/* 16 byte IP V6 address */
67         } ip_addr;
68 } if_addr_t;
69
70 GList *get_interface_list(int *err, char **err_str);
71
72 /* Error values from "get_interface_list()". */
73 #define CANT_GET_INTERFACE_LIST 0       /* error getting list */
74 #define NO_INTERFACES_FOUND     1       /* list is empty */
75
76 void free_interface_list(GList *if_list);
77
78 /*
79  * The list of data link types returned by "get_pcap_linktype_list()" is
80  * a list of these structures.
81  */
82 typedef struct {
83         int     dlt;                /* e.g. DLT_EN10MB (which is 1) */
84         char    *name;          /* e.g. "EN10MB" or "DLT 1" */
85         char    *description;   /* descriptive name from wiretap e.g. "Ethernet", NULL if unknown */
86 } data_link_info_t;
87
88 GList *get_pcap_linktype_list(char *devname, char **err_str);
89 void free_pcap_linktype_list(GList *linktype_list);
90
91 /* get/set the link type of an interface */
92 /* (only used in capture_loop.c / capture-pcap-util.c) */
93 int get_pcap_linktype(pcap_t *pch, const char *devname);
94 const char *set_pcap_linktype(pcap_t *pch, char *devname, int dlt);
95
96
97 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
98 const char *linktype_val_to_name(int dlt);
99 #endif
100 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
101 int linktype_name_to_val(const char *linktype);
102 #endif
103
104 #ifdef __cplusplus
105 }
106 #endif /* __cplusplus */
107
108 #endif /* HAVE_LIBPCAP */
109
110 /*
111  * Append to a GString an indication of the version of libpcap/WinPcap
112  * with which we were compiled, if we were, or an indication that we
113  * weren't compiled with libpcap/WinPcap, if we weren't.
114  */
115 extern void get_compiled_pcap_version(GString *str);
116
117 /*
118  * Append to a GString an indication of the version of libpcap/WinPcap
119  * with which we're running, or an indication that we're not running
120  * with libpcap/WinPcap, if we were compiled with libpcap/WinPcap,
121  * or nothing, if we weren't compiled with libpcap/WinPcap.
122  */
123 extern void get_runtime_pcap_version(GString *str);
124
125 #endif /* __PCAP_UTIL_H__ */