2010-08-01 08:58:34 +00:00
|
|
|
/* PCAP code from OpenBSC done by Holger Freyther */
|
|
|
|
/*
|
|
|
|
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
|
|
|
|
* (C) 2010 by On-Waves
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
2017-11-12 16:25:47 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*
|
2010-08-01 08:58:34 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
build: move include/{mtp,sccp} to include/osmocom/
Anywhere else in the Osmocom code base, we arrange headers in
include/osmocom/foo/ and pass -I ${root_srcdir}/include/.
This way including an osmocom header always has the format
#include <osmocom/foo/bar.h>
whether we are including from the local source tree or from $prefix.
For some reason not clear to me, the mtp and sccp folders, even though they are
being installed to $prefix/include/osmocom/, were kept *next* to the osmocom/
dir, instead of inside it. Fix that weird situation.
The motivation is that I wanted to use a definition from sccp_types.h in a
public-API header. That is impossible if it requires
#include <sccp/sccp_types.h>
in a local build, but
#include <osmocom/sccp/sccp_types.h>
for any other source tree using libosmo-sccp. After this patch, both are
identical and including works without quirks. (The other patch that needed this
has changed in the meantime on and no longer needs this, but this still makes
sense for future hacking.)
The installed result does not change, since both mtp/*.h and sccp/*.h have
always been installed to $prefix/include/osmocom/{mtp,sccp}/. This merely
changes their position in the source tree.
The most curious situation before this is that any patch #including
<osmocom/sccp/sccp_types.h> might not get a notice that the header didn't
exist, but might instead include an older system-installed file.
Change-Id: I1209a4ecf9f692a8030b5c93cd281fc9dd58d105
2018-09-26 18:49:48 +00:00
|
|
|
#include <osmocom/mtp/mtp_pcap.h>
|
2010-08-01 08:58:34 +00:00
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pcap writing of the misdn load
|
|
|
|
* pcap format is from http://wiki.wireshark.org/Development/LibpcapFileFormat
|
|
|
|
*/
|
|
|
|
struct pcap_hdr {
|
|
|
|
uint32_t magic_number;
|
|
|
|
uint16_t version_major;
|
|
|
|
uint16_t version_minor;
|
|
|
|
int32_t thiszone;
|
|
|
|
uint32_t sigfigs;
|
|
|
|
uint32_t snaplen;
|
|
|
|
uint32_t network;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct pcaprec_hdr {
|
|
|
|
uint32_t ts_sec;
|
|
|
|
uint32_t ts_usec;
|
|
|
|
uint32_t incl_len;
|
|
|
|
uint32_t orig_len;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
int mtp_pcap_write_header(int fd)
|
|
|
|
{
|
|
|
|
static struct pcap_hdr hdr = {
|
|
|
|
.magic_number = 0xa1b2c3d4,
|
|
|
|
.version_major = 2,
|
|
|
|
.version_minor = 4,
|
|
|
|
.thiszone = 0,
|
|
|
|
.sigfigs = 0,
|
|
|
|
.snaplen = 65535,
|
|
|
|
.network = 141,
|
|
|
|
};
|
|
|
|
|
|
|
|
return write(fd, &hdr, sizeof(hdr));
|
|
|
|
}
|
|
|
|
|
|
|
|
int mtp_pcap_write_msu(int fd, const uint8_t *data, int length)
|
|
|
|
{
|
|
|
|
int rc_h, rc_d;
|
|
|
|
struct timeval tv;
|
|
|
|
struct pcaprec_hdr payload_header = {
|
|
|
|
.ts_sec = 0,
|
|
|
|
.ts_usec = 0,
|
|
|
|
.incl_len = length,
|
|
|
|
.orig_len = length,
|
|
|
|
};
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
payload_header.ts_sec = tv.tv_sec;
|
|
|
|
payload_header.ts_usec = tv.tv_usec;
|
|
|
|
|
|
|
|
rc_h = write(fd, &payload_header, sizeof(payload_header));
|
|
|
|
rc_d = write(fd, data, length);
|
|
|
|
|
|
|
|
return rc_h == sizeof(payload_header) && rc_d == length;
|
|
|
|
}
|