79b424232a4bf8b82ab227a413f7c2d6406cfcf2
[obnox/wireshark/wip.git] / epan / addr_resolv.h
1 /* addr_resolv.h
2  * Definitions for network object lookup
3  *
4  * $Id$
5  *
6  * Laurent Deniel <laurent.deniel@free.fr>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
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.
16  *
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.
21  *
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
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.
32  */
33
34 #ifndef __RESOLV_H__
35 #define __RESOLV_H__
36
37 #include <epan/address.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif /* __cplusplus */
42
43 #ifndef MAXNAMELEN
44 #define MAXNAMELEN      64      /* max name length (hostname and port name) */
45 #endif
46
47 /*
48  * Flag controlling what names to resolve.
49  */
50 WS_VAR_IMPORT guint32 gbl_resolv_flags;
51
52 /* 32 types are sufficient (as are 640k of RAM) */
53 /* FIXME: Maybe MANUF/m, IP/i, IP6/6, IPX/x, UDP+TCP/t etc would be
54    more useful/consistent */
55 #define RESOLV_NONE             0x0
56 #define RESOLV_MAC              0x1
57 #define RESOLV_NETWORK          0x2
58 #define RESOLV_TRANSPORT        0x4
59 #define RESOLV_CONCURRENT       0x8
60
61 #define RESOLV_ALL_ADDRS        (RESOLV_MAC|RESOLV_NETWORK|RESOLV_TRANSPORT)
62 #define RESOLV_ALL              0xFFFFFFFF
63
64 /* global variables */
65
66 extern gchar *g_ethers_path;
67 extern gchar *g_ipxnets_path;
68 extern gchar *g_pethers_path;
69 extern gchar *g_pipxnets_path;
70
71 /* Functions in resolv.c */
72
73 /* Set the flags controlling what names to resolve */
74 extern void resolv_set_flags(guint32 flags);
75
76 /*
77  * get_udp_port() returns the port name corresponding to that UDP port,
78  * or the port number as a string if not found.
79  */
80 extern gchar *get_udp_port(guint port);
81
82 /*
83  * get_tcp_port() returns the port name corresponding to that TCP port,
84  * or the port number as a string if not found.
85  */
86 extern gchar *get_tcp_port(guint port);
87
88 /*
89  * get_dccp_port() returns the port name corresponding to that DCCP port,
90  * or the port number as a string if not found.
91  */
92 extern gchar *get_dccp_port(guint port);
93
94 /*
95  * get_sctp_port() returns the port name corresponding to that SCTP port,
96  * or the port number as a string if not found.
97  */
98 extern gchar *get_sctp_port(guint port);
99
100 /* get_addr_name takes as input an "address", as defined in address.h */
101 /* it returns a string that contains: */
102 /*  - if the address is of a type that can be translated into a name, and the user */
103 /*    has activated name resolution, the translated name */
104 /*  - if the address is of type AT_NONE, a pointer to the string "NONE" */
105 /*  - if the address is of any other type, the result of ep_address_to_str on the argument, */
106 /*    which should be a string representation for the answer -e.g. "10.10.10.10" for IPv4 */
107 /*    address 10.10.10.10 */
108
109 const gchar *get_addr_name(const address *addr);
110 const gchar *se_get_addr_name(const address *addr);
111
112 /* get_addr_name_buf solves an address in the same way as get_addr_name above */
113 /* The difference is that get_addr_name_buf takes as input a buffer, into which it puts */
114 /* the result which is always NUL ('\0') terminated. The buffer should be large enough to */
115 /* contain size characters including the terminator */
116
117 void get_addr_name_buf(const address *addr, gchar *buf, gsize size);
118
119
120 /*
121  * Asynchronous host name lookup initialization, processing, and cleanup
122  */
123
124 /* host_name_lookup_init fires up an ADNS socket if we're using ADNS */
125 extern void host_name_lookup_init(void);
126
127 /** If we're using c-ares or ADNS, process outstanding host name lookups.
128  *  This is called from a GLIB timeout in Wireshark and before processing
129  *  each packet in TShark.
130  *
131  * @param data Ignored.
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.
134  */
135 extern gboolean host_name_lookup_process(gpointer data);
136
137 /* host_name_lookup_cleanup cleans up an ADNS socket if we're using ADNS */
138 extern void host_name_lookup_cleanup(void);
139
140 /* get_hostname returns the host name or "%d.%d.%d.%d" if not found */
141 extern const gchar *get_hostname(const guint addr);
142
143 /* get_hostname6 returns the host name, or numeric addr if not found */
144 struct e_in6_addr;
145 extern const gchar* get_hostname6(const struct e_in6_addr *ad);
146
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 extern gchar *get_ether_name(const guint8 *addr);
151
152 /* get_ether_name returns the logical name if found in ethers files else NULL */
153 extern gchar *get_ether_name_if_known(const guint8 *addr);
154
155 /* get_manuf_name returns the vendor name or "%02x:%02x:%02x" if not known */
156 extern const gchar *get_manuf_name(const guint8 *addr);
157
158 /* get_manuf_name returns the vendor name or NULL if not known */
159 extern const gchar *get_manuf_name_if_known(const guint8 *addr);
160
161 /* get_ipxnet_name returns the logical name if found in an ipxnets file,
162  * or a string formatted with "%X" if not */
163 extern const gchar *get_ipxnet_name(const guint32 addr);
164
165 /* returns the ethernet address corresponding to name or NULL if not known */
166 extern guint8 *get_ether_addr(const gchar *name);
167
168 /* returns the ipx network corresponding to name. If name is unknown,
169  * 0 is returned and 'known' is set to FALSE. On success, 'known'
170  * is set to TRUE. */
171 guint32 get_ipxnet_addr(const gchar *name, gboolean *known);
172
173 /* adds a hostname/IPv4 in the hash table */
174 extern void add_ipv4_name(const guint addr, const gchar *name);
175
176 /* adds a hostname/IPv6 in the hash table */
177 extern void add_ipv6_name(const struct e_in6_addr *addr, const gchar *name);
178
179 /* adds a hostname in the hash table */
180 extern gboolean add_ip_name_from_string (const char *addr, const char *name);
181
182 /* add ethernet address / name corresponding to IP address  */
183 extern void add_ether_byip(const guint ip, const guint8 *eth);
184
185 /** Translates a string representing a hostname or dotted-decimal IPv4 address
186  *  into a numeric IPv4 address value in network byte order. If compiled with
187  *  c-ares, the request will wait a maximum of 250ms for the request to finish.
188  *  Otherwise the wait time will be system-dependent, ususally much longer.
189  *  Immediately returns FALSE for hostnames if network name resolution is
190  *  disabled.
191  *
192  * @param[in] host The hostname.
193  * @param[out] addrp The numeric IPv4 address in network byte order.
194  * @return TRUE on success, FALSE on failure, timeout.
195  */
196 gboolean get_host_ipaddr(const char *host, guint32 *addrp);
197
198 /** Translates a string representing a hostname or colon-hex IPv6 address
199  *  into a numeric IPv6 address value in network byte order. If compiled with
200  *  c-ares, the request will wait a maximum of 250ms for the request to finish.
201  *  Otherwise the wait time will be system-dependent, usually much longer.
202  *  Immediately returns FALSE for hostnames if network name resolution is
203  *  disabled.
204  *
205  * @param[in] host The hostname.
206  * @param[out] addrp The numeric IPv6 address in network byte order.
207  * @return TRUE on success, FALSE on failure or timeout.
208  */
209 gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp);
210
211 /*
212  * Find out whether a hostname resolves to an ip or ipv6 address
213  * Return "ip6" if it is IPv6, "ip" otherwise (including the case
214  * that we don't know)
215  */
216 const char* host_ip_af(const char *host);
217
218 #ifdef __cplusplus
219 }
220 #endif /* __cplusplus */
221
222 #endif /* __RESOLV_H__ */