This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHarald Welte has submitted this change and it was merged. Change subject: Add osmo_pcap_lapd_set_fd() function ...................................................................... Add osmo_pcap_lapd_set_fd() function This way the caller can hand in an already-open file descriptor, rather than calling osmo_pcap_lapd_open() with a file path name. Change-Id: Ic7193907a96b0e2284cb6a8a942d2bf0fb95d7e4 --- M include/osmocom/abis/lapd_pcap.h M src/input/lapd_pcap.c 2 files changed, 23 insertions(+), 8 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/osmocom/abis/lapd_pcap.h b/include/osmocom/abis/lapd_pcap.h index 1c0d555..e1b587e 100644 --- a/include/osmocom/abis/lapd_pcap.h +++ b/include/osmocom/abis/lapd_pcap.h @@ -5,6 +5,7 @@ #define OSMO_LAPD_PCAP_OUTPUT 1 int osmo_pcap_lapd_open(char *filename, mode_t mode); +int osmo_pcap_lapd_set_fd(int fd); int osmo_pcap_lapd_write(int fd, int direction, struct msgb *msg); int osmo_pcap_lapd_close(int fd); diff --git a/src/input/lapd_pcap.c b/src/input/lapd_pcap.c index c83bc60..2a635cc 100644 --- a/src/input/lapd_pcap.c +++ b/src/input/lapd_pcap.c @@ -75,10 +75,9 @@ osmo_static_assert(offsetof(struct pcap_lapdhdr, protocol) == 14, proto_offset); osmo_static_assert(sizeof(struct pcap_lapdhdr) == 16, lapd_header_size); -int osmo_pcap_lapd_open(char *filename, mode_t mode) +int osmo_pcap_lapd_set_fd(int fd) { - int fd; - struct pcap_hdr pcap_header = { + struct pcap_hdr pcap_header = { .magic_number = 0xa1b2c3d4, .version_major = 2, .version_minor = 4, @@ -88,6 +87,21 @@ .network = DLT_LINUX_LAPD, }; + if (write(fd, &pcap_header, sizeof(pcap_header)) + != sizeof(pcap_header)) { + LOGP(DLLAPD, LOGL_ERROR, "cannot write PCAP header: %s\n", + strerror(errno)); + close(fd); + return -1; + } + + return 0; +} + +int osmo_pcap_lapd_open(char *filename, mode_t mode) +{ + int fd, rc; + LOGP(DLLAPD, LOGL_NOTICE, "opening LAPD pcap file `%s'\n", filename); fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, mode); @@ -96,13 +110,13 @@ strerror(errno)); return -1; } - if (write(fd, &pcap_header, sizeof(pcap_header)) - != sizeof(pcap_header)) { - LOGP(DLLAPD, LOGL_ERROR, "cannot write PCAP header: %s\n", - strerror(errno)); + + rc = osmo_pcap_lapd_set_fd(fd); + if (rc < 0) { close(fd); - return -1; + return rc; } + return fd; } -- To view, visit https://gerrit.osmocom.org/452 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic7193907a96b0e2284cb6a8a942d2bf0fb95d7e4 Gerrit-PatchSet: 1 Gerrit-Project: libosmo-abis Gerrit-Branch: master Gerrit-Owner: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder