Export libwireshark symbols using WS_DLL_PUBLIC define
[metze/wireshark/wip.git] / epan / addr_resolv.h
1 /* addr_resolv.h
2  * Definitions for network object lookup
3  *
4  * $Id$
5  *
6  * Laurent Deniel <laurent.deniel@free.fr>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26 /* The buffers returned by these functions are all allocated with a
27  * packet lifetime and does not have have to be freed.
28  * However, take into account that when the packet dissection
29  * completes, these buffers will be automatically reclaimed/freed.
30  * If you need the buffer to remain for a longer scope than packet lifetime
31  * you must copy the content to an se_alloc() buffer.
32  */
33
34 #ifndef __RESOLV_H__
35 #define __RESOLV_H__
36
37 #include <epan/address.h>
38 #include <epan/tvbuff.h>
39 #include "ws_symbol_export.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44
45 #ifndef MAXNAMELEN
46 #define MAXNAMELEN      64      /* max name length (hostname and port name) */
47 #endif
48
49 typedef struct _e_addr_resolve {
50   gboolean mac_name;
51   gboolean network_name;
52   gboolean transport_name;
53   gboolean concurrent_dns;
54   gboolean use_external_net_name_resolver;
55   gboolean load_hosts_file_from_profile_only;
56 } e_addr_resolve;
57
58 /*
59  * Flag controlling what names to resolve.
60  */
61 WS_DLL_PUBLIC e_addr_resolve gbl_resolv_flags;
62
63 /* global variables */
64
65 extern gchar *g_ethers_path;
66 extern gchar *g_ipxnets_path;
67 extern gchar *g_pethers_path;
68 extern gchar *g_pipxnets_path;
69
70 /* Functions in addr_resolv.c */
71
72 /*
73  * get_udp_port() returns the port name corresponding to that UDP port,
74  * or the port number as a string if not found.
75  */
76 WS_DLL_PUBLIC gchar *get_udp_port(guint port);
77
78 /*
79  * get_tcp_port() returns the port name corresponding to that TCP port,
80  * or the port number as a string if not found.
81  */
82 WS_DLL_PUBLIC gchar *get_tcp_port(guint port);
83
84 /*
85  * get_dccp_port() returns the port name corresponding to that DCCP port,
86  * or the port number as a string if not found.
87  */
88 extern gchar *get_dccp_port(guint port);
89
90 /*
91  * get_sctp_port() returns the port name corresponding to that SCTP port,
92  * or the port number as a string if not found.
93  */
94 WS_DLL_PUBLIC gchar *get_sctp_port(guint port);
95
96 /* get_addr_name takes as input an "address", as defined in address.h */
97 /* it returns a string that contains: */
98 /*  - if the address is of a type that can be translated into a name, and the user */
99 /*    has activated name resolution, the translated name */
100 /*  - if the address is of type AT_NONE, a pointer to the string "NONE" */
101 /*  - if the address is of any other type, the result of ep_address_to_str on the argument, */
102 /*    which should be a string representation for the answer -e.g. "10.10.10.10" for IPv4 */
103 /*    address 10.10.10.10 */
104
105 WS_DLL_PUBLIC
106 const gchar *get_addr_name(const address *addr);
107 const gchar *se_get_addr_name(const address *addr);
108
109 /* get_addr_name_buf solves an address in the same way as get_addr_name above */
110 /* The difference is that get_addr_name_buf takes as input a buffer, into which it puts */
111 /* the result which is always NUL ('\0') terminated. The buffer should be large enough to */
112 /* contain size characters including the terminator */
113
114 void get_addr_name_buf(const address *addr, gchar *buf, gsize size);
115
116
117 /*
118  * Asynchronous host name lookup initialization, processing, and cleanup
119  */
120
121 /* Setup name resolution preferences */
122 struct pref_module;
123 extern void addr_resolve_pref_init(struct pref_module *nameres);
124
125 /* host_name_lookup_init fires up an ADNS socket if we're using ADNS */
126 extern void host_name_lookup_init(void);
127
128 /** If we're using c-ares or ADNS, process outstanding host name lookups.
129  *  This is called from a GLIB timeout in Wireshark and before processing
130  *  each packet in TShark.
131  *
132  * @return True if any new objects have been resolved since the previous
133  * call. This can be used to trigger a display update, e.g. in Wireshark.
134  */
135 WS_DLL_PUBLIC gboolean host_name_lookup_process(void);
136
137 /* host_name_lookup_cleanup cleans up an ADNS socket if we're using ADNS */
138 extern void host_name_lookup_cleanup(void);
139
140 /* get_hostname returns the host name or "%d.%d.%d.%d" if not found */
141 WS_DLL_PUBLIC const gchar *get_hostname(const guint addr);
142
143 /* get_hostname6 returns the host name, or numeric addr if not found */
144 struct e_in6_addr;
145 WS_DLL_PUBLIC const gchar* get_hostname6(const struct e_in6_addr *ad);
146
147 /* get_ether_name returns the logical name if found in ethers files else
148    "<vendor>_%02x:%02x:%02x" if the vendor code is known else
149    "%02x:%02x:%02x:%02x:%02x:%02x" */
150 WS_DLL_PUBLIC gchar *get_ether_name(const guint8 *addr);
151
152 /* get_ether_name returns the logical name if found in ethers files else NULL */
153 gchar *get_ether_name_if_known(const guint8 *addr);
154
155 /*
156  * Given a sequence of 3 octets containing an OID, get_manuf_name()
157  * returns the vendor name, or "%02x:%02x:%02x" if not known.
158  */
159 extern const gchar *get_manuf_name(const guint8 *addr);
160
161 /*
162  * Given a sequence of 3 octets containing an OID, get_manuf_name_if_known()
163  * returns the vendor name, or NULL if not known.
164  */
165 WS_DLL_PUBLIC const gchar *get_manuf_name_if_known(const guint8 *addr);
166
167 /*
168  * Given an integer containing a 24-bit OID, uint_get_manuf_name()
169  * returns the vendor name, or "%02x:%02x:%02x" if not known.
170  */
171 extern const gchar *uint_get_manuf_name(const guint oid);
172
173 /*
174  * Given an integer containing a 24-bit OID, uint_get_manuf_name_if_known()
175  * returns the vendor name, or NULL if not known.
176  */
177 extern const gchar *uint_get_manuf_name_if_known(const guint oid);
178
179 /*
180  * Given a tvbuff and an offset in that tvbuff for a 3-octet OID,
181  * tvb_get_manuf_name() returns the vendor name, or "%02x:%02x:%02x"
182  * if not known.
183  */
184 WS_DLL_PUBLIC const gchar *tvb_get_manuf_name(tvbuff_t *tvb, gint offset);
185
186 /*
187  * Given a tvbuff and an offset in that tvbuff for a 3-octet OID,
188  * tvb_get_manuf_name_if_known() returns the vendor name, or NULL
189  * if not known.
190  */
191 WS_DLL_PUBLIC const gchar *tvb_get_manuf_name_if_known(tvbuff_t *tvb, gint offset);
192
193 /* get_eui64_name returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the vendor code is known
194    "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" */
195 extern const gchar *get_eui64_name(const guint64 addr);
196
197 /* get_eui64_name_if_known returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the vendor code is known else NULL */
198 extern const gchar *get_eui64_name_if_known(const guint64 addr);
199
200
201 /* get_ipxnet_name returns the logical name if found in an ipxnets file,
202  * or a string formatted with "%X" if not */
203 extern const gchar *get_ipxnet_name(const guint32 addr);
204
205 /* returns the ethernet address corresponding to name or NULL if not known */
206 extern guint8 *get_ether_addr(const gchar *name);
207
208 /* returns the ipx network corresponding to name. If name is unknown,
209  * 0 is returned and 'known' is set to FALSE. On success, 'known'
210  * is set to TRUE. */
211 guint32 get_ipxnet_addr(const gchar *name, gboolean *known);
212
213 /* adds a hostname/IPv4 in the hash table */
214 WS_DLL_PUBLIC void add_ipv4_name(const guint addr, const gchar *name);
215
216 /* adds a hostname/IPv6 in the hash table */
217 WS_DLL_PUBLIC void add_ipv6_name(const struct e_in6_addr *addr, const gchar *name);
218
219 /** Add an additional "hosts" file for IPv4 and IPv6 name resolution.
220  *
221  * The file can be added before host_name_lookup_init() is called and
222  * will be re-read each time host_name_lookup_init() is called.
223  *
224  * @param hostspath Absolute path to the hosts file.
225  *
226  * @return TRUE if the hosts file can be read.
227  */
228 WS_DLL_PUBLIC gboolean add_hosts_file (const char *hosts_file);
229
230 /* adds a hostname in the hash table */
231 WS_DLL_PUBLIC gboolean add_ip_name_from_string (const char *addr, const char *name);
232
233 /** Get a list of host name to address mappings we know about.
234  *
235  * Each list element is an addrinfo struct with the following fields defined:
236  *   - ai_family: 0, AF_INET or AF_INET6
237  *   - ai_addrlen: Length of ai_addr
238  *   - ai_canonname: Host name or NULL
239  *   - ai_addr: Pointer to a struct sockaddr or NULL (see below)
240  *   - ai_next: Next element or NULL
241  * All other fields are zero-filled.
242  *
243  * If ai_family is 0, this is a dummy entry which should only appear at the beginning of the list.
244  *
245  * If ai_family is AF_INET, ai_addr points to a struct sockaddr_in with the following fields defined:
246  *   - sin_family: AF_INET
247  *   - sin_addr: Host IPv4 address
248  * All other fields are zero-filled.
249  *
250  * If ai_family is AF_INET6, ai_addr points to a struct sockaddr_in6 with the following fields defined:
251  *   - sin6_family: AF_INET6
252  *   - sin6_addr: Host IPv6 address
253  * All other fields are zero-filled.
254  *
255  * The list and its elements MUST NOT be modified or freed.
256  *
257  * @return The first element in our list of known addresses. May be NULL.
258  */
259 WS_DLL_PUBLIC struct addrinfo *get_addrinfo_list(void);
260
261 /* add ethernet address / name corresponding to IP address  */
262 extern void add_ether_byip(const guint ip, const guint8 *eth);
263
264 /** Translates a string representing a hostname or dotted-decimal IPv4 address
265  *  into a numeric IPv4 address value in network byte order. If compiled with
266  *  c-ares, the request will wait a maximum of 250ms for the request to finish.
267  *  Otherwise the wait time will be system-dependent, ususally much longer.
268  *  Immediately returns FALSE for hostnames if network name resolution is
269  *  disabled.
270  *
271  * @param[in] host The hostname.
272  * @param[out] addrp The numeric IPv4 address in network byte order.
273  * @return TRUE on success, FALSE on failure, timeout.
274  */
275 WS_DLL_PUBLIC
276 gboolean get_host_ipaddr(const char *host, guint32 *addrp);
277
278 /** Translates a string representing a hostname or colon-hex IPv6 address
279  *  into a numeric IPv6 address value in network byte order. If compiled with
280  *  c-ares, the request will wait a maximum of 250ms for the request to finish.
281  *  Otherwise the wait time will be system-dependent, usually much longer.
282  *  Immediately returns FALSE for hostnames if network name resolution is
283  *  disabled.
284  *
285  * @param[in] host The hostname.
286  * @param[out] addrp The numeric IPv6 address in network byte order.
287  * @return TRUE on success, FALSE on failure or timeout.
288  */
289 WS_DLL_PUBLIC
290 gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp);
291
292 /*
293  * Find out whether a hostname resolves to an ip or ipv6 address
294  * Return "ip6" if it is IPv6, "ip" otherwise (including the case
295  * that we don't know)
296  */
297 WS_DLL_PUBLIC
298 const char* host_ip_af(const char *host);
299
300 #ifdef __cplusplus
301 }
302 #endif /* __cplusplus */
303
304 #endif /* __RESOLV_H__ */