2 * Definitions for network object lookup
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.
37 #include <epan/address.h>
38 #include <epan/tvbuff.h>
39 #include "ws_symbol_export.h"
43 #endif /* __cplusplus */
46 #define MAXNAMELEN 64 /* max name length (hostname and port name) */
49 typedef struct _e_addr_resolve {
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;
59 typedef struct hashether {
60 guint status; /* (See above) */
63 char resolved_name[MAXNAMELEN];
66 typedef struct serv_port {
74 * Flag controlling what names to resolve.
76 WS_DLL_PUBLIC e_addr_resolve gbl_resolv_flags;
78 /* global variables */
80 extern gchar *g_ethers_path;
81 extern gchar *g_ipxnets_path;
82 extern gchar *g_pethers_path;
83 extern gchar *g_pipxnets_path;
85 /* Functions in addr_resolv.c */
88 * get_udp_port() returns the port name corresponding to that UDP port,
89 * or the port number as a string if not found.
91 WS_DLL_PUBLIC gchar *get_udp_port(guint port);
94 * get_tcp_port() returns the port name corresponding to that TCP port,
95 * or the port number as a string if not found.
97 WS_DLL_PUBLIC gchar *get_tcp_port(guint port);
100 * get_dccp_port() returns the port name corresponding to that DCCP port,
101 * or the port number as a string if not found.
103 extern gchar *get_dccp_port(guint port);
106 * get_sctp_port() returns the port name corresponding to that SCTP port,
107 * or the port number as a string if not found.
109 WS_DLL_PUBLIC gchar *get_sctp_port(guint port);
111 /* get_addr_name takes as input an "address", as defined in address.h */
112 /* it returns a string that contains: */
113 /* - if the address is of a type that can be translated into a name, and the user */
114 /* has activated name resolution, the translated name */
115 /* - if the address is of type AT_NONE, a pointer to the string "NONE" */
116 /* - if the address is of any other type, the result of ep_address_to_str on the argument, */
117 /* which should be a string representation for the answer -e.g. "10.10.10.10" for IPv4 */
118 /* address 10.10.10.10 */
121 const gchar *get_addr_name(const address *addr);
122 const gchar *se_get_addr_name(const address *addr);
124 /* get_addr_name_buf solves an address in the same way as get_addr_name above */
125 /* The difference is that get_addr_name_buf takes as input a buffer, into which it puts */
126 /* the result which is always NUL ('\0') terminated. The buffer should be large enough to */
127 /* contain size characters including the terminator */
129 void get_addr_name_buf(const address *addr, gchar *buf, gsize size);
133 * Asynchronous host name lookup initialization, processing, and cleanup
136 /* Setup name resolution preferences */
138 extern void addr_resolve_pref_init(struct pref_module *nameres);
140 /** If we're using c-ares or ADNS, process outstanding host name lookups.
141 * This is called from a GLIB timeout in Wireshark and before processing
142 * each packet in TShark.
144 * @return True if any new objects have been resolved since the previous
145 * call. This can be used to trigger a display update, e.g. in Wireshark.
147 WS_DLL_PUBLIC gboolean host_name_lookup_process(void);
149 /* get_hostname returns the host name or "%d.%d.%d.%d" if not found */
150 WS_DLL_PUBLIC const gchar *get_hostname(const guint addr);
152 /* get_hostname6 returns the host name, or numeric addr if not found */
154 WS_DLL_PUBLIC const gchar* get_hostname6(const struct e_in6_addr *ad);
156 /* get_ether_name returns the logical name if found in ethers files else
157 "<vendor>_%02x:%02x:%02x" if the vendor code is known else
158 "%02x:%02x:%02x:%02x:%02x:%02x" */
159 WS_DLL_PUBLIC gchar *get_ether_name(const guint8 *addr);
161 /* get_ether_name returns the logical name if found in ethers files else NULL */
162 gchar *get_ether_name_if_known(const guint8 *addr);
165 * Given a sequence of 3 octets containing an OID, get_manuf_name()
166 * returns the vendor name, or "%02x:%02x:%02x" if not known.
168 extern const gchar *get_manuf_name(const guint8 *addr);
171 * Given a sequence of 3 octets containing an OID, get_manuf_name_if_known()
172 * returns the vendor name, or NULL if not known.
174 WS_DLL_PUBLIC const gchar *get_manuf_name_if_known(const guint8 *addr);
177 * Given an integer containing a 24-bit OID, uint_get_manuf_name()
178 * returns the vendor name, or "%02x:%02x:%02x" if not known.
180 extern const gchar *uint_get_manuf_name(const guint oid);
183 * Given an integer containing a 24-bit OID, uint_get_manuf_name_if_known()
184 * returns the vendor name, or NULL if not known.
186 extern const gchar *uint_get_manuf_name_if_known(const guint oid);
189 * Given a tvbuff and an offset in that tvbuff for a 3-octet OID,
190 * tvb_get_manuf_name() returns the vendor name, or "%02x:%02x:%02x"
193 WS_DLL_PUBLIC const gchar *tvb_get_manuf_name(tvbuff_t *tvb, gint offset);
196 * Given a tvbuff and an offset in that tvbuff for a 3-octet OID,
197 * tvb_get_manuf_name_if_known() returns the vendor name, or NULL
200 WS_DLL_PUBLIC const gchar *tvb_get_manuf_name_if_known(tvbuff_t *tvb, gint offset);
202 /* get_eui64_name returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the vendor code is known
203 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" */
204 extern const gchar *get_eui64_name(const guint64 addr);
206 /* get_eui64_name_if_known returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the vendor code is known else NULL */
207 extern const gchar *get_eui64_name_if_known(const guint64 addr);
210 /* get_ipxnet_name returns the logical name if found in an ipxnets file,
211 * or a string formatted with "%X" if not */
212 extern const gchar *get_ipxnet_name(const guint32 addr);
214 /* returns the ethernet address corresponding to name or NULL if not known */
215 extern guint8 *get_ether_addr(const gchar *name);
217 /* returns the ipx network corresponding to name. If name is unknown,
218 * 0 is returned and 'known' is set to FALSE. On success, 'known'
220 guint32 get_ipxnet_addr(const gchar *name, gboolean *known);
222 /* adds a hostname/IPv4 in the hash table */
223 WS_DLL_PUBLIC void add_ipv4_name(const guint addr, const gchar *name);
225 /* adds a hostname/IPv6 in the hash table */
226 WS_DLL_PUBLIC void add_ipv6_name(const struct e_in6_addr *addr, const gchar *name);
228 /** Add an additional "hosts" file for IPv4 and IPv6 name resolution.
230 * The file can be added before host_name_lookup_init() is called and
231 * will be re-read each time host_name_lookup_init() is called.
233 * @param hosts_file Absolute path to the hosts file.
235 * @return TRUE if the hosts file can be read.
237 WS_DLL_PUBLIC gboolean add_hosts_file (const char *hosts_file);
239 /* adds a hostname in the hash table */
240 WS_DLL_PUBLIC gboolean add_ip_name_from_string (const char *addr, const char *name);
242 /** Get a list of host name to address mappings we know about.
244 * Each list element is an addrinfo struct with the following fields defined:
245 * - ai_family: 0, AF_INET or AF_INET6
246 * - ai_addrlen: Length of ai_addr
247 * - ai_canonname: Host name or NULL
248 * - ai_addr: Pointer to a struct sockaddr or NULL (see below)
249 * - ai_next: Next element or NULL
250 * All other fields are zero-filled.
252 * If ai_family is 0, this is a dummy entry which should only appear at the beginning of the list.
254 * If ai_family is AF_INET, ai_addr points to a struct sockaddr_in with the following fields defined:
255 * - sin_family: AF_INET
256 * - sin_addr: Host IPv4 address
257 * All other fields are zero-filled.
259 * If ai_family is AF_INET6, ai_addr points to a struct sockaddr_in6 with the following fields defined:
260 * - sin6_family: AF_INET6
261 * - sin6_addr: Host IPv6 address
262 * All other fields are zero-filled.
264 * The list and its elements MUST NOT be modified or freed.
266 * @return The first element in our list of known addresses. May be NULL.
268 WS_DLL_PUBLIC struct addrinfo *get_addrinfo_list(void);
270 /* add ethernet address / name corresponding to IP address */
271 extern void add_ether_byip(const guint ip, const guint8 *eth);
273 /** Translates a string representing a hostname or dotted-decimal IPv4 address
274 * into a numeric IPv4 address value in network byte order. If compiled with
275 * c-ares, the request will wait a maximum of 250ms for the request to finish.
276 * Otherwise the wait time will be system-dependent, ususally much longer.
277 * Immediately returns FALSE for hostnames if network name resolution is
280 * @param[in] host The hostname.
281 * @param[out] addrp The numeric IPv4 address in network byte order.
282 * @return TRUE on success, FALSE on failure, timeout.
285 gboolean get_host_ipaddr(const char *host, guint32 *addrp);
287 /** Translates a string representing a hostname or colon-hex IPv6 address
288 * into a numeric IPv6 address value in network byte order. If compiled with
289 * c-ares, the request will wait a maximum of 250ms for the request to finish.
290 * Otherwise the wait time will be system-dependent, usually much longer.
291 * Immediately returns FALSE for hostnames if network name resolution is
294 * @param[in] host The hostname.
295 * @param[out] addrp The numeric IPv6 address in network byte order.
296 * @return TRUE on success, FALSE on failure or timeout.
299 gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp);
302 * Find out whether a hostname resolves to an ip or ipv6 address
303 * Return "ip6" if it is IPv6, "ip" otherwise (including the case
304 * that we don't know)
307 const char* host_ip_af(const char *host);
310 GHashTable *get_manuf_hashtable(void);
313 GHashTable *get_wka_hashtable(void);
316 GHashTable *get_eth_hashtable(void);
319 GHashTable *get_serv_port_hashtable(void);
322 * private functions (should only be called by epan directly)
326 void name_resolver_init(void);
328 /* (Re)Initialize hostname resolution subsystem */
330 void host_name_lookup_init(void);
332 /* Clean up only hostname resolutions (so they don't "leak" from one
336 void host_name_lookup_cleanup(void);
339 void addr_resolv_init(void);
342 void addr_resolv_cleanup(void);
346 #endif /* __cplusplus */
348 #endif /* __RESOLV_H__ */