Wireshark 4.7.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
64
65#define ADDR_RESOLV_MACADDR(at) \
66 (((at)->type == AT_ETHER) || ((at)->type == AT_EUI64))
67
68#define ADDR_RESOLV_NETADDR(at) \
69 (((at)->type == AT_IPv4) || ((at)->type == AT_IPv6) || ((at)->type == AT_IPX))
70
71struct hashether;
72typedef struct hashether hashether_t;
73
74struct hasheui64;
75typedef struct hasheui64 hasheui64_t;
76
77struct hashwka;
78typedef struct hashwka hashwka_t;
79
80struct hashmanuf;
81typedef struct hashmanuf hashmanuf_t;
82
83typedef struct _serv_port_key {
84 uint16_t port;
85 port_type type;
87
88/* Used for manually edited DNS resolved names */
89typedef struct _resolved_name {
90 char name[MAXDNSNAMELEN];
92
93/*
94 * Flags for various resolved name hash table entries.
95 */
96#define TRIED_RESOLVE_ADDRESS (1U<<0) /* name resolution is being/has been tried */
97#define NAME_RESOLVED (1U<<1) /* the name field contains a host name, not a printable address */
98#define RESOLVED_ADDRESS_USED (1U<<2) /* a get_hostname* call returned the host name */
99#define STATIC_HOSTNAME (1U<<3) /* do not update entries from hosts file with DNS responses */
100#define NAME_RESOLVED_PREFIX (1U<<4) /* name was generated from a prefix (e.g., OUI) instead of the entire address */
101
102#define TRIED_OR_RESOLVED_MASK (TRIED_RESOLVE_ADDRESS | NAME_RESOLVED)
103#define USED_AND_RESOLVED_MASK (NAME_RESOLVED | RESOLVED_ADDRESS_USED)
104
105/*
106 * Flag controlling what names to resolve.
107 */
108WS_DLL_PUBLIC e_addr_resolve gbl_resolv_flags;
109
110/* global variables */
111
112extern char *g_ethers_path;
113extern char *g_ipxnets_path;
114extern char *g_pethers_path;
115extern char *g_pipxnets_path;
116
117/* Functions in addr_resolv.c */
118
129WS_DLL_PUBLIC hashipv4_t * new_ipv4(const unsigned addr);
130
143WS_DLL_PUBLIC bool fill_dummy_ip4(const unsigned addr, hashipv4_t* volatile tp);
144
156WS_DLL_PUBLIC char *udp_port_to_display(wmem_allocator_t *allocator, unsigned port);
157
158
170WS_DLL_PUBLIC char *tcp_port_to_display(wmem_allocator_t *allocator, unsigned port);
171
183WS_DLL_PUBLIC char *dccp_port_to_display(wmem_allocator_t *allocator, unsigned port);
184
196WS_DLL_PUBLIC char *sctp_port_to_display(wmem_allocator_t *allocator, unsigned port);
197
210WS_DLL_PUBLIC const char *serv_name_lookup(port_type proto, unsigned port);
211
226WS_DLL_PUBLIC const char *enterprises_lookup(uint32_t value, const char *unknown_str);
227
238WS_DLL_PUBLIC const char *try_enterprises_lookup(uint32_t value);
239
250WS_DLL_PUBLIC void enterprises_base_custom(char *buf, uint32_t value);
251
263WS_DLL_PUBLIC const char *try_serv_name_lookup(port_type proto, unsigned port);
264
278WS_DLL_PUBLIC char *port_with_resolution_to_str(wmem_allocator_t *scope,
279 port_type proto, unsigned port);
280
299WS_DLL_PUBLIC int port_with_resolution_to_str_buf(char *buf, unsigned long buf_size,
300 port_type proto, unsigned port);
301
302/*
303 * Asynchronous host name lookup initialization, processing, and cleanup
304 */
305
306/* Setup name resolution preferences */
307struct pref_module;
308extern void addr_resolve_pref_init(struct pref_module *nameres);
309extern void addr_resolve_pref_apply(void);
310
319WS_DLL_PUBLIC void disable_name_resolution(void);
320
332WS_DLL_PUBLIC bool host_name_lookup_process(void);
333
350WS_DLL_PUBLIC const char *get_hostname(const unsigned addr);
351
367WS_DLL_PUBLIC char *get_hostname_wmem(wmem_allocator_t *allocator, const unsigned addr);
368
383WS_DLL_PUBLIC const char *get_hostname6(const ws_in6_addr *ad);
384
395WS_DLL_PUBLIC char *get_hostname6_wmem(wmem_allocator_t *allocator, const ws_in6_addr *ad);
396
412WS_DLL_PUBLIC const char *get_ether_name(const uint8_t *addr);
413
424WS_DLL_PUBLIC const char *get_hostname_ss7pc(const uint8_t ni, const uint32_t pc);
425
435WS_DLL_PUBLIC void fill_unresolved_ss7pc(const char * pc_addr, const uint8_t ni, const uint32_t pc);
436
448WS_DLL_PUBLIC const char *tvb_get_ether_name(tvbuff_t *tvb, unsigned offset);
449
462WS_DLL_PUBLIC const char *get_ether_name_if_known(const uint8_t *addr);
463
480extern const char *get_manuf_name(const uint8_t *addr, size_t size);
481
498WS_DLL_PUBLIC const char *get_manuf_name_if_known(const uint8_t *addr, size_t size);
499
511WS_DLL_PUBLIC const char *uint_get_manuf_name_if_known(const uint32_t oid);
512
528WS_DLL_PUBLIC const char *tvb_get_manuf_name(tvbuff_t *tvb, unsigned offset);
529
543WS_DLL_PUBLIC const char *tvb_get_manuf_name_if_known(tvbuff_t *tvb, unsigned offset);
544
557extern const char *get_eui64_name(const uint8_t *addr);
558
574WS_DLL_PUBLIC char *eui64_to_display(wmem_allocator_t *allocator, const uint64_t addr);
575
588WS_DLL_PUBLIC char *get_ipxnet_name(wmem_allocator_t *allocator, const uint32_t addr);
589
602WS_DLL_PUBLIC char *get_vlan_name(wmem_allocator_t *allocator, const uint16_t id);
603
610WS_DLL_PUBLIC unsigned get_hash_ether_status(hashether_t* ether);
611
618WS_DLL_PUBLIC bool get_hash_ether_used(hashether_t* ether);
619
626WS_DLL_PUBLIC char* get_hash_ether_hexaddr(hashether_t* ether);
627
634WS_DLL_PUBLIC char* get_hash_ether_resolved_name(hashether_t* ether);
635
642WS_DLL_PUBLIC bool get_hash_manuf_used(hashmanuf_t* manuf);
643
650WS_DLL_PUBLIC char* get_hash_manuf_resolved_name(hashmanuf_t* manuf);
651
658WS_DLL_PUBLIC bool get_hash_wka_used(hashwka_t* wka);
659
666WS_DLL_PUBLIC char* get_hash_wka_resolved_name(hashwka_t* wka);
667
677WS_DLL_PUBLIC void add_ipv4_name(const unsigned addr, const char *name, const bool static_entry);
678
688WS_DLL_PUBLIC void add_ipv6_name(const ws_in6_addr *addr, const char *name, const bool static_entry);
689
700WS_DLL_PUBLIC bool add_hosts_file(const char *hosts_file);
701
712WS_DLL_PUBLIC bool add_ip_name_from_string(const char *addr, const char *name);
713
723WS_DLL_PUBLIC resolved_name_t* get_edited_resolved_name(const char* addr);
724
733WS_DLL_PUBLIC addrinfo_lists_t *get_addrinfo_list(void);
734
744WS_DLL_PUBLIC void add_ether_byip(const unsigned ip, const uint8_t *eth);
745
760WS_DLL_PUBLIC
761bool get_host_ipaddr(const char *host, uint32_t *addrp);
762
777WS_DLL_PUBLIC
778bool get_host_ipaddr6(const char *host, ws_in6_addr *addrp);
779
787WS_DLL_PUBLIC
789
797WS_DLL_PUBLIC
799
807WS_DLL_PUBLIC
809
817WS_DLL_PUBLIC
819
827WS_DLL_PUBLIC
829
837WS_DLL_PUBLIC
839
847WS_DLL_PUBLIC
849
857WS_DLL_PUBLIC
859
860
861/*
862 * XXX - if we ever have per-session host name etc. information, we
863 * should probably have the "resolve synchronously or asynchronously"
864 * flag be per-session, set with an epan API.
865 */
874WS_DLL_PUBLIC
875void set_resolution_synchrony(bool synchronous);
876
877/*
878 * private functions (should only be called by epan directly)
879 */
880
887WS_DLL_LOCAL
889
896WS_DLL_LOCAL
897void host_name_lookup_reset(const char* app_env_var_prefix);
898
905WS_DLL_LOCAL
906void addr_resolv_init(const char* app_env_var_prefix);
907
914WS_DLL_LOCAL
915void addr_resolv_cleanup(void);
916
926WS_DLL_PUBLIC
927bool str_to_ip(const char *str, void *dst);
928
938WS_DLL_PUBLIC
939bool str_to_ip6(const char *str, void *dst);
940
951WS_DLL_LOCAL
952bool str_to_eth(const char *str, uint8_t (*eth_bytes)[6]);
953
963WS_DLL_LOCAL
964unsigned ipv6_oat_hash(const void *key);
965
976WS_DLL_LOCAL
977gboolean ipv6_equal(const void *v1, const void *v2);
978
995WS_DLL_PUBLIC const char *tac_name_lookup(const unsigned addr);
996
997#ifdef __cplusplus
998}
999#endif /* __cplusplus */
1000
1001#endif /* __RESOLV_H__ */
WS_DLL_PUBLIC bool host_name_lookup_process(void)
Process outstanding asynchronous host name lookups via c-ares.
Definition addr_resolv.c:3539
WS_DLL_PUBLIC wmem_map_t * get_ipv4_hash_table(void)
Retrieves the IPv4 address hashtable.
Definition addr_resolv.c:4301
WS_DLL_PUBLIC void fill_unresolved_ss7pc(const char *pc_addr, const uint8_t ni, const uint32_t pc)
Initializes unresolved SS7 Point Code entries in the hashtable.
Definition addr_resolv.c:3225
WS_DLL_PUBLIC char * get_vlan_name(wmem_allocator_t *allocator, const uint16_t id)
Resolves a VLAN ID to a name.
Definition addr_resolv.c:4008
WS_DLL_PUBLIC const char * get_hostname(const unsigned addr)
Resolve an IPv4 address to its host name.
Definition addr_resolv.c:3586
WS_DLL_PUBLIC const char * get_ether_name_if_known(const uint8_t *addr)
Resolves an Ethernet address only if an exact match is known.
Definition addr_resolv.c:3948
WS_DLL_PUBLIC char * eui64_to_display(wmem_allocator_t *allocator, const uint64_t addr)
Converts a uint64_t EUI-64 address to a display string.
Definition addr_resolv.c:4110
WS_DLL_PUBLIC char * tcp_port_to_display(wmem_allocator_t *allocator, unsigned port)
Resolve a TCP port number to its display name.
Definition addr_resolv.c:3875
WS_DLL_PUBLIC void enterprises_base_custom(char *buf, uint32_t value)
Format a private enterprise code as "name (decimal)" into a buffer.
Definition addr_resolv.c:1141
WS_DLL_PUBLIC bool get_hash_wka_used(hashwka_t *wka)
Checks if a WKA hash entry was used.
Definition addr_resolv.c:1938
WS_DLL_PUBLIC const char * get_manuf_name_if_known(const uint8_t *addr, size_t size)
Resolves an OUI to a full vendor name if known.
Definition addr_resolv.c:4043
WS_DLL_PUBLIC char * get_hash_wka_resolved_name(hashwka_t *wka)
Gets the resolved name for a WKA hash entry.
Definition addr_resolv.c:1943
WS_DLL_PUBLIC wmem_map_t * get_wka_hashtable(void)
Retrieves the well-known address (WKA) hashtable.
Definition addr_resolv.c:4271
WS_DLL_PUBLIC bool get_hash_ether_used(hashether_t *ether)
Checks if an Ethernet hash entry was used.
Definition addr_resolv.c:1923
WS_DLL_PUBLIC const char * tvb_get_ether_name(tvbuff_t *tvb, unsigned offset)
Resolves an Ethernet address from a tvbuff.
Definition addr_resolv.c:3939
WS_DLL_PUBLIC const char * try_enterprises_lookup(uint32_t value)
Attempt to resolve a private enterprise code to its registered name.
Definition addr_resolv.c:1117
WS_DLL_PUBLIC wmem_map_t * get_manuf_hashtable(void)
Retrieves the manufacturer hashtable.
Definition addr_resolv.c:4265
const char * get_manuf_name(const uint8_t *addr, size_t size)
Resolves a 3-octet OUI to a short vendor name.
Definition addr_resolv.c:4020
WS_DLL_PUBLIC const char * serv_name_lookup(port_type proto, unsigned port)
Resolve a port number to its well-known service name.
Definition addr_resolv.c:984
WS_DLL_PUBLIC wmem_map_t * get_ipv6_hash_table(void)
Retrieves the IPv6 address hashtable.
Definition addr_resolv.c:4307
WS_DLL_PUBLIC bool get_host_ipaddr6(const char *host, ws_in6_addr *addrp)
Resolves a hostname or IPv6 string to a numeric IPv6 address.
Definition addr_resolv.c:4206
WS_DLL_PUBLIC void add_ether_byip(const unsigned ip, const uint8_t *eth)
Associates an Ethernet (MAC) address / name to an IPv4 address.
Definition addr_resolv.c:3972
const char * get_eui64_name(const uint8_t *addr)
Resolves an EUI-64 address to a logical name or vendor string.
Definition addr_resolv.c:4098
WS_DLL_LOCAL unsigned ipv6_oat_hash(const void *key)
Computes a hash value for an IPv6 address using OAT hashing.
Definition addr_resolv.c:266
WS_DLL_PUBLIC hashipv4_t * new_ipv4(const unsigned addr)
Construct a new IPv4 object from a 32-bit address.
Definition addr_resolv.c:1268
WS_DLL_PUBLIC char * udp_port_to_display(wmem_allocator_t *allocator, unsigned port)
Resolve a UDP port number to its display name.
Definition addr_resolv.c:3851
WS_DLL_PUBLIC wmem_map_t * get_serv_port_hashtable(void)
Retrieves the service port hashtable.
Definition addr_resolv.c:4283
WS_DLL_LOCAL void addr_resolv_cleanup(void)
Cleans up the address resolution subsystem.
Definition addr_resolv.c:4328
WS_DLL_PUBLIC void add_ipv4_name(const unsigned addr, const char *name, const bool static_entry)
Adds a static or dynamic IPv4 name mapping.
Definition addr_resolv.c:3656
WS_DLL_PUBLIC unsigned get_hash_ether_status(hashether_t *ether)
Gets the status code for a resolved Ethernet entry.
Definition addr_resolv.c:1918
WS_DLL_LOCAL bool str_to_eth(const char *str, uint8_t(*eth_bytes)[6])
Parses a string as an Ethernet (MAC) address.
Definition addr_resolv.c:4360
WS_DLL_PUBLIC bool get_hash_manuf_used(hashmanuf_t *manuf)
Checks if a manufacturer hash entry was used.
Definition addr_resolv.c:4087
WS_DLL_PUBLIC const char * try_serv_name_lookup(port_type proto, unsigned port)
Attempt to resolve a port number to its well-known service name.
Definition addr_resolv.c:978
WS_DLL_PUBLIC bool str_to_ip6(const char *str, void *dst)
Parses a string as an IPv6 address.
Definition addr_resolv.c:4349
WS_DLL_PUBLIC wmem_map_t * get_ipxnet_hash_table(void)
Retrieves the IPX network hashtable.
Definition addr_resolv.c:4289
WS_DLL_PUBLIC bool add_ip_name_from_string(const char *addr, const char *name)
Adds a hostname mapping for a given IP address string.
Definition addr_resolv.c:2887
WS_DLL_PUBLIC char * get_hash_ether_resolved_name(hashether_t *ether)
Gets the resolved name for an Ethernet hash entry.
Definition addr_resolv.c:1933
WS_DLL_PUBLIC bool str_to_ip(const char *str, void *dst)
Parses a string as an IPv4 address.
Definition addr_resolv.c:4343
WS_DLL_PUBLIC const char * tac_name_lookup(const unsigned addr)
Resolve an TAC to its area name.
Definition addr_resolv.c:3399
WS_DLL_PUBLIC bool get_host_ipaddr(const char *host, uint32_t *addrp)
Resolves a hostname or IPv4 string to a numeric IPv4 address.
Definition addr_resolv.c:4141
WS_DLL_PUBLIC const char * tvb_get_manuf_name(tvbuff_t *tvb, unsigned offset)
Resolves a 3-octet OUI from a tvbuff to a short vendor name.
Definition addr_resolv.c:4035
WS_DLL_PUBLIC void add_ipv6_name(const ws_in6_addr *addr, const char *name, const bool static_entry)
Adds a Hostname/IPv4 in the hash table.
Definition addr_resolv.c:3684
WS_DLL_PUBLIC const char * tvb_get_manuf_name_if_known(tvbuff_t *tvb, unsigned offset)
Resolves a 3-octet OUI from a tvbuff to a full vendor name.
Definition addr_resolv.c:4080
WS_DLL_LOCAL void name_resolver_init(void)
Initializes the name resolution subsystem.
WS_DLL_PUBLIC const char * enterprises_lookup(uint32_t value, const char *unknown_str)
Resolve a private enterprise code to its registered name.
Definition addr_resolv.c:1128
WS_DLL_PUBLIC char * get_hash_ether_hexaddr(hashether_t *ether)
Gets the hex string representation of an Ethernet address.
Definition addr_resolv.c:1928
WS_DLL_PUBLIC addrinfo_lists_t * get_addrinfo_list(void)
Retrieves known host-to-address mappings.
Definition addr_resolv.c:2987
WS_DLL_PUBLIC char * sctp_port_to_display(wmem_allocator_t *allocator, unsigned port)
Resolve an SCTP port number to its display name.
Definition addr_resolv.c:3887
WS_DLL_PUBLIC bool fill_dummy_ip4(const unsigned addr, hashipv4_t *volatile tp)
Populate a dummy IPv4 object with the specified address.
Definition addr_resolv.c:1166
WS_DLL_PUBLIC resolved_name_t * get_edited_resolved_name(const char *addr)
Retrieves the user-defined name for a given address.
Definition addr_resolv.c:2942
WS_DLL_LOCAL void addr_resolv_init(const char *app_env_var_prefix)
Initializes the address resolution subsystem.
Definition addr_resolv.c:4313
WS_DLL_PUBLIC char * get_hostname_wmem(wmem_allocator_t *allocator, const unsigned addr)
Resolve an IPv4 address to its host name using scoped memory allocation.
Definition addr_resolv.c:3613
WS_DLL_LOCAL gboolean ipv6_equal(const void *v1, const void *v2)
Compares two IPv6 addresses for equality.
Definition addr_resolv.c:297
WS_DLL_PUBLIC char * dccp_port_to_display(wmem_allocator_t *allocator, unsigned port)
Resolve a DCCP port number to its display name.
Definition addr_resolv.c:3863
WS_DLL_PUBLIC const char * get_ether_name(const uint8_t *addr)
Resolves an Ethernet address to a logical name or vendor string.
Definition addr_resolv.c:3927
WS_DLL_PUBLIC wmem_map_t * get_vlan_hash_table(void)
Retrieves the VLAN ID hashtable.
Definition addr_resolv.c:4295
WS_DLL_PUBLIC const char * uint_get_manuf_name_if_known(const uint32_t oid)
Resolves a 24-bit OUI integer to a vendor name.
Definition addr_resolv.c:4069
WS_DLL_PUBLIC bool add_hosts_file(const char *hosts_file)
Adds an additional "hosts" file for IPv4 and IPv6 name resolution.
Definition addr_resolv.c:2863
WS_DLL_PUBLIC const char * get_hostname6(const ws_in6_addr *ad)
Resolves an IPv6 address to a hostname or numeric string.
Definition addr_resolv.c:3627
WS_DLL_PUBLIC char * get_hostname6_wmem(wmem_allocator_t *allocator, const ws_in6_addr *ad)
Resolves an IPv6 address to a hostname using a memory allocator.
Definition addr_resolv.c:3643
struct _e_addr_resolve e_addr_resolve
Flags to control name resolution.
WS_DLL_PUBLIC const char * get_hostname_ss7pc(const uint8_t ni, const uint32_t pc)
Resolves an SS7 Point Code to a hostname.
Definition addr_resolv.c:3233
WS_DLL_PUBLIC void disable_name_resolution(void)
Disable all forms of name resolution.
Definition addr_resolv.c:3525
WS_DLL_PUBLIC char * get_ipxnet_name(wmem_allocator_t *allocator, const uint32_t addr)
Resolves an IPX network number to a name.
Definition addr_resolv.c:3996
WS_DLL_PUBLIC int port_with_resolution_to_str_buf(char *buf, unsigned long buf_size, port_type proto, unsigned port)
Format a port number with its resolved service name into a buffer.
Definition addr_resolv.c:3913
WS_DLL_LOCAL void host_name_lookup_reset(const char *app_env_var_prefix)
Reinitialize hostname resolution subsystem.
Definition addr_resolv.c:3844
WS_DLL_PUBLIC char * port_with_resolution_to_str(wmem_allocator_t *scope, port_type proto, unsigned port)
Format a port number with its resolved service name.
Definition addr_resolv.c:3899
WS_DLL_PUBLIC void set_resolution_synchrony(bool synchronous)
Sets the resolution mode to synchronous or asynchronous.
Definition addr_resolv.c:689
WS_DLL_PUBLIC char * get_hash_manuf_resolved_name(hashmanuf_t *manuf)
Gets the resolved name for a manufacturer hash entry.
Definition addr_resolv.c:4092
WS_DLL_PUBLIC wmem_map_t * get_eth_hashtable(void)
Retrieves the Ethernet address hashtable.
Definition addr_resolv.c:4277
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 tac_name
Definition addr_resolv.h:62
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:89
Definition addr_resolv.h:83
Internal memory allocator interface used by the wmem subsystem.
Definition wmem_allocator.h:34
Definition wmem_map.c:60
Definition wtap.h:1608
Represents a 128-bit IPv6 address.
Definition inet_addr.h:27
Definition addr_resolv.c:162
Definition addr_resolv.c:169
Definition wtap.h:1590
Definition addr_resolv.c:181
Definition addr_resolv.c:176
Definition prefs-int.h:27
const char * name
Definition prefs-int.h:28
Definition tvbuff-int.h:36