Make pcap file format an option

Valid options are raw and eth. Default is raw as it was before last commit.
fixes #290
changes/53/9753/1
Kristian Høgh 9 years ago committed by Richard Fuchs
parent 29488f9e49
commit 0edfb2dfcc

@ -88,6 +88,7 @@ static int delete_delay = 30;
static int graphite_interval = 0;
static char *spooldir;
static char *rec_method = "pcap";
static char *rec_format = "raw";
static void sighandler(gpointer x) {
sigset_t ss;
@ -329,6 +330,7 @@ static void options(int *argc, char ***argv) {
{ "homer-id", 0, 0, G_OPTION_ARG_STRING, &homer_id, "'Capture ID' to use within the HEP protocol", "INT" },
{ "recording-dir", 0, 0, G_OPTION_ARG_STRING, &spooldir, "Directory for storing pcap and metadata files", "FILE" },
{ "recording-method",0, 0, G_OPTION_ARG_STRING, &rec_method, "Strategy for call recording", "pcap|proc" },
{ "recording-format",0, 0, G_OPTION_ARG_STRING, &rec_format, "File format for stored pcap files", "raw|eth" },
{ NULL, }
};
@ -529,7 +531,7 @@ static void init_everything() {
struct timespec ts;
log_init();
recording_fs_init(spooldir, rec_method);
recording_fs_init(spooldir, rec_method, rec_format);
clock_gettime(CLOCK_REALTIME, &ts);
srandom(ts.tv_sec ^ ts.tv_nsec);
SSL_library_init();

@ -82,7 +82,7 @@ static const struct recording_method methods[] = {
static char *spooldir = NULL;
const struct recording_method *selected_recording_method;
int rec_format;
@ -90,7 +90,7 @@ const struct recording_method *selected_recording_method;
* Initialize RTP Engine filesystem settings and structure.
* Check for or create the RTP Engine spool directory.
*/
void recording_fs_init(const char *spoolpath, const char *method_str) {
void recording_fs_init(const char *spoolpath, const char *method_str, const char *format_str) {
int i;
// Whether or not to fail if the spool directory does not exist.
@ -108,6 +108,15 @@ void recording_fs_init(const char *spoolpath, const char *method_str) {
return;
found:
if(!strcmp("raw", format_str))
rec_format = 0;
else if(!strcmp("eth", format_str))
rec_format = 1;
else {
ilog(LOG_ERR, "Invalid value for recording format \"%s\".", format_str);
exit(-1);
}
spooldir = strdup(spoolpath);
int path_len = strlen(spooldir);
@ -399,7 +408,10 @@ static char *recording_setup_file(struct recording *recording) {
recording_path = file_path_str(recording->meta_prefix, "/pcaps/", ".pcap");
recording->pcap.recording_path = recording_path;
recording->pcap.recording_pd = pcap_open_dead(DLT_EN10MB, 65535);
if(rec_format == 1)
recording->pcap.recording_pd = pcap_open_dead(DLT_EN10MB, 65535);
else
recording->pcap.recording_pd = pcap_open_dead(DLT_RAW, 65535);
recording->pcap.recording_pdumper = pcap_dump_open(recording->pcap.recording_pd, recording_path);
if (recording->pcap.recording_pdumper == NULL) {
pcap_close(recording->pcap.recording_pd);
@ -450,11 +462,17 @@ static void stream_pcap_dump(pcap_dumper_t *pdumper, struct packet_stream *strea
if (!pdumper)
return;
unsigned char pkt[s->len + MAX_PACKET_HEADER_LEN + 14];
unsigned int pkt_len = fake_ip_header(pkt + 14, stream, s);
pkt_len += 14;
memset(pkt, 0, 14);
pkt[12] = 0x08;
int ether_len = 0;
if(rec_format == 1)
ether_len = 14;
unsigned char pkt[s->len + MAX_PACKET_HEADER_LEN + ether_len];
unsigned int pkt_len = fake_ip_header(pkt + ether_len, stream, s);
if(rec_format == 1) {
pkt_len += 14;
memset(pkt, 0, 14);
pkt[12] = 0x08;
}
// Set up PCAP packet header
struct pcap_pkthdr header;

@ -100,7 +100,7 @@ extern const struct recording_method *selected_recording_method;
* Initialize RTP Engine filesystem settings and structure.
* Check for or create the RTP Engine spool directory.
*/
void recording_fs_init(const char *spooldir, const char *method);
void recording_fs_init(const char *spooldir, const char *method, const char *format);
/**

Loading…
Cancel
Save