FIXUP: WIP: verification_trailer
[wireshark-wip.git] / epan / addr_resolv.h
blobe4c6a6fe724c6cd0eaf29885c71cbabd0a1dffc9
1 /* addr_resolv.h
2 * Definitions for network object lookup
4 * $Id$
6 * Laurent Deniel <laurent.deniel@free.fr>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
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.
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.
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.
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.
34 #ifndef __RESOLV_H__
35 #define __RESOLV_H__
37 #include <epan/address.h>
38 #include <epan/tvbuff.h>
39 #include <epan/ipv6-utils.h>
40 #include <epan/to_str.h>
41 #include <wiretap/wtap.h>
42 #include "ws_symbol_export.h"
44 #ifdef __cplusplus
45 extern "C" {
46 #endif /* __cplusplus */
48 #ifndef MAXNAMELEN
49 #define MAXNAMELEN 64 /* max name length (hostname and port name) */
50 #endif
52 typedef struct _e_addr_resolve {
53 gboolean mac_name;
54 gboolean network_name;
55 gboolean transport_name;
56 gboolean concurrent_dns;
57 gboolean use_external_net_name_resolver;
58 gboolean load_hosts_file_from_profile_only;
59 } e_addr_resolve;
62 typedef struct hashether {
63 guint status; /* (See above) */
64 guint8 addr[6];
65 char hexaddr[6*3];
66 char resolved_name[MAXNAMELEN];
67 } hashether_t;
69 typedef struct serv_port {
70 gchar *udp_name;
71 gchar *tcp_name;
72 gchar *sctp_name;
73 gchar *dccp_name;
74 } serv_port_t;
79 #define DUMMY_ADDRESS_ENTRY 1<<0
80 #define TRIED_RESOLVE_ADDRESS 1<<1
81 #define RESOLVED_ADDRESS_USED 1<<2
83 #define DUMMY_AND_RESOLVE_FLGS 3
84 #define USED_AND_RESOLVED_MASK (1+4)
85 typedef struct hashipv4 {
86 guint addr;
87 guint8 flags; /* B0 dummy_entry, B1 resolve, B2 If the address is used in the trace */
88 gchar ip[16];
89 gchar name[MAXNAMELEN];
90 } hashipv4_t;
93 typedef struct hashipv6 {
94 struct e_in6_addr addr;
95 guint8 flags; /* B0 dummy_entry, B1 resolve, B2 If the address is used in the trace */
96 gchar ip6[MAX_IP6_STR_LEN]; /* XX */
97 gchar name[MAXNAMELEN];
98 } hashipv6_t;
100 * Flag controlling what names to resolve.
102 WS_DLL_PUBLIC e_addr_resolve gbl_resolv_flags;
104 /* global variables */
106 extern gchar *g_ethers_path;
107 extern gchar *g_ipxnets_path;
108 extern gchar *g_pethers_path;
109 extern gchar *g_pipxnets_path;
111 /* Functions in addr_resolv.c */
114 * get_udp_port() returns the port name corresponding to that UDP port,
115 * or the port number as a string if not found.
117 WS_DLL_PUBLIC gchar *get_udp_port(guint port);
120 * get_tcp_port() returns the port name corresponding to that TCP port,
121 * or the port number as a string if not found.
123 WS_DLL_PUBLIC gchar *get_tcp_port(guint port);
126 * get_dccp_port() returns the port name corresponding to that DCCP port,
127 * or the port number as a string if not found.
129 extern gchar *get_dccp_port(guint port);
132 * get_sctp_port() returns the port name corresponding to that SCTP port,
133 * or the port number as a string if not found.
135 WS_DLL_PUBLIC gchar *get_sctp_port(guint port);
137 /* get_addr_name takes as input an "address", as defined in address.h */
138 /* it returns a string that contains: */
139 /* - if the address is of a type that can be translated into a name, and the user */
140 /* has activated name resolution, the translated name */
141 /* - if the address is of type AT_NONE, a pointer to the string "NONE" */
142 /* - if the address is of any other type, the result of ep_address_to_str on the argument, */
143 /* which should be a string representation for the answer -e.g. "10.10.10.10" for IPv4 */
144 /* address 10.10.10.10 */
146 WS_DLL_PUBLIC
147 const gchar *get_addr_name(const address *addr);
148 const gchar *se_get_addr_name(const address *addr);
150 /* get_addr_name_buf solves an address in the same way as get_addr_name above */
151 /* The difference is that get_addr_name_buf takes as input a buffer, into which it puts */
152 /* the result which is always NUL ('\0') terminated. The buffer should be large enough to */
153 /* contain size characters including the terminator */
155 void get_addr_name_buf(const address *addr, gchar *buf, gsize size);
159 * Asynchronous host name lookup initialization, processing, and cleanup
162 /* Setup name resolution preferences */
163 struct pref_module;
164 extern void addr_resolve_pref_init(struct pref_module *nameres);
166 /** If we're using c-ares or ADNS, process outstanding host name lookups.
167 * This is called from a GLIB timeout in Wireshark and before processing
168 * each packet in TShark.
170 * @return True if any new objects have been resolved since the previous
171 * call. This can be used to trigger a display update, e.g. in Wireshark.
173 WS_DLL_PUBLIC gboolean host_name_lookup_process(void);
175 /* get_hostname returns the host name or "%d.%d.%d.%d" if not found */
176 WS_DLL_PUBLIC const gchar *get_hostname(const guint addr);
178 /* get_hostname6 returns the host name, or numeric addr if not found */
179 struct e_in6_addr;
180 WS_DLL_PUBLIC const gchar* get_hostname6(const struct e_in6_addr *ad);
182 /* get_ether_name returns the logical name if found in ethers files else
183 "<vendor>_%02x:%02x:%02x" if the vendor code is known else
184 "%02x:%02x:%02x:%02x:%02x:%02x" */
185 WS_DLL_PUBLIC gchar *get_ether_name(const guint8 *addr);
187 /* get_ether_name returns the logical name if found in ethers files else NULL */
188 gchar *get_ether_name_if_known(const guint8 *addr);
191 * Given a sequence of 3 octets containing an OID, get_manuf_name()
192 * returns the vendor name, or "%02x:%02x:%02x" if not known.
194 extern const gchar *get_manuf_name(const guint8 *addr);
197 * Given a sequence of 3 octets containing an OID, get_manuf_name_if_known()
198 * returns the vendor name, or NULL if not known.
200 WS_DLL_PUBLIC const gchar *get_manuf_name_if_known(const guint8 *addr);
203 * Given an integer containing a 24-bit OID, uint_get_manuf_name()
204 * returns the vendor name, or "%02x:%02x:%02x" if not known.
206 extern const gchar *uint_get_manuf_name(const guint oid);
209 * Given an integer containing a 24-bit OID, uint_get_manuf_name_if_known()
210 * returns the vendor name, or NULL if not known.
212 extern const gchar *uint_get_manuf_name_if_known(const guint oid);
215 * Given a tvbuff and an offset in that tvbuff for a 3-octet OID,
216 * tvb_get_manuf_name() returns the vendor name, or "%02x:%02x:%02x"
217 * if not known.
219 WS_DLL_PUBLIC const gchar *tvb_get_manuf_name(tvbuff_t *tvb, gint offset);
222 * Given a tvbuff and an offset in that tvbuff for a 3-octet OID,
223 * tvb_get_manuf_name_if_known() returns the vendor name, or NULL
224 * if not known.
226 WS_DLL_PUBLIC const gchar *tvb_get_manuf_name_if_known(tvbuff_t *tvb, gint offset);
228 /* get_eui64_name returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the vendor code is known
229 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" */
230 extern const gchar *get_eui64_name(const guint64 addr);
232 /* get_eui64_name_if_known returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the vendor code is known else NULL */
233 extern const gchar *get_eui64_name_if_known(const guint64 addr);
236 /* get_ipxnet_name returns the logical name if found in an ipxnets file,
237 * or a string formatted with "%X" if not */
238 extern const gchar *get_ipxnet_name(const guint32 addr);
240 /* returns the ethernet address corresponding to name or NULL if not known */
241 extern guint8 *get_ether_addr(const gchar *name);
243 /* returns the ipx network corresponding to name. If name is unknown,
244 * 0 is returned and 'known' is set to FALSE. On success, 'known'
245 * is set to TRUE. */
246 guint32 get_ipxnet_addr(const gchar *name, gboolean *known);
248 /* adds a hostname/IPv4 in the hash table */
249 WS_DLL_PUBLIC void add_ipv4_name(const guint addr, const gchar *name);
251 /* adds a hostname/IPv6 in the hash table */
252 WS_DLL_PUBLIC void add_ipv6_name(const struct e_in6_addr *addr, const gchar *name);
254 /** Add an additional "hosts" file for IPv4 and IPv6 name resolution.
256 * The file can be added before host_name_lookup_init() is called and
257 * will be re-read each time host_name_lookup_init() is called.
259 * @param hosts_file Absolute path to the hosts file.
261 * @return TRUE if the hosts file can be read.
263 WS_DLL_PUBLIC gboolean add_hosts_file (const char *hosts_file);
265 /* adds a hostname in the hash table */
266 WS_DLL_PUBLIC gboolean add_ip_name_from_string (const char *addr, const char *name);
269 /** Get lists of host name to address mappings we know about.
271 * The struct contains two g_lists one with hashipv4_t entries and one with hashipv6_t entries.
273 * @return a struct with lists of known addresses(IPv4 and IPv6). May be NULL.
275 WS_DLL_PUBLIC addrinfo_lists_t *get_addrinfo_list(void);
277 /* add ethernet address / name corresponding to IP address */
278 extern void add_ether_byip(const guint ip, const guint8 *eth);
280 /** Translates a string representing a hostname or dotted-decimal IPv4 address
281 * into a numeric IPv4 address value in network byte order. If compiled with
282 * c-ares, the request will wait a maximum of 250ms for the request to finish.
283 * Otherwise the wait time will be system-dependent, ususally much longer.
284 * Immediately returns FALSE for hostnames if network name resolution is
285 * disabled.
287 * @param[in] host The hostname.
288 * @param[out] addrp The numeric IPv4 address in network byte order.
289 * @return TRUE on success, FALSE on failure, timeout.
291 WS_DLL_PUBLIC
292 gboolean get_host_ipaddr(const char *host, guint32 *addrp);
294 /** Translates a string representing a hostname or colon-hex IPv6 address
295 * into a numeric IPv6 address value in network byte order. If compiled with
296 * c-ares, the request will wait a maximum of 250ms for the request to finish.
297 * Otherwise the wait time will be system-dependent, usually much longer.
298 * Immediately returns FALSE for hostnames if network name resolution is
299 * disabled.
301 * @param[in] host The hostname.
302 * @param[out] addrp The numeric IPv6 address in network byte order.
303 * @return TRUE on success, FALSE on failure or timeout.
305 WS_DLL_PUBLIC
306 gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp);
309 * Find out whether a hostname resolves to an ip or ipv6 address
310 * Return "ip6" if it is IPv6, "ip" otherwise (including the case
311 * that we don't know)
313 WS_DLL_PUBLIC
314 const char* host_ip_af(const char *host);
316 WS_DLL_PUBLIC
317 GHashTable *get_manuf_hashtable(void);
319 WS_DLL_PUBLIC
320 GHashTable *get_wka_hashtable(void);
322 WS_DLL_PUBLIC
323 GHashTable *get_eth_hashtable(void);
325 WS_DLL_PUBLIC
326 GHashTable *get_serv_port_hashtable(void);
328 WS_DLL_PUBLIC
329 GHashTable *get_ipxnet_table(void);
331 WS_DLL_PUBLIC
332 GHashTable *get_ipv4_hash_table(void);
334 WS_DLL_PUBLIC
335 GHashTable *get_ipv6_hash_table(void);
338 * private functions (should only be called by epan directly)
341 WS_DLL_LOCAL
342 void name_resolver_init(void);
344 /* (Re)Initialize hostname resolution subsystem */
345 WS_DLL_LOCAL
346 void host_name_lookup_init(void);
348 /* Clean up only hostname resolutions (so they don't "leak" from one
349 * file to the next).
351 WS_DLL_LOCAL
352 void host_name_lookup_cleanup(void);
354 WS_DLL_LOCAL
355 void addr_resolv_init(void);
357 WS_DLL_LOCAL
358 void addr_resolv_cleanup(void);
360 WS_DLL_PUBLIC
361 void manually_resolve_cleanup(void);
363 #ifdef __cplusplus
365 #endif /* __cplusplus */
367 #endif /* __RESOLV_H__ */