Compare commits
No commits in common. "80d2ed51804d282bbdd4544c1e0b7e392080e06e" and "0485a7242da39d566a21b446d3c0317f61a77a44" have entirely different histories.
80d2ed5180
...
0485a7242d
9 changed files with 16 additions and 269 deletions
|
|
@ -1,12 +1,2 @@
|
||||||
---
|
---
|
||||||
BasedOnStyle: LLVM
|
BasedOnStyle: WebKit
|
||||||
IndentWidth: 4
|
|
||||||
ColumnLimit: 88
|
|
||||||
|
|
||||||
AllowShortFunctionsOnASingleLine: Inline
|
|
||||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
|
||||||
|
|
||||||
BinPackParameters: OnePerLine
|
|
||||||
|
|
||||||
AlignConsecutiveMacros: Consecutive
|
|
||||||
AlignEscapedNewlines: LeftWithLastLine
|
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 4.0)
|
||||||
PROJECT(nfgen LANGUAGES C)
|
PROJECT(nfgen LANGUAGES C)
|
||||||
|
|
||||||
SET(SOURCE_FILES
|
SET(SOURCE_FILES
|
||||||
config.c
|
main.c
|
||||||
main.c
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_EXECUTABLE(nfgen ${SOURCE_FILES})
|
ADD_EXECUTABLE(nfgen ${SOURCE_FILES})
|
||||||
|
|
@ -25,7 +24,5 @@ ADD_EXECUTABLE(nfgen ${SOURCE_FILES})
|
||||||
SET_PROPERTY(TARGET nfgen PROPERTY C_STANDARD 11)
|
SET_PROPERTY(TARGET nfgen PROPERTY C_STANDARD 11)
|
||||||
|
|
||||||
TARGET_COMPILE_OPTIONS(nfgen PRIVATE
|
TARGET_COMPILE_OPTIONS(nfgen PRIVATE
|
||||||
$<$<C_COMPILER_ID:AppleClang,Clang,GNU>: -Wall -Wextra -Wpedantic -Wformat=2 -Wuseless-cast -Wshadow>
|
$<$<C_COMPILER_ID:AppleClang,Clang,GNU>: -Wall>
|
||||||
)
|
)
|
||||||
|
|
||||||
TARGET_COMPILE_OPTIONS(nfgen PRIVATE $<$<NOT:$<CONFIG:Release,RelMinSize>>: -g>)
|
|
||||||
|
|
|
||||||
2
LICENSE
2
LICENSE
|
|
@ -209,7 +209,7 @@ If you develop a new program, and you want it to be of the greatest possible use
|
||||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
nfgen
|
nfgen
|
||||||
Copyright (C) 2026 Joshua Vega
|
Copyright (C) 2026 jsvcycling
|
||||||
|
|
||||||
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 3 of the License, or (at your option) any later version.
|
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 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
|
|
||||||
32
README.md
32
README.md
|
|
@ -1,33 +1,3 @@
|
||||||
# nfgen
|
# nfgen
|
||||||
|
|
||||||
Generate realistic NetFlow (v5 and/or v9) traffic.
|
Generate realistic NetFlow v5 and v9 packets.
|
||||||
|
|
||||||
## Building
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ cmake -DCMAKE_BUILD_TYPE=Release .
|
|
||||||
$ make
|
|
||||||
```
|
|
||||||
|
|
||||||
To build the executable with debugging symbols, remove the `-DCMAKE_BUILD_TYPE`
|
|
||||||
argument or set it to `-DCMAKE_BUILD_TYPE=Debug`.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
```
|
|
||||||
Copyright (C) 2026 Joshua Vega
|
|
||||||
|
|
||||||
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 3 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.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along with
|
|
||||||
this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
```
|
|
||||||
|
|
||||||
Please see `LICENSE` for the complete license details.
|
|
||||||
30
config.c
30
config.c
|
|
@ -1,30 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2026 Joshua Vega
|
|
||||||
*
|
|
||||||
* 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 3 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.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#define YAML_IMPLEMENTATION
|
|
||||||
#include "yaml.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int loadConfigFromFile(const char *path, size_t pathLength, Config **config) {
|
|
||||||
yaml_value_t *configRoot = yaml_parse(path, pathLength);
|
|
||||||
if (configRoot == NULL) {
|
|
||||||
fprintf(stderr, "%s", yaml_error());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
27
config.h
27
config.h
|
|
@ -1,27 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2026 Joshua Vega
|
|
||||||
*
|
|
||||||
* 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 3 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.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
#ifndef CONFIG_H
|
|
||||||
#define CONFIG_H
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
typedef struct Config {
|
|
||||||
/* TODO */
|
|
||||||
} Config;
|
|
||||||
|
|
||||||
int loadConfigFromFile(const char *path, size_t pathLength, Config **config);
|
|
||||||
|
|
||||||
#endif /* CONFIG_H */
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
find . -regex '.*\.\(c\|h\)' -not -path "./CMakeFiles/*" -exec clang-format -i --sort-includes {} \;
|
|
||||||
28
main.c
28
main.c
|
|
@ -18,20 +18,20 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#define ARG_L_CONFIG_PATH "--config"
|
#define ARG_L_CONFIG_PATH "--config"
|
||||||
#define ARG_S_CONFIG_PATH "-c"
|
#define ARG_S_CONFIG_PATH "-c"
|
||||||
|
|
||||||
#define ARG_LEN_L_CONFIG_PATH 8
|
#define ARG_LEN_L_CONFIG_PATH 8
|
||||||
#define ARG_LEN_S_CONFIG_PATH 2
|
#define ARG_LEN_S_CONFIG_PATH 2
|
||||||
|
|
||||||
Config *config = NULL;
|
char configPath[1024];
|
||||||
|
size_t configPathLength = 0;
|
||||||
|
|
||||||
int parseArguments(int, char **);
|
int parseArguments(int, char**);
|
||||||
void printHelp(void);
|
void printHelp(void);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
if (parseArguments(argc, argv) != 0) {
|
if (parseArguments(argc, argv) != 0) {
|
||||||
printHelp();
|
printHelp();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -40,13 +40,12 @@ int main(int argc, char **argv) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parseArguments(int argc, char **argv) {
|
int parseArguments(int argc, char** argv)
|
||||||
char configPath[1024];
|
{
|
||||||
size_t configPathLength = 0;
|
|
||||||
bool expectConfigPath = false;
|
bool expectConfigPath = false;
|
||||||
|
|
||||||
for (int argIndex = 1; argIndex < argc; argIndex++) {
|
for (int argIndex = 1; argIndex < argc; argIndex++) {
|
||||||
const char *arg = argv[argIndex];
|
const char* arg = argv[argIndex];
|
||||||
|
|
||||||
if (expectConfigPath) {
|
if (expectConfigPath) {
|
||||||
size_t length = strlen(arg);
|
size_t length = strlen(arg);
|
||||||
|
|
@ -63,9 +62,7 @@ int parseArguments(int argc, char **argv) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expectConfigPath &&
|
if (!expectConfigPath && (strncmp(arg, ARG_L_CONFIG_PATH, ARG_LEN_L_CONFIG_PATH) || strncmp(arg, ARG_S_CONFIG_PATH, ARG_LEN_S_CONFIG_PATH))) {
|
||||||
(strncmp(arg, ARG_L_CONFIG_PATH, ARG_LEN_L_CONFIG_PATH) ||
|
|
||||||
strncmp(arg, ARG_S_CONFIG_PATH, ARG_LEN_S_CONFIG_PATH))) {
|
|
||||||
printf("Encountered config path argument.\n");
|
printf("Encountered config path argument.\n");
|
||||||
expectConfigPath = true;
|
expectConfigPath = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -73,13 +70,10 @@ int parseArguments(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadConfigFromFile(configPath, configPathLength, &config) != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printHelp(void) {
|
void printHelp(void)
|
||||||
|
{
|
||||||
/* TODO */
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
144
yaml.h
144
yaml.h
|
|
@ -1,144 +0,0 @@
|
||||||
#ifndef YAML_H
|
|
||||||
#define YAML_H
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
YAML_TYPE_STRING, /**< A value that represents a string. */
|
|
||||||
YAML_TYPE_NUMBER, /**< A value that represents a number. */
|
|
||||||
YAML_TYPE_OBJECT, /**< A value that represents an object. */
|
|
||||||
YAML_TYPE_ARRAY, /**< A value that represents an array. */
|
|
||||||
YAML_TYPE_TRUE, /**< A value that represents true. */
|
|
||||||
YAML_TYPE_FALSE, /**< A value that represents false. */
|
|
||||||
YAML_TYPE_NULL, /**< A value that represents null. */
|
|
||||||
} yaml_type_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
void *data;
|
|
||||||
yaml_type_t type;
|
|
||||||
} yaml_value_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *data;
|
|
||||||
size_t length;
|
|
||||||
} yaml_string_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *data;
|
|
||||||
size_t length;
|
|
||||||
} yaml_number_t;
|
|
||||||
|
|
||||||
typedef struct yaml_object_field_s {
|
|
||||||
yaml_string_t *name;
|
|
||||||
yaml_value_t *value;
|
|
||||||
|
|
||||||
struct yaml_object_field_s *next;
|
|
||||||
} yaml_object_field_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
yaml_object_field_t *head;
|
|
||||||
size_t count;
|
|
||||||
} yaml_object_t;
|
|
||||||
|
|
||||||
typedef struct yaml_array_element_s {
|
|
||||||
yaml_value_t *value;
|
|
||||||
|
|
||||||
struct yaml_array_element_s *next;
|
|
||||||
} yaml_array_element_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
yaml_array_element_t *head;
|
|
||||||
size_t count;
|
|
||||||
} yaml_array_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a UTF-8 encoded string into a value object.
|
|
||||||
*
|
|
||||||
* Returns `NULL` if parsing fails.
|
|
||||||
*/
|
|
||||||
yaml_value_t *yaml_parse(const void *, size_t);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Traverse the tree to retrieve a specific sub-value from a root value.
|
|
||||||
*
|
|
||||||
* Returns `NULL` if the requested sub-value does not exist.
|
|
||||||
*/
|
|
||||||
yaml_value_t *yaml_get(const yaml_value_t *, const char *);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access a value object as a string.
|
|
||||||
*
|
|
||||||
* Returns `NULL` if the value is not a string.
|
|
||||||
*/
|
|
||||||
yaml_string_t *yaml_value_as_string(const yaml_value_t *);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access a value object as a number.
|
|
||||||
*
|
|
||||||
* Returns `NULL` if the value is not a number.
|
|
||||||
*/
|
|
||||||
yaml_number_t *yaml_value_as_number(const yaml_value_t *);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access a value object as an object.
|
|
||||||
*
|
|
||||||
* Returns `NULL` if the value is not an object.
|
|
||||||
*/
|
|
||||||
yaml_object_t *yaml_value_as_object(const yaml_value_t *);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access a value object as an array.
|
|
||||||
*
|
|
||||||
* Returns `NULL` if the value is not an array.
|
|
||||||
*/
|
|
||||||
yaml_array_t *yaml_value_as_array(const yaml_value_t *);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a string describing the most recently encountered error.
|
|
||||||
*
|
|
||||||
* Returns `NULL` if no error has been encountered.
|
|
||||||
*/
|
|
||||||
const char *yaml_error(void);
|
|
||||||
|
|
||||||
#endif /* YAML_H */
|
|
||||||
|
|
||||||
#ifdef YAML_IMPLEMENTATION
|
|
||||||
|
|
||||||
char error_message[4096];
|
|
||||||
|
|
||||||
yaml_value_t *yaml_parse(const void *content, size_t length) {
|
|
||||||
/* TODO */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
yaml_value_t *yaml_get(const yaml_value_t *root, const char *path) {
|
|
||||||
/* TODO */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
yaml_string_t *yaml_value_as_string(const yaml_value_t *value) {
|
|
||||||
/* TODO */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
yaml_number_t *yaml_value_as_number(const yaml_value_t *value) {
|
|
||||||
/* TODO */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
yaml_object_t *yaml_object_as_object(const yaml_value_t *value) {
|
|
||||||
/* TODO */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
yaml_array_t *yaml_object_as_array(const yaml_value_t *value) {
|
|
||||||
/* TODO */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *yaml_error(void) {
|
|
||||||
if (error_message[0] == '\0') return NULL;
|
|
||||||
return error_message;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* YAML_IMPLEMENTATION */
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue