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 (hostname and port name) */
36#endif
37
38#ifndef MAXVLANNAMELEN
39#define MAXVLANNAMELEN 128 /* max vlan name length */
40#endif
41
42#define BASE_ENTERPRISES BASE_CUSTOM
43#define STRINGS_ENTERPRISES CF_FUNC(enterprises_base_custom)
44
59
60#define ADDR_RESOLV_MACADDR(at) \
61 (((at)->type == AT_ETHER))
62
63#define ADDR_RESOLV_NETADDR(at) \
64 (((at)->type == AT_IPv4) || ((at)->type == AT_IPv6) || ((at)->type == AT_IPX))
65
66struct hashether;
67typedef struct hashether hashether_t;
68
69struct hashwka;
70typedef struct hashwka hashwka_t;
71
72struct hashmanuf;
73typedef struct hashmanuf hashmanuf_t;
74
75typedef struct serv_port {
76 const char *udp_name;
77 const char *tcp_name;
78 const char *sctp_name;
79 const char *dccp_name;
80 const char *numeric;
82
83typedef struct _resolved_name {
84 char name[MAXNAMELEN];
86
87/*
88 * Flags for various resolved name hash table entries.
89 */
90#define TRIED_RESOLVE_ADDRESS (1U<<0) /* name resolution is being/has been tried */
91#define NAME_RESOLVED (1U<<1) /* the name field contains a host name, not a printable address */
92#define RESOLVED_ADDRESS_USED (1U<<2) /* a get_hostname* call returned the host name */
93#define STATIC_HOSTNAME (1U<<3) /* do not update entries from hosts file with DNS responses */
94#define NAME_RESOLVED_PREFIX (1U<<4) /* name was generated from a prefix (e.g., OUI) instead of the entire address */
95
96#define TRIED_OR_RESOLVED_MASK (TRIED_RESOLVE_ADDRESS | NAME_RESOLVED)
97#define USED_AND_RESOLVED_MASK (NAME_RESOLVED | RESOLVED_ADDRESS_USED)
98
99/*
100 * Flag controlling what names to resolve.
101 */
102WS_DLL_PUBLIC e_addr_resolve gbl_resolv_flags;
103
104/* global variables */
105
106extern char *g_ethers_path;
107extern char *g_ipxnets_path;
108extern char *g_pethers_path;
109extern char *g_pipxnets_path;
110
111/* Functions in addr_resolv.c */
112
113/*
114 * returns an ipv4 object built from its address
115 */
116WS_DLL_PUBLIC hashipv4_t * new_ipv4(const unsigned addr);
117
118/*
119 * returns a 'dummy ip4' object built from an address
120 */
121WS_DLL_PUBLIC bool fill_dummy_ip4(const unsigned addr, hashipv4_t* volatile tp);
122
123/*
124 * udp_port_to_display() returns the port name corresponding to that UDP port,
125 * or the port number as a string if not found.
126 */
127WS_DLL_PUBLIC char *udp_port_to_display(wmem_allocator_t *allocator, unsigned port);
128
129/*
130 * tcp_port_to_display() returns the port name corresponding to that TCP port,
131 * or the port number as a string if not found.
132 */
133WS_DLL_PUBLIC char *tcp_port_to_display(wmem_allocator_t *allocator, unsigned port);
134
135/*
136 * dccp_port_to_display() returns the port name corresponding to that DCCP port,
137 * or the port number as a string if not found.
138 */
139extern char *dccp_port_to_display(wmem_allocator_t *allocator, unsigned port);
140
141/*
142 * sctp_port_to_display() returns the port name corresponding to that SCTP port,
143 * or the port number as a string if not found.
144 */
145WS_DLL_PUBLIC char *sctp_port_to_display(wmem_allocator_t *allocator, unsigned port);
146
147/*
148 * serv_name_lookup() returns the well known service name string, or numeric
149 * representation if one doesn't exist.
150 */
151WS_DLL_PUBLIC const char *serv_name_lookup(port_type proto, unsigned port);
152
153/*
154 * enterprises_lookup() returns the private enterprise code string, or 'unknown_str'
155 * if one doesn't exist, or "<Unknown>" if that is NULL.
156 */
157WS_DLL_PUBLIC const char *enterprises_lookup(uint32_t value, const char *unknown_str);
158
159/*
160 * try_enterprises_lookup() returns the private enterprise code string, or NULL if not found.
161 */
162WS_DLL_PUBLIC const char *try_enterprises_lookup(uint32_t value);
163
164/*
165 * enterprises_base_custom() prints the "name (decimal)" string to 'buf'.
166 * (Used with BASE_CUSTOM field display).
167 */
168WS_DLL_PUBLIC void enterprises_base_custom(char *buf, uint32_t value);
169
170/*
171 * try_serv_name_lookup() returns the well known service name string, or NULL if
172 * one doesn't exist.
173 */
174WS_DLL_PUBLIC const char *try_serv_name_lookup(port_type proto, unsigned port);
175
176/*
177 * port_with_resolution_to_str() prints the "<resolved> (<numerical>)" port
178 * string.
179 */
180WS_DLL_PUBLIC char *port_with_resolution_to_str(wmem_allocator_t *scope,
181 port_type proto, unsigned port);
182
183/*
184 * port_with_resolution_to_str_buf() prints the "<resolved> (<numerical>)" port
185 * string to 'buf'. Return value is the same as snprintf().
186 */
187WS_DLL_PUBLIC int port_with_resolution_to_str_buf(char *buf, unsigned long buf_size,
188 port_type proto, unsigned port);
189
190/*
191 * Asynchronous host name lookup initialization, processing, and cleanup
192 */
193
194/* Setup name resolution preferences */
195struct pref_module;
196extern void addr_resolve_pref_init(struct pref_module *nameres);
197extern void addr_resolve_pref_apply(void);
198
199/*
200 * disable_name_resolution() sets all relevant gbl_resolv_flags to false.
201 */
202WS_DLL_PUBLIC void disable_name_resolution(void);
203
211WS_DLL_PUBLIC bool host_name_lookup_process(void);
212
213/* get_hostname returns the host name or "%d.%d.%d.%d" if not found */
214WS_DLL_PUBLIC const char *get_hostname(const unsigned addr);
215
216/* get_hostname6 returns the host name, or numeric addr if not found */
217WS_DLL_PUBLIC const char *get_hostname6(const ws_in6_addr *ad);
218
219/* get_ether_name returns the logical name if found in ethers files else
220 "<vendor>_%02x:%02x:%02x" if the vendor code is known else
221 "%02x:%02x:%02x:%02x:%02x:%02x" */
222WS_DLL_PUBLIC const char *get_ether_name(const uint8_t *addr);
223
224/* get_hostname_ss7pc returns the logical name if found in ss7pcs file else
225 '\0' on the first call or the unresolved Point Code in the subsequent calls */
226const char *get_hostname_ss7pc(const uint8_t ni, const uint32_t pc);
227
228/* fill_unresolved_ss7pc initializes the unresolved Point Code Address string in the hashtable */
229void fill_unresolved_ss7pc(const char * pc_addr, const uint8_t ni, const uint32_t pc);
230
231
232/* Same as get_ether_name with tvb support */
233WS_DLL_PUBLIC const char *tvb_get_ether_name(tvbuff_t *tvb, int offset);
234
235/* get_ether_name_if_known returns the logical name if an exact match is
236 * found (in ethers files or from ARP) else NULL.
237 * @note: It returns NULL for addresses if only a prefix can be resolved
238 * into a manufacturer name.
239 */
240const char *get_ether_name_if_known(const uint8_t *addr);
241
242/*
243 * Given a sequence of 3 octets containing an OID, get_manuf_name()
244 * returns an abbreviated form of the vendor name, or "%02x:%02x:%02x"
245 * if not known. (The short form of the name is roughly similar in length
246 * to the hexstring, so that they may be used in similar places.)
247 * @note: This only looks up entries in the 24-bit OUI table (and the
248 * CID table), not the MA-M and MA-S tables. The hex byte string is
249 * returned for sequences registered to the IEEE Registration Authority
250 * for the purposes of being subdivided into MA-M and MA-S.
251 */
252extern const char *get_manuf_name(const uint8_t *addr, size_t size);
253
254/*
255 * Given a sequence of 3 or more octets containing an OUI,
256 * get_manuf_name_if_known() returns the vendor name, or NULL if not known.
257 * @note Unlike get_manuf_name() above, this returns the full vendor name.
258 * @note If size is 6 or larger, vendor names will be looked up in the MA-M
259 * and MA-S tables as well (but note that the length of the sequence is
260 * not returned.) If size is less than 6, only the 24 bit tables are searched,
261 * and NULL is returned for sequences registered to the IEEE Registration
262 * Authority for purposes of being subdivided into MA-M and MA-S.
263 */
264WS_DLL_PUBLIC const char *get_manuf_name_if_known(const uint8_t *addr, size_t size);
265
266/*
267 * Given an integer containing a 24-bit OUI (or CID),
268 * uint_get_manuf_name_if_known() returns the vendor name, or NULL if not known.
269 * @note NULL is returned for sequences registered to the IEEE Registration
270 * Authority for purposes of being subdivided into MA-M and MA-S.
271 */
272extern const char *uint_get_manuf_name_if_known(const uint32_t oid);
273
274/*
275 * Given a tvbuff and an offset in that tvbuff for a 3-octet OID,
276 * tvb_get_manuf_name() returns an abbreviated vendor name, or "%02x:%02x:%02x"
277 * if not known.
278 * @note: This only looks up entries in the 24-bit OUI table (and the
279 * CID table), not the MA-M and MA-S tables. The hex byte string is
280 * returned for sequences registered to the IEEE Registration Authority
281 * for the purposes of being subdivided into MA-M and MA-S.
282 */
283WS_DLL_PUBLIC const char *tvb_get_manuf_name(tvbuff_t *tvb, int offset);
284
285/*
286 * Given a tvbuff and an offset in that tvbuff for a 3-octet OID,
287 * tvb_get_manuf_name_if_known() returns the full vendor name, or NULL
288 * if not known.
289 * @note NULL is returned for sequences registered to the IEEE Registration
290 * Authority for purposes of being subdivided into MA-M and MA-S.
291 */
292WS_DLL_PUBLIC const char *tvb_get_manuf_name_if_known(tvbuff_t *tvb, int offset);
293
294/* eui64_to_display returns "<vendor>_%02x:%02x:%02x:%02x:%02x:%02x" if the
295 * vendor code is known (or as appropriate for MA-M and MA-S), and if not,
296 * "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
297*/
298extern char *eui64_to_display(wmem_allocator_t *allocator, const uint64_t addr);
299
300/* get_ipxnet_name returns the logical name if found in an ipxnets file,
301 * or a string formatted with "%X" if not */
302extern char *get_ipxnet_name(wmem_allocator_t *allocator, const uint32_t addr);
303
304/* get_vlan_name returns the logical name if found in a vlans file,
305 * or the VLAN ID itself as a string if not found*/
306extern char *get_vlan_name(wmem_allocator_t *allocator, const uint16_t id);
307
308WS_DLL_PUBLIC unsigned get_hash_ether_status(hashether_t* ether);
309WS_DLL_PUBLIC bool get_hash_ether_used(hashether_t* ether);
310WS_DLL_PUBLIC char* get_hash_ether_hexaddr(hashether_t* ether);
311WS_DLL_PUBLIC char* get_hash_ether_resolved_name(hashether_t* ether);
312
313WS_DLL_PUBLIC bool get_hash_manuf_used(hashmanuf_t* manuf);
314WS_DLL_PUBLIC char* get_hash_manuf_resolved_name(hashmanuf_t* manuf);
315
316WS_DLL_PUBLIC bool get_hash_wka_used(hashwka_t* wka);
317WS_DLL_PUBLIC char* get_hash_wka_resolved_name(hashwka_t* wka);
318
319/* adds a hostname/IPv4 in the hash table */
320WS_DLL_PUBLIC void add_ipv4_name(const unsigned addr, const char *name, const bool static_entry);
321
322/* adds a hostname/IPv6 in the hash table */
323WS_DLL_PUBLIC void add_ipv6_name(const ws_in6_addr *addr, const char *name, const bool static_entry);
324
334WS_DLL_PUBLIC bool add_hosts_file (const char *hosts_file);
335
336/* adds a hostname in the hash table */
337WS_DLL_PUBLIC bool add_ip_name_from_string (const char *addr, const char *name);
338
339/* Get the user defined name, for a given address */
340WS_DLL_PUBLIC resolved_name_t* get_edited_resolved_name(const char* addr);
341
342
349WS_DLL_PUBLIC addrinfo_lists_t *get_addrinfo_list(void);
350
351/* add ethernet address / name corresponding to IP address */
352extern void add_ether_byip(const unsigned ip, const uint8_t *eth);
353
365WS_DLL_PUBLIC
366bool get_host_ipaddr(const char *host, uint32_t *addrp);
367
379WS_DLL_PUBLIC
380bool get_host_ipaddr6(const char *host, ws_in6_addr *addrp);
381
382WS_DLL_PUBLIC
383wmem_map_t *get_manuf_hashtable(void);
384
385WS_DLL_PUBLIC
386wmem_map_t *get_wka_hashtable(void);
387
388WS_DLL_PUBLIC
389wmem_map_t *get_eth_hashtable(void);
390
391WS_DLL_PUBLIC
392wmem_map_t *get_serv_port_hashtable(void);
393
394WS_DLL_PUBLIC
395wmem_map_t *get_ipxnet_hash_table(void);
396
397WS_DLL_PUBLIC
398wmem_map_t *get_vlan_hash_table(void);
399
400WS_DLL_PUBLIC
401wmem_map_t *get_ipv4_hash_table(void);
402
403WS_DLL_PUBLIC
404wmem_map_t *get_ipv6_hash_table(void);
405
406/*
407 * XXX - if we ever have per-session host name etc. information, we
408 * should probably have the "resolve synchronously or asynchronously"
409 * flag be per-session, set with an epan API.
410 */
411WS_DLL_PUBLIC
412void set_resolution_synchrony(bool synchronous);
413
414/*
415 * private functions (should only be called by epan directly)
416 */
417
418WS_DLL_LOCAL
419void name_resolver_init(void);
420
421/* Reinitialize hostname resolution subsystem */
422WS_DLL_LOCAL
423void host_name_lookup_reset(void);
424
425WS_DLL_LOCAL
426void addr_resolv_init(void);
427
428WS_DLL_LOCAL
429void addr_resolv_cleanup(void);
430
431WS_DLL_PUBLIC
432bool str_to_ip(const char *str, void *dst);
433
434WS_DLL_PUBLIC
435bool str_to_ip6(const char *str, void *dst);
436
437WS_DLL_LOCAL
438bool str_to_eth(const char *str, char *eth_bytes);
439
440WS_DLL_LOCAL
441unsigned ipv6_oat_hash(const void *key);
442
443WS_DLL_LOCAL
444gboolean ipv6_equal(const void *v1, const void *v2);
445
446#ifdef __cplusplus
447}
448#endif /* __cplusplus */
449
450#endif /* __RESOLV_H__ */
WS_DLL_PUBLIC bool host_name_lookup_process(void)
Definition addr_resolv.c:3316
WS_DLL_PUBLIC bool get_host_ipaddr6(const char *host, ws_in6_addr *addrp)
Definition addr_resolv.c:3974
WS_DLL_PUBLIC bool get_host_ipaddr(const char *host, uint32_t *addrp)
Definition addr_resolv.c:3909
WS_DLL_PUBLIC addrinfo_lists_t * get_addrinfo_list(void)
Definition addr_resolv.c:2838
WS_DLL_PUBLIC bool add_hosts_file(const char *hosts_file)
Definition addr_resolv.c:2714
struct _e_addr_resolve e_addr_resolve
Flags to control name resolution.
Flags to control name resolution.
Definition addr_resolv.h:48
bool dns_pkt_addr_resolution
Definition addr_resolv.h:52
bool maxmind_geoip
Definition addr_resolv.h:57
bool ss7pc_name
Definition addr_resolv.h:56
bool use_external_net_name_resolver
Definition addr_resolv.h:54
bool handshake_sni_addr_resolution
Definition addr_resolv.h:53
bool transport_name
Definition addr_resolv.h:51
bool mac_name
Definition addr_resolv.h:49
bool network_name
Definition addr_resolv.h:50
bool vlan_name
Definition addr_resolv.h:55
Definition addr_resolv.h:83
Definition wmem_allocator.h:27
Definition wmem_map.c:44
Definition wtap.h:1507
Definition inet_addr.h:21
Definition addr_resolv.c:162
Definition wtap.h:1489
Definition addr_resolv.c:174
Definition addr_resolv.c:169
Definition prefs-int.h:27
const char * name
Definition prefs-int.h:28
Definition addr_resolv.h:75
Definition tvbuff-int.h:35