Rename some routines and structures to reflect that they're specific to
[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  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
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
27 #ifndef __RESOLV_H__
28 #define __RESOLV_H__
29
30 #ifndef MAXNAMELEN
31 #define MAXNAMELEN      64      /* max name length (hostname and port name) */
32 #endif
33
34 /*
35  * Flag controlling what names to resolve.
36  */
37 ETH_VAR_IMPORT guint32 g_resolv_flags;
38
39 /* 32 types are sufficient (as are 640k of RAM) */
40 /* FIXME: Maybe MANUF/m, IP/i, IP6/6, IPX/x, UDP+TCP/t etc would be
41    more useful/consistent */
42 #define RESOLV_NONE             0x0
43 #define RESOLV_MAC              0x1
44 #define RESOLV_NETWORK          0x2
45 #define RESOLV_TRANSPORT        0x4
46 #define RESOLV_CONCURRENT       0x8
47
48 #define RESOLV_ALL_ADDRS        (RESOLV_MAC|RESOLV_NETWORK|RESOLV_TRANSPORT)
49 #define RESOLV_ALL              0xFFFFFFFF
50
51 /* global variables */
52
53 extern gchar *g_ethers_path;
54 extern gchar *g_ipxnets_path;
55 extern gchar *g_pethers_path;
56 extern gchar *g_pipxnets_path;
57
58 /* Functions in resolv.c */
59
60 /* Set the flags controlling what names to resolve */
61 extern void resolv_set_flags(guint32 flags);
62
63 /* get_tcp_port returns the UDP port name or "%u" if not found */
64 extern gchar *get_udp_port(guint port);
65
66 /* get_tcp_port returns the TCP port name or "%u" if not found */
67 extern gchar *get_tcp_port(guint port);
68
69 /* get_sctp_port returns the SCTP port name or "%u" if not found */
70 extern gchar *get_sctp_port(guint port);
71
72 /*
73  * Asynchronous host name lookup initialization, processing, and cleanup
74  */
75
76 /* host_name_lookup_init fires up an ADNS socket if we're using ADNS */
77 extern void host_name_lookup_init(void);
78
79 /* host_name_lookup_process does ADNS processing in GTK+ timeouts in Ethereal,
80    and before processing each packet in Tethereal, if we're using ADNS */
81 extern gint host_name_lookup_process(gpointer data);
82
83 /* host_name_lookup_cleanup cleans up an ADNS socket if we're using ADNS */
84 extern void host_name_lookup_cleanup(void);
85
86 /* get_hostname returns the host name or "%d.%d.%d.%d" if not found */
87 extern gchar *get_hostname(guint addr);
88
89 /* get_hostname6 returns the host name, or numeric addr if not found */
90 struct e_in6_addr;
91 const gchar* get_hostname6(struct e_in6_addr *ad);
92
93 /* get_ether_name returns the logical name if found in ethers files else
94    "<vendor>_%02x:%02x:%02x" if the vendor code is known else
95    "%02x:%02x:%02x:%02x:%02x:%02x" */
96 extern gchar *get_ether_name(const guint8 *addr);
97
98 /* get_ether_name returns the logical name if found in ethers files else NULL */
99 extern gchar *get_ether_name_if_known(const guint8 *addr);
100
101 /* get_manuf_name returns the vendor name or "%02x:%02x:%02x" if not known */
102 extern const gchar *get_manuf_name(const guint8 *addr);
103
104 /* get_ipxnet_name returns the logical name if found in an ipxnets file,
105  * or a string formatted with "%X" if not */
106 extern const gchar *get_ipxnet_name(const guint32 addr);
107
108 /* returns the ethernet address corresponding to name or NULL if not known */
109 extern guint8 *get_ether_addr(const gchar *name);
110
111 /* returns the ipx network corresponding to name. If name is unknown,
112  * 0 is returned and 'known' is set to FALSE. On success, 'known'
113  * is set to TRUE. */
114 guint32 get_ipxnet_addr(const gchar *name, gboolean *known);
115
116 /* adds a hostname/IPv4 in the hash table */
117 extern void add_ipv4_name(guint addr, const gchar *name);
118
119 /* add ethernet address / name corresponding to IP address  */
120 extern void add_ether_byip(guint ip, const guint8 *eth);
121
122 /* Translates a string representing the hostname or dotted-decimal IP address
123  * into a numeric IP address value, returning TRUE if it succeeds and
124  * FALSE if it fails. */
125 gboolean get_host_ipaddr(const char *host, guint32 *addrp);
126
127 /*
128  * Translate IPv6 numeric address or FQDN hostname, into binary IPv6 address.
129  * Return TRUE if we succeed and set "*addrp" to that numeric IP address;
130  * return FALSE if we fail.
131  */
132 gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp);
133
134 /*
135  * Find out whether a hostname resolves to an ip or ipv6 address
136  * Return "ip6" if it is IPv6, "ip" otherwise (including the case
137  * that we don't know)
138  */
139 const char* host_ip_af(const char *host);
140
141 #endif /* __RESOLV_H__ */