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 * Flag controlling what names to resolve.
61 WS_DLL_PUBLIC e_addr_resolve gbl_resolv_flags;
63 /* global variables */
65 extern gchar *g_ethers_path;
66 extern gchar *g_ipxnets_path;
67 extern gchar *g_pethers_path;
68 extern gchar *g_pipxnets_path;
70 /* Functions in addr_resolv.c */
73 * get_udp_port() returns the port name corresponding to that UDP port,
74 * or the port number as a string if not found.
76 WS_DLL_PUBLIC gchar *get_udp_port(guint port);
79 * get_tcp_port() returns the port name corresponding to that TCP port,
80 * or the port number as a string if not found.
82 WS_DLL_PUBLIC gchar *get_tcp_port(guint port);
85 * get_dccp_port() returns the port name corresponding to that DCCP port,
86 * or the port number as a string if not found.
88 extern gchar *get_dccp_port(guint port);
91 * get_sctp_port() returns the port name corresponding to that SCTP port,
92 * or the port number as a string if not found.
94 WS_DLL_PUBLIC gchar *get_sctp_port(guint port);
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 */
106 const gchar *get_addr_name(const address *addr);
107 const gchar *se_get_addr_name(const address *addr);
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 */
114 void get_addr_name_buf(const address *addr, gchar *buf, gsize size);
118 * Asynchronous host name lookup initialization, processing, and cleanup
121 /* Setup name resolution preferences */
123 extern void addr_resolve_pref_init(struct pref_module *nameres);
125 /* host_name_lookup_init fires up an ADNS socket if we're using ADNS */
126 extern void host_name_lookup_init(void);
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.
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.
135 WS_DLL_PUBLIC gboolean host_name_lookup_process(void);
137 /* host_name_lookup_cleanup cleans up an ADNS socket if we're using ADNS */
138 extern void host_name_lookup_cleanup(void);
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);
143 /* get_hostname6 returns the host name, or numeric addr if not found */
145 WS_DLL_PUBLIC const gchar* get_hostname6(const struct e_in6_addr *ad);
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);
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);
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.
159 extern const gchar *get_manuf_name(const guint8 *addr);
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.
165 WS_DLL_PUBLIC const gchar *get_manuf_name_if_known(const guint8 *addr);
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.
171 extern const gchar *uint_get_manuf_name(const guint oid);
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.
177 extern const gchar *uint_get_manuf_name_if_known(const guint oid);
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"
184 WS_DLL_PUBLIC const gchar *tvb_get_manuf_name(tvbuff_t *tvb, gint offset);
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
191 WS_DLL_PUBLIC const gchar *tvb_get_manuf_name_if_known(tvbuff_t *tvb, gint offset);
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);
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);
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);
205 /* returns the ethernet address corresponding to name or NULL if not known */
206 extern guint8 *get_ether_addr(const gchar *name);
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'
211 guint32 get_ipxnet_addr(const gchar *name, gboolean *known);
213 /* adds a hostname/IPv4 in the hash table */
214 WS_DLL_PUBLIC void add_ipv4_name(const guint addr, const gchar *name);
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);
219 /** Add an additional "hosts" file for IPv4 and IPv6 name resolution.
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.
224 * @param hostspath Absolute path to the hosts file.
226 * @return TRUE if the hosts file can be read.
228 WS_DLL_PUBLIC gboolean add_hosts_file (const char *hosts_file);
230 /* adds a hostname in the hash table */
231 WS_DLL_PUBLIC gboolean add_ip_name_from_string (const char *addr, const char *name);
233 /** Get a list of host name to address mappings we know about.
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.
243 * If ai_family is 0, this is a dummy entry which should only appear at the beginning of the list.
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.
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.
255 * The list and its elements MUST NOT be modified or freed.
257 * @return The first element in our list of known addresses. May be NULL.
259 WS_DLL_PUBLIC struct addrinfo *get_addrinfo_list(void);
261 /* add ethernet address / name corresponding to IP address */
262 extern void add_ether_byip(const guint ip, const guint8 *eth);
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
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.
276 gboolean get_host_ipaddr(const char *host, guint32 *addrp);
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
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.
290 gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp);
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)
298 const char* host_ip_af(const char *host);
302 #endif /* __cplusplus */
304 #endif /* __RESOLV_H__ */