wiretap: fix memory leak of interface_data for wtap_dumper
[metze/wireshark/wip.git] / wiretap / wtap.h
index 3e1010194754052cdebcbd8e76542f6e6e4b2a91..63787292bae5b092d16a0b89667aea0ae3492d53 100644 (file)
@@ -268,6 +268,7 @@ extern "C" {
 #define WTAP_ENCAP_GFP_T                        178
 #define WTAP_ENCAP_GFP_F                        179
 #define WTAP_ENCAP_IP_OVER_IB_PCAP              180
+#define WTAP_ENCAP_JUNIPER_VN                   181
 /* After adding new item here, please also add new item to encap_table_base array */
 
 #define WTAP_NUM_ENCAP_TYPES                    wtap_get_num_encap_types()
@@ -357,6 +358,7 @@ extern "C" {
 #define WTAP_FILE_TYPE_SUBTYPE_JSON                          77
 #define WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_5                 78
 #define WTAP_FILE_TYPE_SUBTYPE_NETTRACE_3GPP_32_423          79
+#define WTAP_FILE_TYPE_SUBTYPE_MPLOG                         80
 
 #define WTAP_NUM_FILE_TYPES_SUBTYPES  wtap_get_num_file_types_subtypes()
 
@@ -1202,6 +1204,7 @@ union wtap_pseudo_header {
 #define REC_TYPE_PACKET               0    /**< packet */
 #define REC_TYPE_FT_SPECIFIC_EVENT    1    /**< file-type-specific event */
 #define REC_TYPE_FT_SPECIFIC_REPORT   2    /**< file-type-specific report */
+#define REC_TYPE_SYSCALL              3    /**< system call */
 
 struct wtap_pkthdr {
     guint     rec_type;         /* what type of record is this? */
@@ -1265,7 +1268,7 @@ typedef struct wtapng_section_mandatory_s {
 } wtapng_mandatory_section_t;
 
 /** struct holding the information to build IDB:s
- *  the interface_data array holds an array of wtap_optionblock_t
+ *  the interface_data array holds an array of wtap_block_t
  *  represending IDB of one per interface.
  */
 typedef struct wtapng_iface_descriptions_s {
@@ -1294,7 +1297,7 @@ typedef struct wtapng_if_descr_filter_s {
                                                    *  libpcap string.
                                                    */
     guint16                bpf_filter_len;        /** variant II BPF filter len 0 if not used*/
-    gchar                 *if_filter_bpf_bytes;   /** BPF filter or NULL */
+    guint8                *if_filter_bpf_bytes;   /** BPF filter or NULL */
 } wtapng_if_descr_filter_t;
 
 /**
@@ -1320,7 +1323,7 @@ typedef struct hashipv4 {
 typedef struct hashipv6 {
     guint8            addr[16];
     guint8            flags;          /* B0 dummy_entry, B1 resolve, B2 If the address is used in the trace */
-    gchar             ip6[40];
+    gchar             ip6[46];
     gchar             name[MAXNAMELEN];
 } hashipv6_t;
 
@@ -1356,23 +1359,29 @@ typedef struct wtap_wslua_file_info {
 } wtap_wslua_file_info_t;
 
 /*
- * For registering extensions used for capture file formats.
+ * For registering extensions used for file formats.
  *
  * These items are used in dialogs for opening files, so that
  * the user can ask to see all capture files (as identified
  * by file extension) or particular types of capture files.
  *
- * Each file type has a description and a list of extensions the file
- * might have.  Some file types aren't real file types, they're
- * just generic types, such as "text file" or "XML file", that can
- * be used for, among other things, captures we can read, or for
- * extensions such as ".cap" that were unimaginatively chosen by
- * several different sniffers for their file formats.
+ * Each file type has a description, a flag indicating whether it's
+ * a capture file or just some file whose contents we can dissect,
+ * and a list of extensions the file might have.
+ *
+ * Some file types aren't real file types, they're just generic types,
+ * such as "text file" or "XML file", that can be used for, among other
+ * things, captures we can read, or for extensions such as ".cap" that
+ * were unimaginatively chosen by several different sniffers for their
+ * file formats.
  */
 struct file_extension_info {
     /* the file type name */
     const char *name;
 
+    /* TRUE if this is a capture file type */
+    gboolean is_capture_file;
+
     /* a semicolon-separated list of file extensions used for this type */
     const char *extensions;
 };
@@ -1589,13 +1598,15 @@ int wtap_file_tsprec(wtap *wth);
  *
  * @param wth The wiretap session.
  * @return The existing section header, which must NOT be g_free'd.
+ *
+ * XXX - need to be updated to handle multiple SHBs.
  */
 WS_DLL_PUBLIC
-wtap_optionblock_t wtap_file_get_shb(wtap *wth);
+wtap_block_t wtap_file_get_shb(wtap *wth);
 
 /**
  * @brief Gets new section header block for new file, based on existing info.
- * @details Creates a new wtap_optionblock_t section header block and only
+ * @details Creates a new wtap_block_t section header block and only
  *          copies appropriate members of the SHB for a new file. In
  *          particular, the comment string is copied, and any custom options
  *          which should be copied are copied. The os, hardware, and
@@ -1607,17 +1618,7 @@ wtap_optionblock_t wtap_file_get_shb(wtap *wth);
  * @return The new section header, which must be wtap_free_shb'd.
  */
 WS_DLL_PUBLIC
-wtap_optionblock_t wtap_file_get_shb_for_new_file(wtap *wth);
-
-/**
- * @brief Gets the section header comment string.
- * @details This gets the pointer, without duplicating the string.
- *
- * @param wth The wtap session.
- * @return The comment string.
- */
-WS_DLL_PUBLIC
-const gchar* wtap_file_get_shb_comment(wtap *wth);
+GArray* wtap_file_get_shb_for_new_file(wtap *wth);
 
 /**
  * @brief Sets or replaces the section header comment.
@@ -1672,46 +1673,37 @@ void wtap_free_idb_info(wtapng_iface_descriptions_t *idb_info);
  * @return A newly allocated gcahr array string, which must be g_free'd.
  */
 WS_DLL_PUBLIC
-gchar *wtap_get_debug_if_descr(const wtap_optionblock_t if_descr,
+gchar *wtap_get_debug_if_descr(const wtap_block_t if_descr,
                                const int indent,
                                const char* line_end);
 
 /**
- * @brief Gets new name resolution info for new file, based on existing info.
- * @details Creates a new wtap_optionblock_t of name resolution info and only
- *          copies appropriate members for a new file.
- *
- * @note Use wtap_free_nrb() to free the returned pointer.
+ * @brief Gets existing name resolution block, not for new file.
+ * @details Returns the pointer to the existing NRB, without creating a
+ *          new one. This should only be used for accessing info, not
+ *          for creating a new file based on existing NRB info. Use
+ *          wtap_file_get_nrb_for_new_file() for that.
  *
  * @param wth The wiretap session.
- * @return The new name resolution info, which must be wtap_optionblock_free'd.
- */
-WS_DLL_PUBLIC
-wtap_optionblock_t wtap_file_get_nrb_for_new_file(wtap *wth);
-
-/**
- * @brief Gets the name resolution comment, if any.
- * @details This retrieves the name resolution comment string pointer,
- *          possibly NULL.
+ * @return The existing section header, which must NOT be g_free'd.
  *
- * @param wth The wiretap session.
- * @return The comment string.
+ * XXX - need to be updated to handle multiple NRBs.
  */
 WS_DLL_PUBLIC
-const gchar* wtap_get_nrb_comment(wtap *wth);
+wtap_block_t wtap_file_get_nrb(wtap *wth);
 
 /**
- * @brief Sets or replaces the name resolution comment.
- * @details The passed-in comment string is set to be the comment
- *          for the name resolution block. The passed-in string's
- *          ownership will be owned by the block, so it should be
- *          duplicated before passing into this function.
+ * @brief Gets new name resolution info for new file, based on existing info.
+ * @details Creates a new wtap_block_t of name resolution info and only
+ *          copies appropriate members for a new file.
+ *
+ * @note Use wtap_free_nrb() to free the returned pointer.
  *
  * @param wth The wiretap session.
- * @param comment The comment string.
+ * @return The new name resolution info, which must be freed.
  */
 WS_DLL_PUBLIC
-void wtap_write_nrb_comment(wtap *wth, gchar *comment);
+GArray* wtap_file_get_nrb_for_new_file(wtap *wth);
 
 /*** close the file descriptors for the current file ***/
 WS_DLL_PUBLIC
@@ -1721,9 +1713,11 @@ void wtap_fdclose(wtap *wth);
 WS_DLL_PUBLIC
 gboolean wtap_fdreopen(wtap *wth, const char *filename, int *err);
 
-/*** close the current file ***/
+/** Close only the sequential side, freeing up memory it uses. */
 WS_DLL_PUBLIC
 void wtap_sequential_close(wtap *wth);
+
+/** Closes any open file handles and frees the memory associated with wth. */
 WS_DLL_PUBLIC
 void wtap_close(wtap *wth);
 
@@ -1775,16 +1769,16 @@ wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int enc
  * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
  * @param snaplen The maximum packet capture length.
  * @param compressed True if file should be compressed.
- * @param shb_hdr The section header block information, or NULL.
+ * @param shb_hdrs The section header block(s) information, or NULL.
  * @param idb_inf The interface description information, or NULL.
- * @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
+ * @param nrb_hdrs The name resolution blocks(s) comment/custom_opts information, or NULL.
  * @param[out] err Will be set to an error code on failure.
  * @return The newly created dumper object, or NULL on failure.
  */
 WS_DLL_PUBLIC
 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);
 
 WS_DLL_PUBLIC
 wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
@@ -1805,17 +1799,17 @@ wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
  * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
  * @param snaplen The maximum packet capture length.
  * @param compressed True if file should be compressed.
- * @param shb_hdr The section header block information, or NULL.
+ * @param shb_hdrs The section header block(s) information, or NULL.
  * @param idb_inf The interface description information, or NULL.
- * @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
+ * @param nrb_hdrs The name resolution blocks(s) comment/custom_opts information, or NULL.
  * @param[out] err Will be set to an error code on failure.
  * @return The newly created dumper object, or NULL on failure.
  */
 WS_DLL_PUBLIC
 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, 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);
 
 WS_DLL_PUBLIC
 wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen,
@@ -1833,16 +1827,16 @@ wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snap
  * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
  * @param snaplen The maximum packet capture length.
  * @param compressed True if file should be compressed.
- * @param shb_hdr The section header block information, or NULL.
+ * @param shb_hdrs The section header block(s) information, or NULL.
  * @param idb_inf The interface description information, or NULL.
- * @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
+ * @param nrb_hdrs The name resolution blocks(s) comment/custom_opts information, or NULL.
  * @param[out] err Will be set to an error code on failure.
  * @return The newly created dumper object, or NULL on failure.
  */
 WS_DLL_PUBLIC
 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);
 
 WS_DLL_PUBLIC
 wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen,
@@ -1859,16 +1853,16 @@ wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen
  * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
  * @param snaplen The maximum packet capture length.
  * @param compressed True if file should be compressed.
- * @param shb_hdr The section header block information, or NULL.
+ * @param shb_hdrs The section header block(s) information, or NULL.
  * @param idb_inf The interface description information, or NULL.
- * @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
+ * @param nrb_hdrs The name resolution blocks(s) comment/custom_opts information, or NULL.
  * @param[out] err Will be set to an error code on failure.
  * @return The newly created dumper object, or NULL on failure.
  */
 WS_DLL_PUBLIC
 wtap_dumper* wtap_dump_open_stdout_ng(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);
 
 WS_DLL_PUBLIC
 gboolean wtap_dump(wtap_dumper *, const struct wtap_pkthdr *, const guint8 *,
@@ -1882,8 +1876,13 @@ void wtap_set_bytes_dumped(wtap_dumper *wdh, gint64 bytes_dumped);
 struct addrinfo;
 WS_DLL_PUBLIC
 gboolean wtap_dump_set_addrinfo_list(wtap_dumper *wdh, addrinfo_lists_t *addrinfo_lists);
+
+/**
+ * Closes open file handles and frees memory associated with wdh. Note that
+ * shb_hdr, idb_inf and nrb_hdr are not freed by this routine.
+ */
 WS_DLL_PUBLIC
-gboolean wtap_dump_close(wtap_dumper *, int *);
+gboolean wtap_dump_close(wtap_dumper *wdh, int *err);
 
 /**
  * Return TRUE if we can write a file out with the given GArray of file
@@ -1911,7 +1910,7 @@ int wtap_short_string_to_file_type_subtype(const char *short_name);
 
 /*** various file extension functions ***/
 WS_DLL_PUBLIC
-GSList *wtap_get_all_file_extensions_list(void);
+GSList *wtap_get_all_capture_file_extensions_list(void);
 WS_DLL_PUBLIC
 const char *wtap_default_file_extension(int filetype);
 WS_DLL_PUBLIC