2004-08-09 22:31:21 +00:00
|
|
|
/* addr_resolv.h
|
1998-09-16 02:39:15 +00:00
|
|
|
* Definitions for network object lookup
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
1998-09-16 03:22:19 +00:00
|
|
|
*
|
2003-01-26 19:35:31 +00:00
|
|
|
* Laurent Deniel <laurent.deniel@free.fr>
|
1998-09-16 02:39:15 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
1998-09-16 02:39:15 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2009-09-06 14:25:47 +00:00
|
|
|
/* The buffers returned by these functions are all allocated with a
|
|
|
|
* packet lifetime and does not have have to be freed.
|
2005-08-17 20:45:18 +00:00
|
|
|
* However, take into account that when the packet dissection
|
|
|
|
* completes, these buffers will be automatically reclaimed/freed.
|
|
|
|
* If you need the buffer to remain for a longer scope than packet lifetime
|
|
|
|
* you must copy the content to an se_alloc() buffer.
|
|
|
|
*/
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
#ifndef __RESOLV_H__
|
|
|
|
#define __RESOLV_H__
|
|
|
|
|
2005-01-07 11:56:00 +00:00
|
|
|
#include <epan/address.h>
|
|
|
|
|
2007-01-18 18:43:30 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
1999-11-20 05:35:15 +00:00
|
|
|
#ifndef MAXNAMELEN
|
|
|
|
#define MAXNAMELEN 64 /* max name length (hostname and port name) */
|
|
|
|
#endif
|
|
|
|
|
2002-01-13 20:35:12 +00:00
|
|
|
/*
|
|
|
|
* Flag controlling what names to resolve.
|
|
|
|
*/
|
2010-10-12 13:15:08 +00:00
|
|
|
WS_VAR_IMPORT guint32 gbl_resolv_flags;
|
2002-01-13 20:35:12 +00:00
|
|
|
|
|
|
|
/* 32 types are sufficient (as are 640k of RAM) */
|
|
|
|
/* FIXME: Maybe MANUF/m, IP/i, IP6/6, IPX/x, UDP+TCP/t etc would be
|
|
|
|
more useful/consistent */
|
|
|
|
#define RESOLV_NONE 0x0
|
|
|
|
#define RESOLV_MAC 0x1
|
|
|
|
#define RESOLV_NETWORK 0x2
|
|
|
|
#define RESOLV_TRANSPORT 0x4
|
2003-07-22 03:14:31 +00:00
|
|
|
#define RESOLV_CONCURRENT 0x8
|
2004-02-13 01:09:52 +00:00
|
|
|
|
|
|
|
#define RESOLV_ALL_ADDRS (RESOLV_MAC|RESOLV_NETWORK|RESOLV_TRANSPORT)
|
2002-01-13 20:35:12 +00:00
|
|
|
#define RESOLV_ALL 0xFFFFFFFF
|
|
|
|
|
1998-09-25 23:24:07 +00:00
|
|
|
/* global variables */
|
|
|
|
|
|
|
|
extern gchar *g_ethers_path;
|
1999-11-21 16:32:23 +00:00
|
|
|
extern gchar *g_ipxnets_path;
|
1998-09-25 23:24:07 +00:00
|
|
|
extern gchar *g_pethers_path;
|
1999-11-21 16:32:23 +00:00
|
|
|
extern gchar *g_pipxnets_path;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
/* Functions in resolv.c */
|
|
|
|
|
2002-01-13 20:35:12 +00:00
|
|
|
/* Set the flags controlling what names to resolve */
|
|
|
|
extern void resolv_set_flags(guint32 flags);
|
|
|
|
|
2004-12-30 02:10:24 +00:00
|
|
|
/*
|
|
|
|
* get_udp_port() returns the port name corresponding to that UDP port,
|
|
|
|
* or the port number as a string if not found.
|
|
|
|
*/
|
2004-01-10 17:31:40 +00:00
|
|
|
extern gchar *get_udp_port(guint port);
|
1998-09-25 23:24:07 +00:00
|
|
|
|
2004-12-30 02:10:24 +00:00
|
|
|
/*
|
|
|
|
* get_tcp_port() returns the port name corresponding to that TCP port,
|
|
|
|
* or the port number as a string if not found.
|
|
|
|
*/
|
2004-01-10 17:31:40 +00:00
|
|
|
extern gchar *get_tcp_port(guint port);
|
1998-09-25 23:24:07 +00:00
|
|
|
|
2005-09-20 15:18:28 +00:00
|
|
|
/*
|
|
|
|
* get_dccp_port() returns the port name corresponding to that DCCP port,
|
|
|
|
* or the port number as a string if not found.
|
|
|
|
*/
|
|
|
|
extern gchar *get_dccp_port(guint port);
|
|
|
|
|
2004-12-30 02:10:24 +00:00
|
|
|
/*
|
|
|
|
* get_sctp_port() returns the port name corresponding to that SCTP port,
|
|
|
|
* or the port number as a string if not found.
|
|
|
|
*/
|
2004-01-10 17:31:40 +00:00
|
|
|
extern gchar *get_sctp_port(guint port);
|
2000-08-19 08:26:04 +00:00
|
|
|
|
2005-02-22 01:55:04 +00:00
|
|
|
/* get_addr_name takes as input an "address", as defined in address.h */
|
|
|
|
/* it returns a string that contains: */
|
|
|
|
/* - if the address is of a type that can be translated into a name, and the user */
|
|
|
|
/* has activated name resolution, the translated name */
|
|
|
|
/* - if the address is of type AT_NONE, a pointer to the string "NONE" */
|
2009-09-06 14:25:47 +00:00
|
|
|
/* - if the address is of any other type, the result of ep_address_to_str on the argument, */
|
2005-02-22 01:55:04 +00:00
|
|
|
/* which should be a string representation for the answer -e.g. "10.10.10.10" for IPv4 */
|
|
|
|
/* address 10.10.10.10 */
|
|
|
|
|
2009-09-07 16:17:58 +00:00
|
|
|
const gchar *get_addr_name(const address *addr);
|
|
|
|
const gchar *se_get_addr_name(const address *addr);
|
2004-12-30 02:10:24 +00:00
|
|
|
|
2005-02-22 01:55:04 +00:00
|
|
|
/* get_addr_name_buf solves an address in the same way as get_addr_name above */
|
2007-09-28 18:23:59 +00:00
|
|
|
/* The difference is that get_addr_name_buf takes as input a buffer, into which it puts */
|
|
|
|
/* the result which is always NUL ('\0') terminated. The buffer should be large enough to */
|
|
|
|
/* contain size characters including the terminator */
|
2005-02-22 01:55:04 +00:00
|
|
|
|
2010-04-03 18:18:50 +00:00
|
|
|
void get_addr_name_buf(const address *addr, gchar *buf, gsize size);
|
2005-02-22 01:55:04 +00:00
|
|
|
|
|
|
|
|
2003-05-05 08:20:01 +00:00
|
|
|
/*
|
|
|
|
* Asynchronous host name lookup initialization, processing, and cleanup
|
|
|
|
*/
|
|
|
|
|
2003-05-04 18:50:56 +00:00
|
|
|
/* host_name_lookup_init fires up an ADNS socket if we're using ADNS */
|
2003-05-05 00:53:06 +00:00
|
|
|
extern void host_name_lookup_init(void);
|
2003-05-04 18:50:56 +00:00
|
|
|
|
2009-12-22 20:01:06 +00:00
|
|
|
/** If we're using c-ares or ADNS, process outstanding host name lookups.
|
|
|
|
* This is called from a GLIB timeout in Wireshark and before processing
|
|
|
|
* each packet in TShark.
|
|
|
|
*
|
|
|
|
* @param data Ignored.
|
|
|
|
* @return True if any new objects have been resolved since the previous
|
|
|
|
* call. This can be used to trigger a display update, e.g. in Wireshark.
|
|
|
|
*/
|
2008-07-08 02:25:30 +00:00
|
|
|
extern gboolean host_name_lookup_process(gpointer data);
|
2003-05-05 08:20:01 +00:00
|
|
|
|
2003-05-04 18:50:56 +00:00
|
|
|
/* host_name_lookup_cleanup cleans up an ADNS socket if we're using ADNS */
|
2003-05-05 00:53:06 +00:00
|
|
|
extern void host_name_lookup_cleanup(void);
|
2003-05-04 18:50:56 +00:00
|
|
|
|
1998-09-25 23:24:07 +00:00
|
|
|
/* get_hostname returns the host name or "%d.%d.%d.%d" if not found */
|
2010-04-03 18:18:50 +00:00
|
|
|
extern const gchar *get_hostname(const guint addr);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
2003-05-04 18:50:56 +00:00
|
|
|
/* get_hostname6 returns the host name, or numeric addr if not found */
|
1999-03-28 18:32:03 +00:00
|
|
|
struct e_in6_addr;
|
2010-04-03 18:18:50 +00:00
|
|
|
extern const gchar* get_hostname6(const struct e_in6_addr *ad);
|
1999-03-28 18:32:03 +00:00
|
|
|
|
1998-09-25 23:24:07 +00:00
|
|
|
/* get_ether_name returns the logical name if found in ethers files else
|
|
|
|
"<vendor>_%02x:%02x:%02x" if the vendor code is known else
|
|
|
|
"%02x:%02x:%02x:%02x:%02x:%02x" */
|
2004-01-10 17:31:40 +00:00
|
|
|
extern gchar *get_ether_name(const guint8 *addr);
|
1998-09-25 23:24:07 +00:00
|
|
|
|
1999-11-20 05:35:15 +00:00
|
|
|
/* get_ether_name returns the logical name if found in ethers files else NULL */
|
2004-01-10 17:31:40 +00:00
|
|
|
extern gchar *get_ether_name_if_known(const guint8 *addr);
|
1999-11-20 05:35:15 +00:00
|
|
|
|
1998-09-25 23:24:07 +00:00
|
|
|
/* get_manuf_name returns the vendor name or "%02x:%02x:%02x" if not known */
|
2004-01-10 17:31:40 +00:00
|
|
|
extern const gchar *get_manuf_name(const guint8 *addr);
|
1998-09-25 23:24:07 +00:00
|
|
|
|
2005-05-20 21:44:17 +00:00
|
|
|
/* get_manuf_name returns the vendor name or NULL if not known */
|
|
|
|
extern const gchar *get_manuf_name_if_known(const guint8 *addr);
|
|
|
|
|
1999-11-21 16:32:23 +00:00
|
|
|
/* get_ipxnet_name returns the logical name if found in an ipxnets file,
|
|
|
|
* or a string formatted with "%X" if not */
|
2004-01-10 17:31:40 +00:00
|
|
|
extern const gchar *get_ipxnet_name(const guint32 addr);
|
1999-11-21 16:32:23 +00:00
|
|
|
|
1998-09-25 23:24:07 +00:00
|
|
|
/* returns the ethernet address corresponding to name or NULL if not known */
|
2004-01-10 17:31:40 +00:00
|
|
|
extern guint8 *get_ether_addr(const gchar *name);
|
1998-09-25 23:24:07 +00:00
|
|
|
|
1999-11-21 16:32:23 +00:00
|
|
|
/* returns the ipx network corresponding to name. If name is unknown,
|
2001-01-31 05:52:24 +00:00
|
|
|
* 0 is returned and 'known' is set to FALSE. On success, 'known'
|
|
|
|
* is set to TRUE. */
|
2004-01-10 17:31:40 +00:00
|
|
|
guint32 get_ipxnet_addr(const gchar *name, gboolean *known);
|
1999-11-21 16:32:23 +00:00
|
|
|
|
2004-11-17 08:53:20 +00:00
|
|
|
/* adds a hostname/IPv4 in the hash table */
|
2010-04-03 18:18:50 +00:00
|
|
|
extern void add_ipv4_name(const guint addr, const gchar *name);
|
1998-09-25 23:24:07 +00:00
|
|
|
|
2004-11-17 09:44:41 +00:00
|
|
|
/* adds a hostname/IPv6 in the hash table */
|
2010-04-03 18:18:50 +00:00
|
|
|
extern void add_ipv6_name(const struct e_in6_addr *addr, const gchar *name);
|
2004-11-17 09:44:41 +00:00
|
|
|
|
2010-04-27 06:51:16 +00:00
|
|
|
/* adds a hostname in the hash table */
|
2010-04-27 22:46:39 +00:00
|
|
|
extern gboolean add_ip_name_from_string (const char *addr, const char *name);
|
2010-04-27 06:51:16 +00:00
|
|
|
|
2000-08-10 20:09:29 +00:00
|
|
|
/* add ethernet address / name corresponding to IP address */
|
2010-04-03 18:18:50 +00:00
|
|
|
extern void add_ether_byip(const guint ip, const guint8 *eth);
|
2000-08-10 20:09:29 +00:00
|
|
|
|
2009-12-24 00:58:31 +00:00
|
|
|
/** Translates a string representing a hostname or dotted-decimal IPv4 address
|
|
|
|
* into a numeric IPv4 address value in network byte order. If compiled with
|
|
|
|
* c-ares, the request will wait a maximum of 250ms for the request to finish.
|
|
|
|
* Otherwise the wait time will be system-dependent, ususally much longer.
|
2009-12-24 17:21:02 +00:00
|
|
|
* Immediately returns FALSE for hostnames if network name resolution is
|
|
|
|
* disabled.
|
2009-12-24 00:58:31 +00:00
|
|
|
*
|
|
|
|
* @param[in] host The hostname.
|
|
|
|
* @param[out] addrp The numeric IPv4 address in network byte order.
|
2009-12-24 17:21:02 +00:00
|
|
|
* @return TRUE on success, FALSE on failure, timeout.
|
2009-12-24 00:58:31 +00:00
|
|
|
*/
|
Have "get_host_ipaddr()" return a Boolean indicating whether it
succeeded or failed, and, if it succeeded, have it fill in the IP
address if found through a pointer passed as the second argument.
Have it first try interpreting its first argument as a dotted-quad IP
address, with "inet_aton()", and, if that fails, have it try to
interpret it as a host name with "gethostbyname()"; don't bother with
"gethostbyaddr()", as we should be allowed to filter on IP addresses
even if there's no host name associated with them (there's no guarantee
that "gethostbyaddr()" will succeed if handed an IP address with no
corresponding name - and it looks as if FreeBSD 3.2, at least, may not
succeed in that case).
Add a "dfilter_fail()" routine that takes "printf()"-like arguments and
uses them to set an error message for the parse; doing so means that
even if the filter expression is syntactically valid, we treat it as
being invalid. (Is there a better way to force a parse to fail from
arbitrary places in routines called by the parser?)
Use that routine in the lexical analyzer.
If that error message was set, use it as is as the failure message,
rather than adding "Unable to parse filter string XXX" to it.
Have the code to handle IP addresses and host names in display filters
check whether "get_host_ipaddr()" succeeded or failed and, if it failed,
arrange that the parse fail with an error message indicating the source
of the problem.
svn path=/trunk/; revision=802
1999-10-11 03:03:12 +00:00
|
|
|
gboolean get_host_ipaddr(const char *host, guint32 *addrp);
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2009-12-24 00:58:31 +00:00
|
|
|
/** Translates a string representing a hostname or colon-hex IPv6 address
|
|
|
|
* into a numeric IPv6 address value in network byte order. If compiled with
|
|
|
|
* c-ares, the request will wait a maximum of 250ms for the request to finish.
|
|
|
|
* Otherwise the wait time will be system-dependent, usually much longer.
|
2009-12-24 17:21:02 +00:00
|
|
|
* Immediately returns FALSE for hostnames if network name resolution is
|
|
|
|
* disabled.
|
2009-12-24 00:58:31 +00:00
|
|
|
*
|
|
|
|
* @param[in] host The hostname.
|
|
|
|
* @param[out] addrp The numeric IPv6 address in network byte order.
|
|
|
|
* @return TRUE on success, FALSE on failure or timeout.
|
1999-10-15 03:11:52 +00:00
|
|
|
*/
|
|
|
|
gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp);
|
|
|
|
|
2004-06-25 07:00:54 +00:00
|
|
|
/*
|
|
|
|
* Find out whether a hostname resolves to an ip or ipv6 address
|
|
|
|
* Return "ip6" if it is IPv6, "ip" otherwise (including the case
|
|
|
|
* that we don't know)
|
|
|
|
*/
|
|
|
|
const char* host_ip_af(const char *host);
|
|
|
|
|
2007-01-18 18:43:30 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
#endif /* __RESOLV_H__ */
|