5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/prefs.h>
34 #include <epan/prefs-int.h>
35 #include <epan/filesystem.h>
37 #include "simple_dialog.h"
38 #include "version_info.h"
41 #include "capture-pcap-util.h"
44 #include "file_util.h"
50 /* update information about a single component */
51 typedef struct update_info_s {
52 char *prefix; /* prefix of the update file keys */
53 gboolean needs_update; /* does this component need an update */
54 char *version_installed; /* the version currently installed */
56 char *title; /* the component title (name) */
57 char *description; /* description of the component */
58 char *version_recommended; /* the version recommended */
59 char *url; /* the URL for an update */
60 char *md5; /* md5 checksum for that update */
61 char *size; /* size of that update */
65 /* download a complete file from the internet */
67 download_file(const char *url, const char *filename) {
76 /* open output file */
77 fd = eth_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
79 g_warning("Couldn't open output file %s!", filename);
84 conn = netio_ie5_connect (url);
86 g_warning("Couldn't connect to %s!", url);
91 /* XXX - maybe add a progress bar here */
93 /* read some bytes from the url */
94 chunk_len = netio_ie5_read (conn, buf, sizeof(buf));
96 /* write bytes to the output file */
97 stream_len = eth_write( fd, buf, chunk_len);
98 if(stream_len != chunk_len) {
99 g_warning("output failed: stream_len %u != chunk_len %u", stream_len, chunk_len);
103 } while(chunk_len > 0);
105 netio_ie5_disconnect(conn);
113 update_info_new(void)
115 return g_malloc0(sizeof(update_info_t));
119 update_info_delete(update_info_t *update_info)
121 if(update_info->prefix)
122 g_free(update_info->prefix);
123 if(update_info->version_installed)
124 g_free(update_info->version_installed);
126 if(update_info->title)
127 g_free(update_info->title);
128 if(update_info->description)
129 g_free(update_info->description);
130 if(update_info->version_recommended)
131 g_free(update_info->version_recommended);
133 g_free(update_info->url);
135 g_free(update_info->md5);
136 if(update_info->size)
137 g_free(update_info->size);
142 /* check a single key value pair */
144 update_pref_check(gchar *pref_name, gchar *value, char *check_prefix, char *check_name, char **check_value)
146 GString *check = g_string_new(check_prefix);
148 g_string_append(check, check_name);
150 if(strcmp(pref_name, check->str) == 0) {
152 /* there shouldn't be a duplicate entry in the update file */
153 g_warning("Duplicate of %s: current %s former %s", pref_name, value, *check_value);
155 *check_value = g_strdup(value);
158 g_string_free(check, TRUE);
161 /* a new key value pair from the update file */
162 static prefs_set_pref_e
163 update_pref(gchar *pref_name, gchar *value, void *private_data)
165 update_info_t *update_info = private_data;
167 update_pref_check(pref_name, value, update_info->prefix, "title", &update_info->title);
168 update_pref_check(pref_name, value, update_info->prefix, "description", &update_info->description);
169 update_pref_check(pref_name, value, update_info->prefix, "version", &update_info->version_recommended);
170 update_pref_check(pref_name, value, update_info->prefix, "update.url", &update_info->url);
171 update_pref_check(pref_name, value, update_info->prefix, "update.md5", &update_info->md5);
172 update_pref_check(pref_name, value, update_info->prefix, "update.size", &update_info->size);
177 /* display an update_info */
179 update_info_display(update_info_t *update_info)
184 overview = g_string_new("");
186 if(update_info->title) {
187 g_string_append_printf(overview, "%s%s%s",
188 simple_dialog_primary_start(), update_info->title, simple_dialog_primary_end());
190 g_string_append_printf(overview, "%sComponent%s",
191 simple_dialog_primary_start(), simple_dialog_primary_end());
194 g_string_append(overview, "\n\n");
196 if(update_info->description)
197 g_string_append_printf(overview, "%s\n\n", update_info->description);
199 g_string_append_printf(overview, "Installed: %s\n", update_info->version_installed);
201 if(update_info->version_recommended)
202 g_string_append_printf(overview, "Recommended: %s\n", update_info->version_recommended);
204 g_string_append(overview, "Recommenced: unknown\n");
206 if(update_info->version_recommended && update_info->url)
207 g_string_append_printf(overview, "From: %s\n", update_info->url);
209 if(update_info->size)
210 g_string_append_printf(overview, "Size: %s", update_info->size);
212 simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, overview->str);
214 g_string_free(overview, TRUE);
218 /* check the version of the wireshark program */
219 static update_info_t *
220 update_check_wireshark(const char *local_file)
223 update_info_t *update_info = update_info_new();
226 update_info->version_installed = g_strdup(VERSION);
227 update_info->prefix = "wireshark.setup.";
229 pf = eth_fopen(local_file, "r");
231 /* read in update_info of Wireshark */
232 read_prefs_file(local_file, pf, update_pref, update_info);
235 /* check if Wireshark needs an update */
236 if(update_info->version_installed && update_info->version_recommended &&
237 strcmp(update_info->version_installed, update_info->version_recommended) != 0)
239 update_info->needs_update = TRUE;
242 g_warning("Could not open %s", local_file);
248 /* check the version of winpcap */
249 static update_info_t *
250 update_check_winpcap(const char *local_file)
253 update_info_t * update_info = update_info_new();
254 GString *pcap_version_tmp;
255 char *pcap_version = NULL;
260 update_info->prefix = "winpcap.";
262 pf = eth_fopen(local_file, "r");
264 /* read in update_info of WinPcap */
265 read_prefs_file(local_file, pf, update_pref, update_info);
268 /* get WinPcap version */
269 /* XXX - what's the "approved" method to get the WinPcap version? */
270 pcap_version_tmp = g_string_new("");
271 get_runtime_pcap_version(pcap_version_tmp);
273 /* cut out real version from "combined" version string */
274 pcap_vstart = strstr(pcap_version_tmp->str, "with WinPcap version ");
275 if(pcap_vstart != NULL) {
276 pcap_vstart += sizeof("with WinPcap version");
277 pcap_vend = strstr(pcap_vstart, " ");
278 if(pcap_vend != NULL) {
280 pcap_version = g_strdup(pcap_vstart);
284 update_info->version_installed = g_strdup(pcap_version);
286 if(pcap_version && update_info->version_recommended &&
287 strcmp(pcap_version, update_info->version_recommended) != 0)
289 update_info->needs_update = TRUE;
292 g_warning("Could not open %s", local_file);
295 g_string_free(pcap_version_tmp, TRUE);
297 g_free(pcap_version);
303 /* check for all updates */
305 update_check(gboolean interactive)
308 const char *url_file = "http://127.0.0.1/wsupdate"; /* XXX - build the URL depending on platform, versions, ... */
309 update_info_t *update_info_wireshark;
310 update_info_t *update_info_winpcap;
313 /* build update file name */
314 /* XXX - using the personal path, use temp dir instead? */
315 local_file = get_persconffile_path("wsupdate", FALSE, TRUE /*for_writing*/);
316 if(local_file == NULL) {
317 g_warning("Couldn't create output path!");
321 /* download update file */
322 if(download_file(url_file, local_file) == -1) {
323 g_warning("Couldn't download update file: %s", local_file);
328 /* check wireshark */
329 update_info_wireshark = update_check_wireshark(local_file);
332 update_info_winpcap = update_check_winpcap(local_file);
334 /* display results */
335 if(update_info_wireshark->needs_update || update_info_winpcap->needs_update) {
336 if(update_info_wireshark->needs_update)
337 update_info_display(update_info_wireshark);
338 if(update_info_winpcap->needs_update)
339 update_info_display(update_info_winpcap);
342 simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "No updates available");
347 update_info_delete(update_info_wireshark);
348 update_info_delete(update_info_winpcap);