aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2020-05-08 09:40:44 +0200
committerSylvain Munaut <tnt@246tNt.com>2020-05-08 18:10:15 +0200
commit4b45e9d1a6fcb0a56cecd561f0c4353d9c2bbb2a (patch)
treebe6094d9e782a6e298a3178f9924de87079979eb
parent73a73c0381beebef3e2a7d88fd612383dfb2bf44 (diff)
e1_input: Allow to change the pcap fd and/or unset it
This will update the pcap fd in all open lines and close the previous one (if applicable). Signed-off-by: Sylvain Munaut <tnt@246tNt.com> Change-Id: I5c7dd740ba0a90b40c69a53b3dcc9d6d6a98f660
-rw-r--r--src/e1_input.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/e1_input.c b/src/e1_input.c
index ad4e25c..379cc53 100644
--- a/src/e1_input.c
+++ b/src/e1_input.c
@@ -142,7 +142,7 @@ static int pcap_fd = -1;
int e1_set_pcap_fd(int fd)
{
- struct pcap_hdr header = {
+ const struct pcap_hdr header = {
.magic_number = 0xa1b2c3d4,
.version_major = 2,
.version_minor = 4,
@@ -151,9 +151,34 @@ int e1_set_pcap_fd(int fd)
.snaplen = 65535,
.network = DLT_LINUX_LAPD,
};
+ struct e1inp_line *line;
+ int i;
+
+ /* write header */
+ if (fd >= 0) {
+ int rc = write(fd, &header, sizeof(header));
+ if (rc < 0)
+ return rc;
+ }
+
+ /* update fd in all lines in our global list of e1 lines */
+ llist_for_each_entry(line, &e1inp_line_list, list) {
+ /* Set the PCAP file descriptor for all timeslots that have
+ * software LAPD instances, to ensure the osmo_lapd_pcap code is
+ * used to write PCAP files (if requested) */
+ for (i = 0; i < ARRAY_SIZE(line->ts); i++) {
+ struct e1inp_ts *e1i_ts = &line->ts[i];
+ if (e1i_ts->lapd)
+ e1i_ts->lapd->pcap_fd = fd;
+ }
+ }
+ /* close previous and update global */
+ if (pcap_fd >= 0)
+ close(pcap_fd);
pcap_fd = fd;
- return write(pcap_fd, &header, sizeof(header));
+
+ return 0;
}
/* This currently only works for the D-Channel */