Skip to content

Commit

Permalink
Merge pull request #5 from nprint/organize
Browse files Browse the repository at this point in the history
lint and re-org / rename for tab completion
  • Loading branch information
Jordan Holland authored Nov 15, 2021
2 parents 1128503 + e41b851 commit dc072c0
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 81 deletions.
21 changes: 13 additions & 8 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ AUTOMAKE_OPTIONS = subdir-objects

bin_PROGRAMS = pcapml


pcapml_SOURCES = include/dir/dir.hpp include/label/label.hpp include/label/labeler.hpp \
include/pcap/pcap_reader.hpp include/pcapng/pcapng_reader.hpp include/pcapng/pcapng_writer.hpp \
include/pcapng/block.hpp include/pcapng/pcapng_sorter.hpp include/sample/sample.hpp \
include/sample/sampler.hpp include/util.hpp include/pcapng/pcapng_splitter.hpp \
include/pcap/pcap_writer.hpp \
include/pcap/reader_pcap.hpp include/pcap/writer_pcap.hpp \
include/pcapng/block_pcapng.hpp include/pcapng/reader_pcapng.hpp \
include/pcapng/sorter_pcapng.hpp include/pcapng/splitter_pcapng.hpp \
include/pcapng/writer_pcapng.hpp \
include/sample/sample.hpp include/sample/sampler.hpp \
include/util.hpp \
src/dir/dir.cpp src/label/label.cpp src/label/labeler.cpp \
src/pcap/pcap_reader.cpp src/pcapng/pcapng_reader.cpp src/pcapng/pcapng_writer.cpp \
src/pcapng/block.cpp src/pcapng/pcapng_sorter.cpp src/sample/sample.cpp \
src/sample/sampler.cpp src/util.cpp src/pcapml.cpp src/pcapng/pcapng_splitter.cpp \
src/pcap/pcap_writer.cpp
src/pcap/reader_pcap.cpp src/pcap/writer_pcap.cpp \
src/pcapng/block_pcapng.cpp src/pcapng/reader_pcapng.cpp \
src/pcapng/sorter_pcapng.cpp src/pcapng/splitter_pcapng.cpp \
src/pcapng/writer_pcapng.cpp \
src/sample/sample.cpp src/sample/sampler.cpp \
src/util.cpp src/pcapml.cpp

AM_CPPFLAGS = -I include/ -I include/dir -I include/pcap/ -I include/pcapng -I include/sample -I include/label -pedantic -Wall -std=gnu++11 $(WRAPPER_CPPFLAGS)
AM_LDFLAGS = $(WRAPPER_LDFLAGS)
5 changes: 2 additions & 3 deletions include/dir/dir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
#include <string>
#include <fstream>


#include "pcap_reader.hpp"
#include "pcapng_writer.hpp"
#include "util.hpp"
#include "reader_pcap.hpp"
#include "writer_pcapng.hpp"

class DirLabeler {
public:
Expand Down
4 changes: 2 additions & 2 deletions include/label/labeler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include "util.hpp"
#include "label.hpp"
#include "pcap_reader.hpp"
#include "pcapng_writer.hpp"
#include "reader_pcap.hpp"
#include "writer_pcapng.hpp"

#define LABEL_FILE_LOC 0
#define FILTER_LOC 1
Expand Down
6 changes: 3 additions & 3 deletions include/pcap/pcap_reader.hpp → include/pcap/reader_pcap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#ifndef INCLUDE_PCAP_PCAP_READER_HPP_
#define INCLUDE_PCAP_PCAP_READER_HPP_
#ifndef INCLUDE_PCAP_READER_PCAP_HPP_
#define INCLUDE_PCAP_READER_PCAP_HPP_

#if defined(__NetBSD__)
#include <net/if_ether.h>
Expand All @@ -30,4 +30,4 @@ class PcapReader {
pcap_t *get_pcap_handle();
};

#endif // INCLUDE_PCAP_PCAP_READER_HPP_
#endif // INCLUDE_PCAP_READER_PCAP_HPP_
6 changes: 3 additions & 3 deletions include/pcap/pcap_writer.hpp → include/pcap/writer_pcap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#ifndef INCLUDE_PCAP_WRITER_HPP_
#define INCLUDE_PCAP_WRITER_HPP_
#ifndef INCLUDE_PCAP_WRITER_PCAP_HPP_
#define INCLUDE_PCAP_WRITER_PCAP_HPP_

#if defined(__NetBSD__)
#include <net/if_ether.h>
Expand All @@ -31,4 +31,4 @@ class PcapWriter {
pcap_t *get_pcap_handle();
};

#endif // INCLUDE_PCAP_PCAP_READER_HPP_
#endif // INCLUDE_PCAP_WRITER_PCAP_HPP_
6 changes: 3 additions & 3 deletions include/pcapng/block.hpp → include/pcapng/block_pcapng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#ifndef INCLUDE_PCAPNG_BLOCK_HPP_
#define INCLUDE_PCAPNG_BLOCK_HPP_
#ifndef INCLUDE_PCAPNG_BLOCK_PCAPNG_HPP_
#define INCLUDE_PCAPNG_BLOCK_PCAPNG_HPP_

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -102,4 +102,4 @@ class Block {
};


#endif // INCLUDE_PCAPNG_BLOCK_HPP_
#endif // INCLUDE_PCAPNG_BLOCK_PCAPNG_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#ifndef INCLUDE_PCAPNG_PCAPNG_READER_HPP_
#define INCLUDE_PCAPNG_PCAPNG_READER_HPP_
#ifndef INCLUDE_PCAPNG_READER_PCAPNG_HPP_
#define INCLUDE_PCAPNG_READER_PCAPNG_HPP_

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))

Expand Down Expand Up @@ -36,7 +36,7 @@
#include <algorithm>

#include "util.hpp"
#include "block.hpp"
#include "block_pcapng.hpp"

class PcapNGReader {
public:
Expand Down Expand Up @@ -70,4 +70,4 @@ class PcapNGReader {
void read_section_header(Block *b);
};

#endif // INCLUDE_PCAPNG_PCAPNG_READER_HPP_
#endif // INCLUDE_PCAPNG_READER_PCAPNG_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#ifndef INCLUDE_PCAPNG_PCAPNG_SORTER_HPP_
#define INCLUDE_PCAPNG_PCAPNG_SORTER_HPP_
#ifndef INCLUDE_PCAPNG_SORTER_PCAPNG_HPP_
#define INCLUDE_PCAPNG_SORTER_PCAPNG_HPP_

#include <vector>
#include <algorithm>

#include "util.hpp"
#include "block.hpp"
#include "pcapng_reader.hpp"
#include "block_pcapng.hpp"
#include "reader_pcapng.hpp"

struct PacketSortInfo {
size_t sid;
Expand Down Expand Up @@ -42,4 +42,4 @@ class Sorter : public PcapNGReader {
std::vector<PacketSortInfo> pkt_blocks;
};

#endif // INCLUDE_PCAPNG_PCAPNG_SORTER_HPP_
#endif // INCLUDE_PCAPNG_SORTER_PCAPNG_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#ifndef INCLUDE_PCAPNG_PCAPNG_SPLITTER_HPP_
#define INCLUDE_PCAPNG_PCAPNG_SPLITTER_HPP_
#ifndef INCLUDE_PCAPNG_SPLITTER_PCAPNG_HPP_
#define INCLUDE_PCAPNG_SPLITTER_PCAPNG_HPP_

#include <string>

#include "util.hpp"
#include "block.hpp"
#include "pcapng_reader.hpp"
#include "pcap_writer.hpp"
#include "writer_pcap.hpp"
#include "block_pcapng.hpp"
#include "reader_pcapng.hpp"

class Splitter : public PcapNGReader {
public:
Expand All @@ -23,13 +25,12 @@ class Splitter : public PcapNGReader {
std::string cur_sid = "";
std::string cur_metadata = "";
FILE *mdf = NULL;

FILE *fopen_mkdir(char *path);
FILE *open_metadata_file(char *path);
void recursive_mkdir(char *path);
bool process_idb(Block *b);
bool process_packet_block(Block *b);
bool update_io(std::vector<std::string> &tokens);
};

#endif // INCLUDE_PCAPNG_PCAPNG_SPLITTER_HPP_
#endif // INCLUDE_PCAPNG_SPLITTER_PCAPNG_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#ifndef INCLUDE_PCAPNG_PCAPNG_WRITER_HPP_
#define INCLUDE_PCAPNG_PCAPNG_WRITER_HPP_
#ifndef INCLUDE_PCAPNG_WRITER_PCAPNG_HPP_
#define INCLUDE_PCAPNG_WRITER_PCAPNG_HPP_

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))

Expand Down Expand Up @@ -34,7 +34,7 @@
#include <exception>

#include "util.hpp"
#include "block.hpp"
#include "block_pcapng.hpp"

class PcapNGWriter {
public:
Expand All @@ -54,4 +54,4 @@ class PcapNGWriter {
int pad_packet(int pkt_len);
};

#endif // INCLUDE_PCAPNG_PCAPNG_WRITER_HPP_
#endif // INCLUDE_PCAPNG_WRITER_PCAPNG_HPP_
4 changes: 2 additions & 2 deletions include/sample/sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#ifndef INCLUDE_SAMPLE_SAMPLER_HPP_
#define INCLUDE_SAMPLE_SAMPLER_HPP_

#include "block.hpp"
#include "sample.hpp"
#include "pcapng_reader.hpp"
#include "block_pcapng.hpp"
#include "reader_pcapng.hpp"

class Sampler : public PcapNGReader {
public:
Expand Down
9 changes: 4 additions & 5 deletions include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@
#define INCLUDE_UTIL_HPP_

#include <sys/stat.h>

#include <pcap.h>

#include <string>
#include <vector>
#include <sstream>
#include <tuple>


#include "block.hpp"
#include "block_pcapng.hpp"

struct pcap_packet_info {
struct pcap_pkthdr hdr;
const uint8_t *buf;
};

void tokenize_string(std::string s, std::vector<std::string> &to_fill,
char delimiter);
bool check_file_exists(char *f);
uint64_t transform_ts(uint32_t low, uint32_t high);
std::tuple<size_t, std::string> get_info_from_pkt_comment(std::string comment);
bool check_file_exists(char *f);
void tokenize_string(std::string s, std::vector<std::string> &to_fill, char delimiter);

#endif // INCLUDE_UTIL_HPP_
2 changes: 1 addition & 1 deletion src/pcap/pcap_reader.cpp → src/pcap/reader_pcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#include "pcap_reader.hpp"
#include "reader_pcap.hpp"

int PcapReader::open_file(char *infile) {
char errbuf[PCAP_ERRBUF_SIZE];
Expand Down
4 changes: 2 additions & 2 deletions src/pcap/pcap_writer.cpp → src/pcap/writer_pcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#include "pcap_writer.hpp"
#include "writer_pcap.hpp"

int PcapWriter::open_file(char *outfile) {
pd = pcap_open_dead(DLT_EN10MB, 65535 /* snaplen */);
Expand All @@ -21,5 +21,5 @@ int PcapWriter::write_packet(pcap_pkthdr *hdr, uint8_t *buf) {
}

void PcapWriter::close_file() {
if(pd != NULL) pcap_close(pd);
if (pd != NULL) pcap_close(pd);
}
6 changes: 3 additions & 3 deletions src/pcapml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

#include "dir.hpp"
#include "labeler.hpp"
#include "pcapng_reader.hpp"
#include "pcapng_sorter.hpp"
#include "pcapng_splitter.hpp"
#include "reader_pcapng.hpp"
#include "sorter_pcapng.hpp"
#include "splitter_pcapng.hpp"

const char *argp_program_version = "pcapml 0.0.1";
const char *argp_program_bug_address = "https://github.com/nprint/pcapml";
Expand Down
2 changes: 1 addition & 1 deletion src/pcapng/block.cpp → src/pcapng/block_pcapng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#include "block.hpp"
#include "block_pcapng.hpp"

Block::Block(BlockHeader *bh, uint64_t f_start) {
this->bh = bh;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#include "pcapng_reader.hpp"
#include "reader_pcapng.hpp"

int PcapNGReader::open_pcapng(char *infile) {
packets_processed = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*/

#include "pcapng_sorter.hpp"
#include "sorter_pcapng.hpp"

bool Sorter::process_block(Block *b, void *p) {
uint32_t block_type;
Expand Down
Loading

0 comments on commit dc072c0

Please sign in to comment.