add parameter dcerpc_info to PIDL_dissect_ipv?address()
[wireshark-wip.git] / ui / gtk / addr_resolution_dlg.c
blobe87e19cdbf82d79e71d21c83dab7f8acc485ec57
1 /* addr_resolution_dlg.c
2 * Show current address resolution as a hosts file
4 * Copyright 2012 Anders Broman <anders.broman@ericsson.com>
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "config.h"
29 #include <string.h>
31 #include <gtk/gtk.h>
33 #include <epan/epan.h>
34 #include <epan/filesystem.h>
35 #include <epan/addr_resolv.h>
37 #include "../cfile.h"
38 #include "../file.h"
40 #include "ui/main_statusbar.h"
42 #include "ui/gtk/dlg_utils.h"
43 #include "ui/gtk/expert_comp_dlg.h"
44 #include "ui/gtk/font_utils.h"
45 #include "ui/gtk/gui_utils.h"
46 #include "ui/gtk/help_dlg.h"
47 #include "ui/gtk/main.h"
48 #include "ui/gtk/packet_list.h"
49 #include "ui/gtk/addr_resolution_dlg.h"
50 #include "ui/gtk/old-gtk-compat.h"
52 static GtkWidget *addr_resolution_dlg_w = NULL;
55 #define HOSTNAME_POS 48
56 #define ADDRSTRLEN 46 /* Covers IPv4 & IPv6 */
57 #define ADDRESS_STR_MAX 1024
59 static void
60 eth_hash_to_texbuff(gpointer key, gpointer value, gpointer user_data)
62 gchar string_buff[ADDRESS_STR_MAX];
63 GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
64 gint64 eth_as_gint64 = *(gint64*)key;
65 hashether_t* tp = (hashether_t*)value;
67 g_snprintf(string_buff, ADDRESS_STR_MAX, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X Status: %u %s %s\n",
68 (guint8)(eth_as_gint64>>40&0xff),
69 (guint8)(eth_as_gint64>>32&0xff),
70 (guint8)((eth_as_gint64>>24)&0xff),
71 (guint8)((eth_as_gint64>>16)&0xff),
72 (guint8)((eth_as_gint64>>8)&0xff),
73 (guint8)(eth_as_gint64&0xff),
74 tp->status,
75 tp->hexaddr,
76 tp->resolved_name);
77 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
80 static void
81 manuf_hash_to_texbuff(gpointer key, gpointer value, gpointer user_data)
83 gchar string_buff[ADDRESS_STR_MAX];
84 GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
85 gchar *name = (gchar *)value;
86 int eth_as_gint = *(int*)key;
88 g_snprintf(string_buff, ADDRESS_STR_MAX, "%.2X:%.2X:%.2X %s\n",eth_as_gint>>16, (eth_as_gint>>8)&0xff, eth_as_gint&0xff,name);
89 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
93 static void
94 wka_hash_to_texbuff(gpointer key, gpointer value, gpointer user_data)
96 gchar string_buff[ADDRESS_STR_MAX];
97 GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
98 gchar *name = (gchar *)value;
99 gint64 eth_as_gint64 = *(gint64*)key;
101 g_snprintf(string_buff, ADDRESS_STR_MAX, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X %s\n",
102 (guint8)(eth_as_gint64>>40&0xff),
103 (guint8)(eth_as_gint64>>32&0xff),
104 (guint8)((eth_as_gint64>>24)&0xff),
105 (guint8)((eth_as_gint64>>16)&0xff),
106 (guint8)((eth_as_gint64>>8)&0xff),
107 (guint8)(eth_as_gint64&0xff),
108 name);
109 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
113 static void
114 serv_port_hash_to_texbuff(gpointer key, gpointer value, gpointer user_data)
116 gchar string_buff[ADDRESS_STR_MAX];
117 GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
118 serv_port_t *serv_port_table = (serv_port_t *)value;
119 int port = *(int*)key;
121 g_snprintf(string_buff, ADDRESS_STR_MAX, "Port %u \n"" TCP %s\n"" UDP %s\n"" SCTP %s\n"" DCCP %s\n",
122 port,
123 serv_port_table->tcp_name,
124 serv_port_table->udp_name,
125 serv_port_table->sctp_name,
126 serv_port_table->dccp_name);
128 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
132 static void
133 ipv4_hash_table_to_texbuff(gpointer key, gpointer value, gpointer user_data)
135 gchar string_buff[ADDRESS_STR_MAX];
136 GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
137 hashipv4_t *ipv4_hash_table_entry = (hashipv4_t *)value;
138 int addr = *(int*)key;
140 g_snprintf(string_buff, ADDRESS_STR_MAX, "Key:0x%x IP: %s, Name: %s\n",
141 addr,
142 ipv4_hash_table_entry->ip,
143 ipv4_hash_table_entry->name);
145 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
149 static void
150 ipv4_hash_table_resolved_to_texbuff(gpointer key _U_, gpointer value, gpointer user_data)
152 gchar string_buff[ADDRESS_STR_MAX];
153 GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
154 hashipv4_t *ipv4_hash_table_entry = (hashipv4_t *)value;
156 if((ipv4_hash_table_entry->flags & DUMMY_ADDRESS_ENTRY)== 0){
157 g_snprintf(string_buff, ADDRESS_STR_MAX, "%s\t%s\n",
158 ipv4_hash_table_entry->ip,
159 ipv4_hash_table_entry->name);
161 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
168 static void
169 ipv6_hash_table_to_texbuff(gpointer key _U_, gpointer value, gpointer user_data)
171 gchar string_buff[ADDRESS_STR_MAX];
172 GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
173 hashipv6_t *ipv6_hash_table_entry = (hashipv6_t *)value;
175 g_snprintf(string_buff, ADDRESS_STR_MAX, "IP: %s, Name: %s\n",
176 ipv6_hash_table_entry->ip6,
177 ipv6_hash_table_entry->name);
179 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
183 static void
184 ipv6_hash_table_resolved_to_texbuff(gpointer key _U_, gpointer value, gpointer user_data)
186 gchar string_buff[ADDRESS_STR_MAX];
187 GtkTextBuffer *buffer = (GtkTextBuffer*)user_data;
188 hashipv6_t *ipv6_hash_table_entry = (hashipv6_t *)value;
190 if((ipv6_hash_table_entry->flags & DUMMY_ADDRESS_ENTRY)== 0){
191 g_snprintf(string_buff, ADDRESS_STR_MAX, "%s\t%s\n",
192 ipv6_hash_table_entry->ip6,
193 ipv6_hash_table_entry->name);
195 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
200 static void
201 addres_resolution_to_texbuff(GtkTextBuffer *buffer)
203 gchar string_buff[ADDRESS_STR_MAX];
204 GHashTable *manuf_hashtable;
205 GHashTable *wka_hashtable;
206 GHashTable *eth_hashtable;
207 GHashTable *serv_port_hashtable;
208 GHashTable *ipv4_hash_table;
209 GHashTable *ipv6_hash_table;
211 g_snprintf(string_buff, ADDRESS_STR_MAX, "# Hosts information in Wireshark \n#\n");
212 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
213 g_snprintf(string_buff, ADDRESS_STR_MAX, "# Host data gathered from %s\n\n", cfile.filename);
214 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
216 /* Dump the v4 addresses first, then v6 */
217 ipv4_hash_table = get_ipv4_hash_table();
218 if(ipv4_hash_table){
219 g_hash_table_foreach( ipv4_hash_table, ipv4_hash_table_resolved_to_texbuff, buffer);
222 ipv6_hash_table = get_ipv6_hash_table();
223 if(ipv6_hash_table){
224 g_hash_table_foreach( ipv6_hash_table, ipv6_hash_table_resolved_to_texbuff, buffer);
227 g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Address resolution IPv4 Hash table \n#\n");
228 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
230 if(ipv4_hash_table){
231 g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(ipv4_hash_table));
232 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
233 g_hash_table_foreach( ipv4_hash_table, ipv4_hash_table_to_texbuff, buffer);
236 g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Address resolution IPv6 Hash table \n#\n");
237 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
239 if(ipv6_hash_table){
240 g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(ipv6_hash_table));
241 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
242 g_hash_table_foreach( ipv6_hash_table, ipv6_hash_table_to_texbuff, buffer);
246 g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Port names information in Wireshark \n#\n");
247 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
249 serv_port_hashtable = get_serv_port_hashtable();
250 if(serv_port_hashtable){
251 g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(serv_port_hashtable));
252 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
253 g_hash_table_foreach( serv_port_hashtable, serv_port_hash_to_texbuff, buffer);
256 g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Eth names information in Wireshark \n#\n");
257 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
259 eth_hashtable = get_eth_hashtable();
260 if(eth_hashtable){
261 g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(eth_hashtable));
262 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
263 g_hash_table_foreach( eth_hashtable, eth_hash_to_texbuff, buffer);
266 g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# Manuf information in Wireshark \n#\n");
267 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
269 manuf_hashtable = get_manuf_hashtable();
270 if(manuf_hashtable){
271 g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(manuf_hashtable));
272 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
273 g_hash_table_foreach( manuf_hashtable, manuf_hash_to_texbuff, buffer);
276 g_snprintf(string_buff, ADDRESS_STR_MAX, "\n\n# wka information in Wireshark \n#\n");
277 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
279 wka_hashtable = get_wka_hashtable();
280 if(wka_hashtable){
281 g_snprintf(string_buff, ADDRESS_STR_MAX, "# With %i entries\n#\n", g_hash_table_size(wka_hashtable));
282 gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1);
283 g_hash_table_foreach( wka_hashtable, wka_hash_to_texbuff, buffer);
289 void
290 addr_resolution_dlg (GtkAction *action _U_, gpointer data _U_)
293 GtkWidget *vbox;
294 GtkWidget *view;
295 GtkWidget *scroll;
296 GtkWidget *bbox;
297 GtkWidget *ok_bt, *cancel_bt, *help_bt;
298 GtkTextBuffer *buffer;
300 addr_resolution_dlg_w = dlg_window_new ("Address Resolution");
301 gtk_widget_set_size_request (addr_resolution_dlg_w, 750, 350);
302 gtk_window_set_resizable (GTK_WINDOW (addr_resolution_dlg_w), TRUE);
303 gtk_container_set_border_width (GTK_CONTAINER (addr_resolution_dlg_w), DLG_OUTER_MARGIN);
305 vbox = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, DLG_UNRELATED_SPACING, FALSE);
306 gtk_container_add (GTK_CONTAINER (addr_resolution_dlg_w), vbox);
307 gtk_widget_show (vbox);
309 view = gtk_text_view_new ();
310 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
311 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
312 #if GTK_CHECK_VERSION(3, 0, 0)
313 gtk_widget_override_font(view, user_font_get_regular());
314 #else
315 gtk_widget_modify_font(view, user_font_get_regular());
316 #endif
317 gtk_widget_show (view);
319 scroll = gtk_scrolled_window_new(NULL, NULL);
320 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
321 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
322 gtk_container_add(GTK_CONTAINER(scroll), view);
323 gtk_widget_show(scroll);
324 gtk_box_pack_start(GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
326 /* Get the address list */
327 addres_resolution_to_texbuff(buffer);
329 /* Button row. */
330 bbox = dlg_button_row_new (GTK_STOCK_OK, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
331 gtk_box_pack_end (GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
333 ok_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_OK);
334 /*g_signal_connect (ok_bt, "clicked", G_CALLBACK(pkt_comment_text_buff_ok_cb), view);*/
335 gtk_widget_set_sensitive (ok_bt, TRUE);
337 cancel_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_CANCEL);
338 window_set_cancel_button (addr_resolution_dlg_w, cancel_bt, window_cancel_button_cb);
340 help_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_HELP);
341 #if 0
342 g_signal_connect (help_bt, "clicked",/* G_CALLBACK(topic_cb)*/NULL, /*(gpointer)HELP_MANUAL_ADDR_RESOLVE_DIALOG*/NULL);
343 #endif
344 gtk_widget_set_sensitive (help_bt, FALSE);
346 gtk_widget_grab_default (ok_bt);
347 /*g_signal_connect (addr_resolution_dlg_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);*/
350 gtk_widget_show (addr_resolution_dlg_w);
354 * Editor modelines
356 * Local Variables:
357 * c-basic-offset: 4
358 * tab-width: 8
359 * indent-tabs-mode: nil
360 * End:
362 * ex: set shiftwidth=4 tabstop=8 expandtab:
363 * :indentSize=4:tabSize=8:noTabs=true: