summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h2
-rw-r--r--examples/c-json-stdout/c-json-stdout.c4
-rw-r--r--nDPId.c10
-rw-r--r--nDPIsrvd.c19
4 files changed, 19 insertions, 16 deletions
diff --git a/config.h b/config.h
index aaca0fac9..d1f744b0b 100644
--- a/config.h
+++ b/config.h
@@ -6,6 +6,8 @@
#define DISTRIBUTOR_HOST "127.0.0.1"
#define DISTRIBUTOR_PORT 7000
+#define NETWORK_BUFFER_MAX_SIZE 8192
+
/* nDPId default config options */
#define nDPId_MAX_FLOW_ROOTS_PER_THREAD 2048
#define nDPId_MAX_IDLE_FLOWS_PER_THREAD 64
diff --git a/examples/c-json-stdout/c-json-stdout.c b/examples/c-json-stdout/c-json-stdout.c
index c58ef6907..ff84a6411 100644
--- a/examples/c-json-stdout/c-json-stdout.c
+++ b/examples/c-json-stdout/c-json-stdout.c
@@ -16,7 +16,7 @@ int main(void)
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in remote_addr = {};
socklen_t remote_addrlen = sizeof(remote_addr);
- uint8_t buf[BUFSIZ];
+ uint8_t buf[NETWORK_BUFFER_MAX_SIZE];
//size_t buf_used = 0;
//unsigned long long int buf_wanted = 0;
@@ -45,7 +45,7 @@ int main(void)
break;
}
- printf("RECV[%zd]: '%.*s'\n", bytes_read, (int) bytes_read, buf);
+ printf("RECV[%zd]: '%.*s'\n\n", bytes_read, (int) bytes_read, buf);
}
return 0;
diff --git a/nDPId.c b/nDPId.c
index ea8b293fb..350a747e3 100644
--- a/nDPId.c
+++ b/nDPId.c
@@ -267,7 +267,7 @@ static struct nDPId_workflow * init_workflow(char const * const file_or_device)
ndpi_set_protocol_detection_bitmask2(workflow->ndpi_struct, &protos);
ndpi_finalize_initalization(workflow->ndpi_struct);
- if (ndpi_init_serializer_ll(&workflow->ndpi_serializer, ndpi_serialization_format_json, BUFSIZ) != 1)
+ if (ndpi_init_serializer_ll(&workflow->ndpi_serializer, ndpi_serialization_format_json, NETWORK_BUFFER_MAX_SIZE) != 1)
{
return NULL;
}
@@ -671,10 +671,10 @@ static void send_to_json_sink(struct nDPId_reader_thread * const reader_thread,
struct nDPId_workflow * const workflow = reader_thread->workflow;
int saved_errno;
int s_ret;
- char newline_json_str[BUFSIZ];
+ char newline_json_str[NETWORK_BUFFER_MAX_SIZE];
s_ret =
- snprintf(newline_json_str, sizeof(newline_json_str), "%zu%.*s\n", json_str_len, (int)json_str_len, json_str);
+ snprintf(newline_json_str, sizeof(newline_json_str), "%zu%.*s", json_str_len, (int)json_str_len, json_str);
if (s_ret < 0 || s_ret > (int)sizeof(newline_json_str))
{
syslog(LOG_DAEMON | LOG_ERR,
@@ -843,7 +843,7 @@ static void jsonize_packet_event(struct nDPId_reader_thread * const reader_threa
jsonize_basic(reader_thread);
size_t base64_data_len = base64_out_len(header->caplen);
- char base64_data[BUFSIZ];
+ char base64_data[NETWORK_BUFFER_MAX_SIZE];
if (ndpi_serialize_string_boolean(&workflow->ndpi_serializer,
"pkt_oversize",
base64_data_len > sizeof(base64_data)) != 0 ||
@@ -894,7 +894,7 @@ static void vjsonize_basic_eventf(struct nDPId_reader_thread * const reader_thre
{
uint8_t got_jsonkey = 0;
uint8_t is_long_long = 0;
- char json_key[BUFSIZ];
+ char json_key[NETWORK_BUFFER_MAX_SIZE];
uint32_t format_index = 0;
while (*format)
diff --git a/nDPIsrvd.c b/nDPIsrvd.c
index 3996e2c26..61b857c8a 100644
--- a/nDPIsrvd.c
+++ b/nDPIsrvd.c
@@ -25,7 +25,7 @@ struct remote_desc
{
enum ev_type type;
int fd;
- uint8_t buf[BUFSIZ];
+ uint8_t buf[NETWORK_BUFFER_MAX_SIZE];
size_t buf_used;
unsigned long long int buf_wanted;
union {
@@ -367,18 +367,19 @@ int main(void)
}
if ((uint8_t *)json_str_start == current->buf)
{
- current->buf_used = 0;
- current->buf_wanted = 0;
syslog(LOG_DAEMON | LOG_ERR,
"Missing size before JSON string: %.*s",
- (int) current->buf_wanted, current->buf);
+ (int) current->buf_used, current->buf);
+ current->buf_used = 0;
+ current->buf_wanted = 0;
continue;
}
- if (current->buf_wanted > BUFSIZ)
+ if (current->buf_wanted > sizeof(current->buf))
{
+ syslog(LOG_DAEMON | LOG_ERR, "BUG: JSON string too big: %llu > %zu",
+ current->buf_wanted, sizeof(current->buf));
current->buf_used = 0;
current->buf_wanted = 0;
- syslog(LOG_DAEMON | LOG_ERR, "BUG: JSON string too big: %llu > %d", current->buf_wanted, BUFSIZ);
continue;
}
}
@@ -390,10 +391,10 @@ int main(void)
/* after buffering complete, last character should always be a '}' (end of object) */
if (current->buf[current->buf_wanted - 1] != '}')
{
- current->buf_used = 0;
- current->buf_wanted = 0;
syslog(LOG_DAEMON | LOG_ERR, "Invalid JSON string: %.*s",
(int) current->buf_wanted, current->buf);
+ current->buf_used = 0;
+ current->buf_wanted = 0;
continue;
}
@@ -430,7 +431,7 @@ int main(void)
}
memmove(current->buf, current->buf + current->buf_wanted, current->buf_used - current->buf_wanted);
- current->buf_used = 0;
+ current->buf_used -= current->buf_wanted;
current->buf_wanted = 0;
}
}