aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/mp2t.c
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2023-11-16 19:44:55 -0500
committerJohn Thacker <johnthacker@gmail.com>2023-11-17 03:47:05 +0000
commit656649d033d05c573c9b9d25d8ae21394e5d8eb2 (patch)
tree6e2dc8b517df7d0c1b77c89a7221cd8a3d5520d2 /wiretap/mp2t.c
parente675c13f8973dfd5a225663d7f2ae197fc4e7d27 (diff)
wiretap: Write MPEG-2 Transport Streams to native format
Write WTAP_ENCAP_MPEG_2_TS to its native format, which means just writing the packet bytes. This allows opening up a transport stream, filtering, and writing the result back in its native format instead of a pcap/pcapng.
Diffstat (limited to 'wiretap/mp2t.c')
-rw-r--r--wiretap/mp2t.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/wiretap/mp2t.c b/wiretap/mp2t.c
index a0f3f6112c..8481139847 100644
--- a/wiretap/mp2t.c
+++ b/wiretap/mp2t.c
@@ -395,6 +395,61 @@ found:
return WTAP_OPEN_MINE;
}
+static int mp2t_dump_can_write_encap(int encap)
+{
+ /* Per-packet encapsulations aren't supported. */
+ if (encap == WTAP_ENCAP_PER_PACKET) {
+ return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
+ }
+
+ /* This is the only encapsulation type we write. */
+ if (encap != WTAP_ENCAP_MPEG_2_TS) {
+ return WTAP_ERR_UNWRITABLE_ENCAP;
+ }
+
+ return 0;
+}
+
+/* Write a record for a packet to a dump file.
+ Returns TRUE on success, FALSE on failure. */
+static gboolean mp2t_dump(wtap_dumper *wdh, const wtap_rec *rec,
+ const uint8_t *pd, int *err, char **err_info _U_)
+{
+ /* We can only write packet records. */
+ if (rec->rec_type != REC_TYPE_PACKET) {
+ *err = WTAP_ERR_UNWRITABLE_REC_TYPE;
+ return FALSE;
+ }
+
+ /*
+ * Make sure this packet doesn't have a link-layer type that
+ * differs from the one for the file.
+ */
+ if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) {
+ *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
+ return FALSE;
+ }
+
+ /* A MPEG-2 Transport Stream is just the packet bytes, with no header.
+ * The sync byte is supposed to identify where packets start.
+ */
+ if (!wtap_dump_file_write(wdh, pd, rec->rec_header.packet_header.caplen, err)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
+ failure */
+static gboolean mp2t_dump_open(wtap_dumper *wdh, int *err _U_, char **err_info _U_)
+{
+ /* There is no header, so we just always return true. */
+ wdh->subtype_write = mp2t_dump;
+
+ return TRUE;
+}
+
static const struct supported_block_type mp2t_blocks_supported[] = {
/*
* We support packet blocks, with no comments or other options.
@@ -405,7 +460,7 @@ static const struct supported_block_type mp2t_blocks_supported[] = {
static const struct file_type_subtype_info mp2t_info = {
"MPEG2 transport stream", "mp2t", "mp2t", "ts;mpg",
FALSE, BLOCKS_SUPPORTED(mp2t_blocks_supported),
- NULL, NULL, NULL
+ mp2t_dump_can_write_encap, mp2t_dump_open, NULL
};
void register_mp2t(void)