summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netbytes.c33
-rw-r--r--netbytes.h10
2 files changed, 43 insertions, 0 deletions
diff --git a/netbytes.c b/netbytes.c
index 1f8433b..3a6dc0a 100644
--- a/netbytes.c
+++ b/netbytes.c
@@ -690,6 +690,7 @@ int nb_type( netbyte_store *store, int count, __NBT_TYPED **type )
//nbt = (__NBT_TYPED)store->types[count].type; //warnign? who cares
//*type = nbt;
+ #warning "Looks like real error"
*type = store->types[count].type;
return 0;
}
@@ -762,6 +763,38 @@ int nb_fread( netbyte_store *store, int fd)
return 0;
}
+
+/*
+Return:
+ 1 - looks like data are netbyte buffer
+ 0 - data isnot netbyte buffer
+*/
+int nb_check_buf(uint8_t *data, int len, int *detected_size)
+{
+ __NBT_SIZE size;
+ if (len < sizeof(__NBT_SIZE))
+ {
+ printf("if (len > sizeof(__NBT_SIZE))\n");
+ return 0;
+ }
+
+ memcpy(&size, data, sizeof(__NBT_SIZE));
+
+ if (len<size)
+ {
+ printf("if (len<size)\n");
+ return 0;
+ }
+
+ //amount of data that are netbyte in buffer
+ *detected_size = size;
+
+ return 1;
+ //TODO find start byte for data in netbyte buffer
+
+}
+
+
int nb_print(netbyte_store *store)
{
int i;
diff --git a/netbytes.h b/netbytes.h
index 6e008bc..685b68a 100644
--- a/netbytes.h
+++ b/netbytes.h
@@ -1,6 +1,10 @@
#ifndef __NETBYTES_H
#define __NETBYTES_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
@@ -167,6 +171,8 @@ int nb_count( netbyte_store *store );
int nb_type( netbyte_store *store, int count, __NBT_TYPED **type );
int nb_val( netbyte_store *store, int count, __nb_type **type );
int nb_fread( netbyte_store *store, int fd);
+/*check if data may contain full netbyte buffer*/
+int nb_check_buf(uint8_t *data, int len, int *detected_size);
//print all all values in netbyte string
int nb_print(netbyte_store *store);
@@ -188,4 +194,8 @@ void nb_tok_destroy(nb_tok_arr *arr);
int nb_parse(char *str, nb_tok_arr *arr);
+#ifdef __cplusplus
+}
+#endif
+
#endif \ No newline at end of file