Wireshark 4.5.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
addr_resolv.h
Go to the documentation of this file.
1
12/* The buffers returned by these functions are all allocated with a
13 * packet lifetime and does not have to be freed.
14 * However, take into account that when the packet dissection
15 * completes, these buffers will be automatically reclaimed/freed.
16 * If you need the buffer to remain for a longer scope than packet lifetime
17 * you must copy the content to an wmem_file_scope() buffer.
18 */
19
20#ifndef __RESOLV_H__
21#define __RESOLV_H__
22
23#include <epan/address.h>
24#include <epan/tvbuff.h>
25#include <wsutil/inet_cidr.h>
26#include <epan/to_str.h>
27#include <wiretap/wtap.h>
28#include "ws_symbol_export.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif /* __cplusplus */
33
34#ifndef MAXNAMELEN
35#define MAXNAMELEN 64 /* max name length (most names: DNS labels, services, eth) */
36#endif
37
38#ifndef MAXVLANNAMELEN
39#define MAXVLANNAMELEN 128 /* max vlan name length */
40#endif
41
42#ifndef MAXDNSNAMELEN
43#define MAXDNSNAMELEN 256 /* max total length of a domain name in the DNS */
44#endif
45
46#define BASE_ENTERPRISES BASE_CUSTOM
47#define STRINGS_ENTERPRISES CF_FUNC(enterprises_base_custom)
48
63
64#define ADDR_RESOLV_MACADDR(at) \
65 (((at)->type == AT_ETHER) || ((at)->type == AT_EUI64))
66
67#define ADDR_RESOLV_NETADDR(at) \
68 (((at)->type == AT_IPv4) || ((at)->type == AT_IPv6) || ((at)->type == AT_IPX))
69
70struct hashether;
71typedef struct hashether hashether_t;
72
73struct hasheui64;
74typedef struct hasheui64 hasheui64_t;
75
76struct hashwka;
77typedef struct hashwka hashwka_t;
78
79struct hashmanuf;
80typedef struct hashmanuf hashmanuf_t;
81
82typedef struct serv_port {
83 const char *udp_name;
84 const char *tcp_name;
85 const char *sctp_name;
86 const char *dccp_name;
87 const char *numeric;
89
90/* Used for manually edited DNS resolved names */
91typedef struct _resolved_name {
92 char name[MAXDNSNAMELEN];
94
95/*
96 * Flags for various resolved name hash table entries.
97 */
98#define TRIED_RESOLVE_ADDRESS (1U<<0) /* name resolution is being/has been tried */
99#define NAME_RESOLVED (1U<<1) /* the name field contains a host name, not a printable address */
100#define RESOLVED_ADDRESS_USED (1U<<2) /* a get_hostname* call returned the host name */
101#define STATIC_HOSTNAME (1U<<3) /* do not update entries from hosts file with DNS responses */
102#define NAME_RESOLVED_PREFIX (1U<<4) /* name was generated from a prefix (e.g., OUI) instead of the entire address */
103
104#define TRIED_OR_RESOLVED_MASK (TRIED_RESOLVE_ADDRESS | NAME_RESOLVED)
105#define USED_AND_RESOLVED_MASK (NAME_RESOLVED | RESOLVED_ADDRESS_USED)
106
107/*
108 * Flag controlling what names to resolve.
109 */
110WS_DLL_PUBLIC e_addr_resolve gbl_resolv_flags;
111
112/* global variables */
113
114extern char *g_ethers_path;
115extern char *g_ipxnets_path;
116extern char *g_pethers_path;
117extern char *g_pipxnets_path;
118
119/* Functions in addr_resolv.c */
120
121/*
122 * returns an ipv4 object built from its address
123 */
124WS_DLL_PUBLIC hashipv4_t * new_ipv4(const unsigned addr);
125
126/*
127 * returns a 'dummy ip4' object built from an address
128 */
129WS_DLL_PUBLIC bool fill_dummy_ip4(const unsigned addr, hashipv4_t* volatile tp);
130
131/*
132 * udp_port_to_display() returns the port name corresponding to that UDP port,
133 * or the port number as a string if not found.
134 */
135WS_DLL_PUBLIC char *udp_port_to_display(wmem_allocator_t *allocator, unsigned port);
136
137/*
138 * tcp_port_to_display() returns the port name corresponding to that TCP port,
139 * or the port number as a string if not found.
140 */
141WS_DLL_PUBLIC char *tcp_port_to_display(wmem_allocator_t *allocator, unsigned port);
142
143/*
144 * dccp_port_to_display() returns the port name corresponding to that DCCP port,
145 * or the port number as a string if not found.
146 */
147extern char *dccp_port_to_display(wmem_allocator_t *allocator, unsigned port);
148
149/*
150 * sctp_port_to_display() returns the port name corresponding to that SCTP port,
151 * or the port number as a string if not found.
152 */
153WS_DLL_PUBLIC char *sctp_port_to_display(wmem_allocator_t *allocator, unsigned port);
154
155/*
156 * serv_name_lookup() returns the well known service name string, or numeric
157 * representation if one doesn't exist.
158 */
159WS_DLL_PUBLIC const char *serv_name_lookup(port_type proto, unsigned port);
160
161/*
162 * enterprises_lookup() returns the private enterprise code string, or 'unknown_str'
163 * if one doesn't exist, or "<Unknown>" if that is NULL.
164 */
165WS_DLL_PUBLIC const char *enterprises_lookup(uint32_t value, const char *unknown_str);
166
167/*
168 * try_enterprises_lookup() returns the private enterprise code string, or NULL if not found.
169 */
170WS_DLL_PUBLIC const char *try_enterprises_lookup(uint32_t value);
171
172/*
173 * enterprises_base_custom() prints the "name (decimal)" string to 'buf'.
174 * (Used with BASE_CUSTOM field display).
175 */
176WS_DLL_PUBLIC void enterprises_base_custom(char *buf, uint32_t value);
177
178/*
179 * try_serv_name_lookup() returns the well known service name string, or NULL if
180 * one doesn't exist.
181 */
182WS_DLL_PUBLIC const char *try_serv_name_lookup(port_type proto, unsigned port);
183
184/*
185 * port_with_resolution_to_str() prints the "<resolved> (<numerical>)" port
186 * string.
187 */
188WS_DLL_PUBLIC char *port_with_resolution_to_str(wmem_allocator_t *scope,
189 port_type proto, unsigned port);
190
191/*
192 * port_with_resolution_to_str_buf() prints the "<resolved> (<numerical>)" port
193 * string to 'buf'. Return value is the same as snprintf().
194 */
195WS_DLL_PUBLIC int port_with_resolution_to_str_buf(char *buf, unsigned long buf_size,
196 port_type proto, unsigned port);
197
198/*
199 * Asynchronous host name lookup initialization, processing, and cleanup
200 */
201
202/* Setup name resolution preferences */
203struct pref_module;
204extern void addr_resolve_pref_init(struct pref_module *nameres);
205extern void addr_resolve_pref_apply(void);
206
207/*
208 * disable_name_resolution() sets all relevant gbl_resolv_flags to false.
209 */
210WS_DLL_PUBLIC void disable_name_resolution(void);
211
219WS_DLL_PUBLIC bool host_name_lookup_process(void);
220
221/* get_hostname returns the host name or "%d.%d.%d.%d" if not found.
222 * The string does not have to be freed; it will be freed when the
223 * address hashtables are emptied (e.g., when preferences change or
224 * redissection.) However, this increases persistent memory usage
225 * even when host name lookups are off.
226 *
227 * This might get deprecated in the future for get_hostname_wmem.
228 */
229WS_DLL_PUBLIC const char *get_hostname(const unsigned addr);
230
231/* get_hostname_wmem returns the host name or "%d.%d.%d.%d" if not found
232 * The returned string is allocated according to the wmem scope allocator. */
233WS_DLL_PUBLIC char *get_hostname_wmem(wmem_allocator_t *allocator, const unsigned addr);
234
235/* get_hostname6 returns the host name, or numeric addr if not found.
236 * The string does not have to be freed; it will be freed when the
237 * address hashtables are emptied (e.g., when preferences change or
238 * upon redissection.) However, this increases persistent memory usage
239 * even when host name lookups are off.
240 *
241 * This might get deprecated in the future for get_hostname6_wmem.
242 */
243WS_DLL_PUBLIC const char *get_hostname6(const ws_in6_addr *ad);
244
245/* get_hostname6 returns the host name, or numeric addr if not found.
246 * The returned string is allocated according to the wmem scope allocator. */
247WS_DLL_PUBLIC char *get_hostname6_wmem(wmem_allocator_t *allocator, const ws_in6_addr *ad);
248
249/* get_ether_name returns the logical name if found in ethers files else
250 "<vendor>_%02x:%02x:%02x" if the vendor code is known else
251 "%02x:%02x:%02x:%02x:%02x:%02x" */
252WS_DLL_PUBLIC const char *get_ether_name(const uint8_t *addr);
253
254/* get_hostname_ss7pc returns the logical name if found in ss7pcs file else
255 '\0' on the first call or the unresolved Point Code in the subsequent calls */
256const char *get_hostname_ss7pc(const uint8_t ni, const uint32_t pc);
257
258/* fill_unresolved_ss7pc initializes the unresolved Point Code Address string in the hashtable */
259void fill_unresolved_ss7pc(const char * pc_addr, const uint8_t ni, const uint32_t pc);
260
261
262/* Same as get_ether_name with tvb support */
263WS_DLL_PUBLIC const char *tvb_get_ether_name(tvbuff_t *tvb, int offset);
264
265/* get_ether_name_if_known returns the logical name if an exact match is
266 * found (in ethers files or from ARP) else NULL.
267 * @note: It returns NULL for addresses if only a prefix can be resolved
268 * into a manufacturer name.
269 */
270const char *get_ether_name_if_known(const uint8_t *addr);
271
272/*
273 * Given a sequence of 3 octets containing an OID, get_manuf_name()
274 * returns an abbreviated form of the vendor name, or "%02x:%02x:%02x"
275 * if not known. (The short form of the name is roughly similar in length
276 * to the hexstring, so that they may be used in similar places.)
277 * @note: This only looks up entries in the 24-bit OUI table (and the
278 * CID table), not the MA-M and MA-S tables. The hex byte string is
279 * returned for sequences registered to the IEEE Registration Authority
280 * for the purposes of being subdivided into MA-M and MA-S.
281 */
282extern const char *get_manuf_name(const uint8_t *addr, size_t size);
283
284/*
285 * Given a sequence of 3 or more octets containing an OUI,
286 * get_manuf_name_if_known() returns the vendor name, or NULL if not known.
287 * @note Unlike get_manuf_name() above, this returns the full vendor name.
288 * @note If size is 6 or larger, vendor names will be looked up in the MA-M
289 * and MA-S tables as well (but note that the length of the sequence is
290 * not returned.) If size is less than 6, only the 24 bit tables are searched,
291 * and NULL is returned for sequences registered to the IEEE Registration
292 * Authority for purposes of being subdivided into MA-M and MA-S.
293 */
294WS_DLL_PUBLIC const char *get_manuf_name_if_known(const uint8_t *addr, size_t size);
295
296/*
297 * Given an integer containing a 24-bit OUI (or CID),
298 * uint_get_manuf_name_if_known() returns the vendor name, or NULL if not known.
299 * @note NULL is returned for sequences registered to the IEEE Registration
300 * Authority for purposes of being subdivided into MA-M and MA-S.
301 */
302extern const char *uint_get_manuf_name_if_known(const uint32_t oid);
303
304/*
305 * Given a tvbuff and an offset in that tvbuff for a 3-octet OID,
306 * tvb_get_manuf_name() returns an abbreviated vendor name, or "%02x:%02x:%02x"
307 * if not known.
308 * @note: This only looks up entries in the 24-bit OUI table (and the
309 * CID table), not the MA-M and MA-S tables. The hex byte string is
310 * returned for sequences registered to the IEEE Registration Authority
311 * for the purposes of being subdivided into MA-M and MA-S.
312 */
313WS_DLL_PUBLIC const char *tvb_get_manuf_name(tvbuff_t *tvb, int offset);
314
315/*
316 * Given a tvbuff and an offset in that tvbuff for a 3-octet OID,
317 * tvb_get_manuf_name_if_known() returns the full vendor name, or NULL
318 * if not known.
319 * @note NULL is returned for sequences registered to the IEEE Registration
320 * Authority for purposes of being subdivided into MA-M and MA-S.
321 */
322WS_DLL_PUBLIC const char *tvb_get_manuf_name_if_known(tvbuff_t *tvb, int offset);
323
324/* get_eui64_name returns the logical name if found in ethers files else
325 * "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the vendor code is known
326 * (or as appropriate for MA-M and MA-S), and if not,
327 * "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
328*/
329extern const char *get_eui64_name(const uint8_t *addr);
330
331/* eui64_to_display returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the
332 * vendor code is known (or as appropriate for MA-M and MA-S), and if not,
333 * "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x". Gives the same results
334 * as address_to_display, but for when the EUI-64 address is a host endian
335 * uint64_t instead of bytes / an AT_EUI64 address.
336*/
337extern char *eui64_to_display(wmem_allocator_t *allocator, const uint64_t addr);
338
339/* get_ipxnet_name returns the logical name if found in an ipxnets file,
340 * or a string formatted with "%X" if not */
341extern char *get_ipxnet_name(wmem_allocator_t *allocator, const uint32_t addr);
342
343/* get_vlan_name returns the logical name if found in a vlans file,
344 * or the VLAN ID itself as a string if not found*/
345extern char *get_vlan_name(wmem_allocator_t *allocator, const uint16_t id);
346
347WS_DLL_PUBLIC unsigned get_hash_ether_status(hashether_t* ether);
348WS_DLL_PUBLIC bool get_hash_ether_used(hashether_t* ether);
349WS_DLL_PUBLIC char* get_hash_ether_hexaddr(hashether_t* ether);
350WS_DLL_PUBLIC char* get_hash_ether_resolved_name(hashether_t* ether);
351
352WS_DLL_PUBLIC bool get_hash_manuf_used(hashmanuf_t* manuf);
353WS_DLL_PUBLIC char* get_hash_manuf_resolved_name(hashmanuf_t* manuf);
354
355WS_DLL_PUBLIC bool get_hash_wka_used(hashwka_t* wka);
356WS_DLL_PUBLIC char* get_hash_wka_resolved_name(hashwka_t* wka);
357
358/* adds a hostname/IPv4 in the hash table */
359WS_DLL_PUBLIC void add_ipv4_name(const unsigned addr, const char *name, const bool static_entry);
360
361/* adds a hostname/IPv6 in the hash table */
362WS_DLL_PUBLIC void add_ipv6_name(const ws_in6_addr *addr, const char *name, const bool static_entry);
363
373WS_DLL_PUBLIC bool add_hosts_file (const char *hosts_file);
374
375/* adds a hostname in the hash table */
376WS_DLL_PUBLIC bool add_ip_name_from_string (const char *addr, const char *name);
377
378/* Get the user defined name, for a given address */
379WS_DLL_PUBLIC resolved_name_t* get_edited_resolved_name(const char* addr);
380
381
388WS_DLL_PUBLIC addrinfo_lists_t *get_addrinfo_list(void);
389
390/* add ethernet address / name corresponding to IP address */
391extern void add_ether_byip(const unsigned ip, const uint8_t *eth);
392
404WS_DLL_PUBLIC
405bool get_host_ipaddr(const char *host, uint32_t *addrp);
406
418WS_DLL_PUBLIC
419bool get_host_ipaddr6(const char *host, ws_in6_addr *addrp);
420
421WS_DLL_PUBLIC
422wmem_map_t *get_manuf_hashtable(void);
423
424WS_DLL_PUBLIC
425wmem_map_t *get_wka_hashtable(void);
426
427WS_DLL_PUBLIC
428wmem_map_t *get_eth_hashtable(void);
429
430WS_DLL_PUBLIC
431wmem_map_t *get_serv_port_hashtable(void);
432
433WS_DLL_PUBLIC
434wmem_map_t *get_ipxnet_hash_table(void);
435
436WS_DLL_PUBLIC
437wmem_map_t *get_vlan_hash_table(void);
438
439WS_DLL_PUBLIC
440wmem_map_t *get_ipv4_hash_table(void);
441
442WS_DLL_PUBLIC
443wmem_map_t *get_ipv6_hash_table(void);
444
445/*
446 * XXX - if we ever have per-session host name etc. information, we
447 * should probably have the "resolve synchronously or asynchronously"
448 * flag be per-session, set with an epan API.
449 */
450WS_DLL_PUBLIC
451void set_resolution_synchrony(bool synchronous);
452
453/*
454 * private functions (should only be called by epan directly)
455 */
456
457WS_DLL_LOCAL
458void name_resolver_init(void);
459
460/* Reinitialize hostname resolution subsystem */
461WS_DLL_LOCAL
462void host_name_lookup_reset(void);
463
464WS_DLL_LOCAL
465void addr_resolv_init(void);
466
467WS_DLL_LOCAL
468void addr_resolv_cleanup(void);
469
470WS_DLL_PUBLIC
471bool str_to_ip(const char *str, void *dst);
472
473WS_DLL_PUBLIC
474bool str_to_ip6(const char *str, void *dst);
475
476WS_DLL_LOCAL
477bool str_to_eth(const char *str, char *eth_bytes);
478
479WS_DLL_LOCAL
480unsigned ipv6_oat_hash(const void *key);
481
482WS_DLL_LOCAL
483gboolean ipv6_equal(const void *v1, const void *v2);
484
485#ifdef __cplusplus
486}
487#endif /* __cplusplus */
488
489#endif /* __RESOLV_H__ */
WS_DLL_PUBLIC bool host_name_lookup_process(void)
Definition addr_resolv.c:3510
WS_DLL_PUBLIC bool get_host_ipaddr6(const char *host, ws_in6_addr *addrp)
Definition addr_resolv.c:4177
WS_DLL_PUBLIC bool get_host_ipaddr(const char *host, uint32_t *addrp)
Definition addr_resolv.c:4112
WS_DLL_PUBLIC addrinfo_lists_t * get_addrinfo_list(void)
Definition addr_resolv.c:3032
WS_DLL_PUBLIC bool add_hosts_file(const char *hosts_file)
Definition addr_resolv.c:2908
struct _e_addr_resolve e_addr_resolve
Flags to control name resolution.
Flags to control name resolution.
Definition addr_resolv.h:52
bool dns_pkt_addr_resolution
Definition addr_resolv.h:56
bool maxmind_geoip
Definition addr_resolv.h:61
bool ss7pc_name
Definition addr_resolv.h:60
bool use_external_net_name_resolver
Definition addr_resolv.h:58
bool handshake_sni_addr_resolution
Definition addr_resolv.h:57
bool transport_name
Definition addr_resolv.h:55
bool mac_name
Definition addr_resolv.h:53
bool network_name
Definition addr_resolv.h:54
bool vlan_name
Definition addr_resolv.h:59
Definition addr_resolv.h:91
Definition wmem_allocator.h:27
Definition wmem_map.c:44
Definition wtap.h:1526
Definition inet_addr.h:21
Definition addr_resolv.c:162
Definition addr_resolv.c:169
Definition wtap.h:1508
Definition addr_resolv.c:181
Definition addr_resolv.c:176
Definition prefs-int.h:27
const char * name
Definition prefs-int.h:28
Definition addr_resolv.h:82
Definition tvbuff-int.h:35