forked from Mirrors/sngrep
parent
cde88e7a4b
commit
0d48912646
|
@ -104,7 +104,7 @@ capture_deinit()
|
|||
}
|
||||
|
||||
int
|
||||
capture_online(const char *dev, const char *outfile)
|
||||
capture_online(const char *dev)
|
||||
{
|
||||
capture_info_t *capinfo;
|
||||
|
||||
|
@ -177,20 +177,11 @@ capture_online(const char *dev, const char *outfile)
|
|||
// Add this capture information as packet source
|
||||
capture_add_source(capinfo);
|
||||
|
||||
// If requested store packets in a dump file
|
||||
if (outfile && !capture_cfg.pd) {
|
||||
if ((capture_cfg.pd = dump_open(outfile)) == NULL) {
|
||||
fprintf(stderr, "Couldn't open output dump file %s: %s\n", outfile,
|
||||
pcap_geterr(capinfo->handle));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
capture_offline(const char *infile, const char *outfile)
|
||||
capture_offline(const char *infile)
|
||||
{
|
||||
capture_info_t *capinfo;
|
||||
FILE *fstdin;
|
||||
|
@ -242,15 +233,6 @@ capture_offline(const char *infile, const char *outfile)
|
|||
// Add this capture information as packet source
|
||||
capture_add_source(capinfo);
|
||||
|
||||
// If requested store packets in a dump file
|
||||
if (outfile && !capture_cfg.pd) {
|
||||
if ((capture_cfg.pd = dump_open(outfile)) == NULL) {
|
||||
fprintf(stderr, "Couldn't open output dump file %s: %s\n", outfile,
|
||||
pcap_geterr(capinfo->handle));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1208,6 +1190,18 @@ capture_packet_time_sorter(vector_t *vector, void *item)
|
|||
vector_insert(vector, item, 0);
|
||||
}
|
||||
|
||||
void
|
||||
capture_set_dumper(pcap_dumper_t *dumper)
|
||||
{
|
||||
capture_cfg.pd = dumper;
|
||||
}
|
||||
|
||||
void
|
||||
capture_dump_packet(packet_t *packet)
|
||||
{
|
||||
dump_packet(capture_cfg.pd, packet);
|
||||
}
|
||||
|
||||
|
||||
int8_t
|
||||
datalink_size(int datalink)
|
||||
|
|
|
@ -199,12 +199,11 @@ capture_deinit();
|
|||
* @brief Online capture function
|
||||
*
|
||||
* @param device Device to start capture from
|
||||
* @param outfile Dumpfile for captured packets
|
||||
*
|
||||
* @return 0 on spawn success, 1 otherwise
|
||||
*/
|
||||
int
|
||||
capture_online(const char *dev, const char *outfile);
|
||||
capture_online(const char *dev);
|
||||
|
||||
/**
|
||||
* @brief Read from pcap file and fill sngrep sctuctures
|
||||
|
@ -217,7 +216,7 @@ capture_online(const char *dev, const char *outfile);
|
|||
* @return 0 if load has been successfull, 1 otherwise
|
||||
*/
|
||||
int
|
||||
capture_offline(const char *infile, const char *outfile);
|
||||
capture_offline(const char *infile);
|
||||
|
||||
/**
|
||||
* @brief Read the next package and parse SIP messages
|
||||
|
@ -464,6 +463,18 @@ capture_packet_time_sorter(vector_t *vector, void *item);
|
|||
void
|
||||
capture_close();
|
||||
|
||||
/**
|
||||
* @brief Set general capture dumper
|
||||
*/
|
||||
void
|
||||
capture_set_dumper(pcap_dumper_t *dumper);
|
||||
|
||||
/**
|
||||
* @brief Store a packet in dumper file
|
||||
*/
|
||||
void
|
||||
capture_dump_packet(packet_t *packet);
|
||||
|
||||
/**
|
||||
* @brief Get datalink header size
|
||||
*
|
||||
|
|
|
@ -674,6 +674,9 @@ capture_eep_receive_v2()
|
|||
packet_set_type(pkt, PACKET_SIP_UDP);
|
||||
packet_set_payload(pkt, payload, header.caplen);
|
||||
|
||||
// Store this packets in output file
|
||||
capture_dump_packet(pkt);
|
||||
|
||||
/* FREE */
|
||||
sng_free(payload);
|
||||
return pkt;
|
||||
|
@ -853,6 +856,9 @@ capture_eep_receive_v3(const u_char *pkt, uint32_t size)
|
|||
packet_set_type(pkt_new, PACKET_SIP_UDP);
|
||||
packet_set_payload(pkt_new, payload, header.caplen);
|
||||
|
||||
// Store this packets in output file
|
||||
capture_dump_packet(pkt_new);
|
||||
|
||||
/* FREE */
|
||||
sng_free(payload);
|
||||
return pkt_new;
|
||||
|
|
|
@ -370,17 +370,21 @@ main(int argc, char* argv[])
|
|||
// If we have an input file, load it
|
||||
for (i = 0; i < vector_count(infiles); i++) {
|
||||
// Try to load file
|
||||
if (capture_offline(vector_item(infiles, i), outfile) != 0)
|
||||
if (capture_offline(vector_item(infiles, i)) != 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// If we have an input device, load it
|
||||
for (i = 0; i < vector_count(indevices); i++) {
|
||||
// Check if all capture data is valid
|
||||
if (capture_online(vector_item(indevices, i), outfile) != 0)
|
||||
if (capture_online(vector_item(indevices, i)) != 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (outfile) {
|
||||
capture_set_dumper(dump_open(outfile));
|
||||
}
|
||||
|
||||
// Remove Input files vector
|
||||
vector_destroy(infiles);
|
||||
|
||||
|
|
Loading…
Reference in New Issue