Rename "register_ethereal_tap()" to "register_tap_listener_cmd_arg()" as
[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 #include <epan/address.h>
31
32 #ifndef MAXNAMELEN
33 #define MAXNAMELEN      64      /* max name length (hostname and port name) */
34 #endif
35
36 /*
37  * Flag controlling what names to resolve.
38  */
39 ETH_VAR_IMPORT guint32 g_resolv_flags;
40
41 /* 32 types are sufficient (as are 640k of RAM) */
42 /* FIXME: Maybe MANUF/m, IP/i, IP6/6, IPX/x, UDP+TCP/t etc would be
43    more useful/consistent */
44 #define RESOLV_NONE             0x0
45 #define RESOLV_MAC              0x1
46 #define RESOLV_NETWORK          0x2
47 #define RESOLV_TRANSPORT        0x4
48 #define RESOLV_CONCURRENT       0x8
49
50 #define RESOLV_ALL_ADDRS        (RESOLV_MAC|RESOLV_NETWORK|RESOLV_TRANSPORT)
51 #define RESOLV_ALL              0xFFFFFFFF
52
53 /* global variables */
54
55 extern gchar *g_ethers_path;
56 extern gchar *g_ipxnets_path;
57 extern gchar *g_pethers_path;
58 extern gchar *g_pipxnets_path;
59
60 /* Functions in resolv.c */
61
62 /* Set the flags controlling what names to resolve */
63 extern void resolv_set_flags(guint32 flags);
64
65 /*
66  * get_udp_port() returns the port name corresponding to that UDP port,
67  * or the port number as a string if not found.
68  */
69 extern gchar *get_udp_port(guint port);
70
71 /*
72  * get_tcp_port() returns the port name corresponding to that TCP port,
73  * or the port number as a string if not found.
74  */
75 extern gchar *get_tcp_port(guint port);
76
77 /*
78  * get_sctp_port() returns the port name corresponding to that SCTP port,
79  * or the port number as a string if not found.
80  */
81 extern gchar *get_sctp_port(guint port);
82
83 /* get_addr_name takes as input an "address", as defined in address.h */
84 /* it returns a string that contains: */
85 /*  - if the address is of a type that can be translated into a name, and the user */
86 /*    has activated name resolution, the translated name */
87 /*  - if the address is of type AT_NONE, a pointer to the string "NONE" */
88 /*  - if the address is of any other type, the result of address_to_str on the argument, */
89 /*    which should be a string representation for the answer -e.g. "10.10.10.10" for IPv4 */
90 /*    address 10.10.10.10 */
91 /* take into account that get_addr_name might eventually call address_to_str and return */
92 /* its result; this means that the returned pointer is only guaranteed to point to a valid */
93 /* string immediately after return, because address_to_str overwrites its previous results */
94 /* and it must not be g_free'd */
95
96 const gchar *get_addr_name(address *addr);
97
98 /* get_addr_name_buf solves an address in the same way as get_addr_name above */
99 /* The difference is that get_addr_name_buf takes as input a buffer, in which it puts */
100 /* the result, and a maximum string length -size-. the buffer should be large enough to */
101 /* contain size characters plus the terminator */
102
103 void get_addr_name_buf(address *addr, gchar *buf, guint size);
104
105
106 /*
107  * Asynchronous host name lookup initialization, processing, and cleanup
108  */
109
110 /* host_name_lookup_init fires up an ADNS socket if we're using ADNS */
111 extern void host_name_lookup_init(void);
112
113 /* host_name_lookup_process does ADNS processing in GTK+ timeouts in Ethereal,
114    and before processing each packet in Tethereal, if we're using ADNS */
115 extern gint host_name_lookup_process(gpointer data);
116
117 /* host_name_lookup_cleanup cleans up an ADNS socket if we're using ADNS */
118 extern void host_name_lookup_cleanup(void);
119
120 /* get_hostname returns the host name or "%d.%d.%d.%d" if not found */
121 extern gchar *get_hostname(guint addr);
122
123 /* get_hostname6 returns the host name, or numeric addr if not found */
124 struct e_in6_addr;
125 const gchar* get_hostname6(struct e_in6_addr *ad);
126
127 /* get_ether_name returns the logical name if found in ethers files else
128    "<vendor>_%02x:%02x:%02x" if the vendor code is known else
129    "%02x:%02x:%02x:%02x:%02x:%02x" */
130 extern gchar *get_ether_name(const guint8 *addr);
131
132 /* get_ether_name returns the logical name if found in ethers files else NULL */
133 extern gchar *get_ether_name_if_known(const guint8 *addr);
134
135 /* get_manuf_name returns the vendor name or "%02x:%02x:%02x" if not known */
136 extern const gchar *get_manuf_name(const guint8 *addr);
137
138 /* get_ipxnet_name returns the logical name if found in an ipxnets file,
139  * or a string formatted with "%X" if not */
140 extern const gchar *get_ipxnet_name(const guint32 addr);
141
142 /* returns the ethernet address corresponding to name or NULL if not known */
143 extern guint8 *get_ether_addr(const gchar *name);
144
145 /* returns the ipx network corresponding to name. If name is unknown,
146  * 0 is returned and 'known' is set to FALSE. On success, 'known'
147  * is set to TRUE. */
148 guint32 get_ipxnet_addr(const gchar *name, gboolean *known);
149
150 /* adds a hostname/IPv4 in the hash table */
151 extern void add_ipv4_name(guint addr, const gchar *name);
152
153 /* adds a hostname/IPv6 in the hash table */
154 extern void add_ipv6_name(struct e_in6_addr *addr, const gchar *name);
155
156 /* add ethernet address / name corresponding to IP address  */
157 extern void add_ether_byip(guint ip, const guint8 *eth);
158
159 /* Translates a string representing the hostname or dotted-decimal IP address
160  * into a numeric IP address value, returning TRUE if it succeeds and
161  * FALSE if it fails. */
162 gboolean get_host_ipaddr(const char *host, guint32 *addrp);
163
164 /*
165  * Translate IPv6 numeric address or FQDN hostname, into binary IPv6 address.
166  * Return TRUE if we succeed and set "*addrp" to that numeric IP address;
167  * return FALSE if we fail.
168  */
169 gboolean get_host_ipaddr6(const char *host, struct e_in6_addr *addrp);
170
171 /*
172  * Find out whether a hostname resolves to an ip or ipv6 address
173  * Return "ip6" if it is IPv6, "ip" otherwise (including the case
174  * that we don't know)
175  */
176 const char* host_ip_af(const char *host);
177
178 #endif /* __RESOLV_H__ */