aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-10-19 00:23:10 +0200
committerHarald Welte <laforge@gnumonks.org>2016-10-19 00:23:10 +0200
commitf403232e0fbc8e9b04671bbcec62bc15ccd2ea30 (patch)
tree5e9a0b31cab70027cf28c9a9a495eccb896414f7
parent57ea229e8a9654c0de004d5e8607c046d1f8c34b (diff)
e1cap_dump: Add capability to filter on a given line+timeslot and for binary output
-rw-r--r--src/e1cap_dump.c74
1 files changed, 66 insertions, 8 deletions
diff --git a/src/e1cap_dump.c b/src/e1cap_dump.c
index 03b86f7..b732449 100644
--- a/src/e1cap_dump.c
+++ b/src/e1cap_dump.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <time.h>
+#include <unistd.h>
#include <sys/time.h>
@@ -12,6 +13,15 @@
struct e1_recorder g_recorder;
+enum mode {
+ MODE_PRINT,
+ MODE_BIN,
+};
+
+static enum mode g_mode = MODE_PRINT;
+static int g_filter_line = -1;
+static int g_filter_slot = -1;
+
static char *timeval2str(struct timeval *tv)
{
time_t nowtime;
@@ -26,27 +36,75 @@ static char *timeval2str(struct timeval *tv)
return buf;
}
+static int handle_options(int argc, char **argv)
+{
+ int opt;
+
+ while ((opt = getopt(argc, argv, "l:s:b")) != -1) {
+ switch (opt) {
+ case 'l':
+ g_filter_line = atoi(optarg);
+ break;
+ case 's':
+ g_filter_slot = atoi(optarg);
+ break;
+ case 'b':
+ g_mode = MODE_BIN;
+ break;
+ default:
+ fprintf(stderr, "Unknown option '%c'\n", opt);
+ exit(EXIT_FAILURE);
+ break;
+ }
+ }
+
+ return 0;
+}
+
int main(int argc, char **argv)
{
struct osmo_e1cap_file *f;
struct osmo_e1cap_pkthdr *pkt;
+ unsigned long num_pkt = 0;
printf("sizeof(timeval) = %zu\n", sizeof(struct timeval));
printf("sizeof(osmo_e1cap_pkthdr) = %zu\n", sizeof(*pkt));
- if (argc < 2)
+ handle_options(argc, argv);
+
+ if (optind >= argc) {
+ fprintf(stderr, "Missing input file name\n");
exit(2);
+ }
- f = osmo_e1cap_open(NULL, argv[1]);
- if (!f)
+ f = osmo_e1cap_open(NULL, argv[optind++]);
+ if (!f) {
+ fprintf(stderr, "Unable to open input file\n");
exit(1);
+ }
while ((pkt = osmo_e1cap_read_next(f))) {
- printf("%s %02u/%02u %u (%u): %s\n",
- timeval2str(&pkt->ts),
- pkt->line_nr, pkt->ts_nr, pkt->capture_mode,
- pkt->len,
- osmo_hexdump_nospc(pkt->data, pkt->len));
+ num_pkt++;
+
+ if (g_filter_line >= 0 && pkt->line_nr != g_filter_line)
+ continue;
+ if (g_filter_slot >= 0 && pkt->ts_nr != g_filter_slot)
+ continue;
+
+ switch (g_mode) {
+ case MODE_PRINT:
+ printf("%s %02u/%02u %u (%u): %s\n",
+ timeval2str(&pkt->ts),
+ pkt->line_nr, pkt->ts_nr, pkt->capture_mode,
+ pkt->len,
+ osmo_hexdump_nospc(pkt->data, pkt->len));
+ break;
+ case MODE_BIN:
+ write(1, pkt->data, pkt->len);
+ break;
+ }
talloc_free(pkt);
}
+
+ fprintf(stderr, "Processed a total of %lu packets\n", num_pkt);
}