X-Git-Url: http://git.samba.org/?p=metze%2Fwireshark%2Fwip.git;a=blobdiff_plain;f=wiretap%2Ffile_access.c;h=ff2200bd2d1bac180f0fd754b592d063fbdb1731;hp=0e923be196c2cb7d7d0d6776c4f6fcc0fedf42da;hb=73286c417eebe975edb24a024eb0230bbca29acc;hpb=b706fc64cace755614b63b8ed957b70eef3a4862 diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 0e923be196..ff2200bd2d 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -83,6 +83,7 @@ #include "capsa.h" #include "pcap-encap.h" #include "nettrace_3gpp_32_423.h" +#include "mplog.h" /* * Add an extension, and all compressed versions thereof, to a GSList @@ -138,6 +139,7 @@ static const struct file_extension_info file_type_extensions_base[] = { { "Tektronix K12xx 32-bit .rf5 format", "rf5" }, { "Savvius *Peek", "pkt;tpc;apc;wpz" }, { "Catapult DCT2000 trace (.out format)", "out" }, + { "Micropross mplog", "mplog" }, { "MPEG files", "mpg;mp3" }, { "TamoSoft CommView", "ncf" }, { "Symbian OS btsnoop", "log" }, @@ -305,6 +307,17 @@ wtap_get_all_file_extensions_list(void) * type to interpret it as, if the file name has no extension, the * extension isn't sufficient to determine the appropriate file type, * or the extension is wrong. + * + * NOTE: when adding file formats to this list you may also want to add them + * to the following files so that the various desktop environments will + * know that Wireshark can open the file: + * 1) wireshark-mime-package.xml (for freedesktop.org environments) + * 2) packaging/macosx/Info.plist.in (for OS X) + * 3) packaging/nsis/AdditionalTasksPage.ini, packaging/nsis/common.nsh, + * and packaging/wix/ComponentGroups.wxi (for Windows) + * + * If your file format has an expected extension (e.g., ".pcap") then you + * should probably also add it to file_type_extensions_base[] (in this file). */ static struct open_info open_info_base[] = { { "Wireshark/tcpdump/... - pcap", OPEN_INFO_MAGIC, libpcap_open, "pcap", NULL, NULL }, @@ -333,6 +346,7 @@ static struct open_info open_info_base[] = { /* Gammu DCT3 trace must come before MIME files as it's XML based*/ { "Gammu DCT3 trace", OPEN_INFO_MAGIC, dct3trace_open, NULL, NULL, NULL }, { "MIME Files Format", OPEN_INFO_MAGIC, mime_file_open, NULL, NULL, NULL }, + { "Micropross mplog", OPEN_INFO_MAGIC, mplog_open, "mplog", NULL, NULL }, { "Novell LANalyzer", OPEN_INFO_HEURISTIC, lanalyzer_open, "tr1", NULL, NULL }, /* * PacketLogger must come before MPEG, because its files @@ -385,7 +399,7 @@ static struct open_info open_info_base[] = { /* this is only used to build the dynamic array on load, do NOT use this * for anything else, because the size of the actual array will change if - * Lua scripts register a new file reader. + * Lua scripts register a new file reader. */ #define N_OPEN_INFO_ROUTINES ((sizeof open_info_base / sizeof open_info_base[0])) @@ -700,6 +714,7 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_ unsigned int i; gboolean use_stdin = FALSE; gchar *extension; + wtap_optionblock_t shb; *err = 0; *err_info = NULL; @@ -819,7 +834,10 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_ wth->file_tsprec = WTAP_TSPREC_USEC; wth->priv = NULL; wth->wslua_data = NULL; - wth->shb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION); + wth->shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t)); + shb = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION); + if (shb) + g_array_append_val(wth->shb_hdrs, shb); /* Initialize the array containing a list of interfaces. pcapng_open and * erf_open needs this (and libpcap_open for ERF encapsulation types). @@ -1583,6 +1601,11 @@ static const struct file_type_subtype_info dump_open_table_base[] = { { "3GPP TS 32.423 Trace", "3gpp32423", NULL, NULL, FALSE, FALSE, 0, NULL, NULL, NULL }, + + /* WTAP_FILE_TYPE_MPLOG */ + { "Micropross mplog file", "mplog", "mplog", NULL, + FALSE, FALSE, 0, + NULL, NULL, NULL } }; /* @@ -2080,7 +2103,7 @@ wtap_dump_can_open(int file_type_subtype) return TRUE; } -#ifdef HAVE_LIBZ +#ifdef HAVE_ZLIB gboolean wtap_dump_can_compress(int file_type_subtype) { @@ -2139,8 +2162,8 @@ static int wtap_dump_file_close(wtap_dumper *wdh); static wtap_dumper * wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean compressed, - wtap_optionblock_t shb_hdr, wtapng_iface_descriptions_t *idb_inf, - wtap_optionblock_t nrb_hdr, int *err) + GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf, + GArray* nrb_hdrs, int *err) { wtap_dumper *wdh; wtap_optionblock_t descr, file_int_data; @@ -2157,9 +2180,9 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co return NULL; /* couldn't allocate it */ /* Set Section Header Block data */ - wdh->shb_hdr = shb_hdr; + wdh->shb_hdrs = shb_hdrs; /* Set Name Resolution Block data */ - wdh->nrb_hdr = nrb_hdr; + wdh->nrb_hdrs = nrb_hdrs; /* Set Interface Description Block data */ if ((idb_inf != NULL) && (idb_inf->interface_data->len > 0)) { guint itf_count; @@ -2185,7 +2208,8 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co descr_mand->time_units_per_second = 1000000; /* default microsecond resolution */ descr_mand->link_type = wtap_wtap_encap_to_pcap_encap(encap); descr_mand->snap_len = snaplen; - wtap_optionblock_set_option_string(descr, OPT_IDB_NAME, "Unknown/not available in original file format(libpcap)"); + wtap_optionblock_set_option_string(descr, OPT_IDB_NAME, "Unknown/not available in original file format(libpcap)", + strlen("Unknown/not available in original file format(libpcap)")); descr_mand->num_stat_entries = 0; /* Number of ISB:s */ descr_mand->interface_statistics = NULL; @@ -2204,15 +2228,15 @@ wtap_dump_open(const char *filename, int file_type_subtype, int encap, wtap_dumper * wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap, - int snaplen, gboolean compressed, wtap_optionblock_t shb_hdr, wtapng_iface_descriptions_t *idb_inf, - wtap_optionblock_t nrb_hdr, int *err) + int snaplen, gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf, + GArray* nrb_hdrs, int *err) { wtap_dumper *wdh; WFILE_T fh; /* Allocate and initialize a data structure for the output stream. */ wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed, - shb_hdr, idb_inf, nrb_hdr, err); + shb_hdrs, idb_inf, nrb_hdrs, err); if (wdh == NULL) return NULL; @@ -2250,9 +2274,9 @@ wtap_dumper * wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx, int file_type_subtype, int encap, int snaplen, gboolean compressed, - wtap_optionblock_t shb_hdr, + GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf, - wtap_optionblock_t nrb_hdr, int *err) + GArray* nrb_hdrs, int *err) { int fd; char *tmpname; @@ -2264,12 +2288,12 @@ wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx, /* Allocate and initialize a data structure for the output stream. */ wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed, - shb_hdr, idb_inf, nrb_hdr, err); + shb_hdrs, idb_inf, nrb_hdrs, err); if (wdh == NULL) return NULL; /* Choose a random name for the file */ - fd = create_tempfile(&tmpname, pfx); + fd = create_tempfile(&tmpname, pfx, ".pcapng"); if (fd == -1) { *err = errno; g_free(wdh); @@ -2283,7 +2307,7 @@ wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx, fh = wtap_dump_file_fdopen(wdh, fd); if (fh == NULL) { *err = errno; - close(fd); + ws_close(fd); g_free(wdh); return NULL; /* can't create file */ } @@ -2309,15 +2333,15 @@ wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen, wtap_dumper * wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen, - gboolean compressed, wtap_optionblock_t shb_hdr, wtapng_iface_descriptions_t *idb_inf, - wtap_optionblock_t nrb_hdr, int *err) + gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf, + GArray* nrb_hdrs, int *err) { wtap_dumper *wdh; WFILE_T fh; /* Allocate and initialize a data structure for the output stream. */ wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed, - shb_hdr, idb_inf, nrb_hdr, err); + shb_hdrs, idb_inf, nrb_hdrs, err); if (wdh == NULL) return NULL; @@ -2349,16 +2373,16 @@ wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen, wtap_dumper * wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snaplen, - gboolean compressed, wtap_optionblock_t shb_hdr, + gboolean compressed, GArray* shb_hdrs, wtapng_iface_descriptions_t *idb_inf, - wtap_optionblock_t nrb_hdr, int *err) + GArray* nrb_hdrs, int *err) { wtap_dumper *wdh; WFILE_T fh; /* Allocate and initialize a data structure for the output stream. */ wdh = wtap_dump_init_dumper(file_type_subtype, encap, snaplen, compressed, - shb_hdr, idb_inf, nrb_hdr, err); + shb_hdrs, idb_inf, nrb_hdrs, err); if (wdh == NULL) return NULL; @@ -2461,7 +2485,7 @@ wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, gboolean compress if(compressed) { cant_seek = TRUE; } else { - fd = fileno((FILE *)wdh->fh); + fd = ws_fileno((FILE *)wdh->fh); if (ws_lseek64(fd, 1, SEEK_CUR) == (off_t) -1) cant_seek = TRUE; else { @@ -2503,7 +2527,7 @@ wtap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, void wtap_dump_flush(wtap_dumper *wdh) { -#ifdef HAVE_LIBZ +#ifdef HAVE_ZLIB if(wdh->compressed) { gzwfile_flush((GZWFILE_T)wdh->fh); } else @@ -2563,7 +2587,7 @@ wtap_dump_set_addrinfo_list(wtap_dumper *wdh, addrinfo_lists_t *addrinfo_lists) } /* internally open a file for writing (compressed or not) */ -#ifdef HAVE_LIBZ +#ifdef HAVE_ZLIB static WFILE_T wtap_dump_file_open(wtap_dumper *wdh, const char *filename) { @@ -2582,7 +2606,7 @@ wtap_dump_file_open(wtap_dumper *wdh _U_, const char *filename) #endif /* internally open a file for writing (compressed or not) */ -#ifdef HAVE_LIBZ +#ifdef HAVE_ZLIB static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh, int fd) { @@ -2606,7 +2630,7 @@ wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize, int *err { size_t nwritten; -#ifdef HAVE_LIBZ +#ifdef HAVE_ZLIB if (wdh->compressed) { nwritten = gzwfile_write((GZWFILE_T)wdh->fh, buf, (unsigned int) bufsize); /* @@ -2640,7 +2664,7 @@ wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize, int *err static int wtap_dump_file_close(wtap_dumper *wdh) { -#ifdef HAVE_LIBZ +#ifdef HAVE_ZLIB if(wdh->compressed) { /* * Tell gzwfile_close() whether to close the descriptor @@ -2664,7 +2688,7 @@ wtap_dump_file_close(wtap_dumper *wdh) gint64 wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err) { -#ifdef HAVE_LIBZ +#ifdef HAVE_ZLIB if(wdh->compressed) { *err = WTAP_ERR_CANT_SEEK_COMPRESSED; return -1; @@ -2685,7 +2709,7 @@ gint64 wtap_dump_file_tell(wtap_dumper *wdh, int *err) { gint64 rval; -#ifdef HAVE_LIBZ +#ifdef HAVE_ZLIB if(wdh->compressed) { *err = WTAP_ERR_CANT_SEEK_COMPRESSED; return -1;