aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-12-15 02:21:00 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-12-15 02:21:00 +0100
commit46ab5fff3d2deb3aad5a40072998a8fa7d09e875 (patch)
tree2bcdbf8840f00995130b2a890303d3cdcd7035ee
parentworking on ggsniff_dns_reverse() (diff)
downloadglouglou-46ab5fff3d2deb3aad5a40072998a8fa7d09e875.tar.xz
glouglou-46ab5fff3d2deb3aad5a40072998a8fa7d09e875.zip
remove all reference to libglouglou.
this implies adding a debug variable to struct ggnet and corresponding ggnet_debug_set()
-rw-r--r--libglouglou/libggnet.c72
-rw-r--r--libglouglou/libggnet.h2
2 files changed, 55 insertions, 19 deletions
diff --git a/libglouglou/libggnet.c b/libglouglou/libggnet.c
index 71a21cc..e6df4bd 100644
--- a/libglouglou/libggnet.c
+++ b/libglouglou/libggnet.c
@@ -1,7 +1,7 @@
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
-#include "libglouglou.h"
#include "libggnet.h"
static struct ggnet_nodegroup *nodegroup_add(struct ggnet *,
@@ -20,7 +20,11 @@ ggnet_new(int manage_connid)
struct ggnet *net;
int i;
- net = xcalloc(1, sizeof(struct ggnet));
+ net = calloc(1, sizeof(struct ggnet));
+ if (!net) {
+ printf("could not allocate ggnet\n");
+ exit(1);
+ }
net->manage_connid = manage_connid;
if (manage_connid)
for (i=0; i<GGNET_CONN_FREEIDS_COUNT-1; i++)
@@ -45,6 +49,12 @@ ggnet_grouping_set(struct ggnet *net, int set,
}
void
+ggnet_debug_set(struct ggnet *net, int set)
+{
+ net->debug = set;
+}
+
+void
ggnet_free(struct ggnet *net)
{
struct ggnet_conn *c, *ctmp;
@@ -65,9 +75,14 @@ ggnet_node_add(struct ggnet *net, struct in_addr *addr)
{
struct ggnet_node *n;
- gg_log_debug("ggnet_node_add");
+ if (net->debug)
+ printf("ggnet_node_add\n");
- n = xcalloc(1, sizeof(struct ggnet_node));
+ n = calloc(1, sizeof(struct ggnet_node));
+ if (!n) {
+ printf("could not allocate node\n");
+ exit(1);
+ }
n->addr.s_addr = addr->s_addr;
n->namelen = GGNET_NODENAME_WAITING;
n->lastseen = net->time;
@@ -82,9 +97,12 @@ ggnet_node_add(struct ggnet *net, struct in_addr *addr)
void
ggnet_node_del(struct ggnet *net, struct ggnet_node *n)
{
- if (n->used)
- gg_log_fatal("ggnet_node_del: trying to remove a used node !");
- gg_log_debug("ggnet_node_del: ggnet_node_del");
+ if (n->used) {
+ printf("FATAL: ggnet_node_del: trying to remove a used node !\n");
+ exit(1);
+ }
+ if (net->debug)
+ printf("ggnet_node_del: ggnet_node_del\n");
if (net->use_grouping)
nodegroup_unset(net, n);
@@ -148,12 +166,13 @@ ggnet_conn_add(struct ggnet *net, struct in_addr *src, int src_port,
struct ggnet_node *dstnode;
int id;
- gg_log_debug("ggnet_conn_add, %x:%d->%x:%d %d [%d]",
- src->s_addr, src_port, dst->s_addr, dst_port, proto, size);
+ if (net->debug)
+ printf("ggnet_conn_add, %x:%d->%x:%d %d [%d]\n",
+ src->s_addr, src_port, dst->s_addr, dst_port, proto, size);
if (net->manage_connid) {
if (net->conn_freeids_ptr == GGNET_CONN_FREEIDS_COUNT) {
- gg_log_warn("ggnet_conn_add: out of connection identifiers !");
+ printf("ggnet_conn_add: ERROR: out of connection identifiers !");
return NULL;
}
id = net->conn_freeids[net->conn_freeids_ptr];
@@ -175,7 +194,11 @@ ggnet_conn_add(struct ggnet *net, struct in_addr *src, int src_port,
if (dstnode->group)
dstnode->group->conn_count++;
- c = xmalloc(sizeof(struct ggnet_conn));
+ c = malloc(sizeof(struct ggnet_conn));
+ if (!c) {
+ printf("could not allocate conn\n");
+ exit(1);
+ }
c->id = id;
c->state = CONNSTATE_ESTABLISHED;
c->src = srcnode;
@@ -195,7 +218,8 @@ ggnet_conn_add(struct ggnet *net, struct in_addr *src, int src_port,
void
ggnet_conn_data(struct ggnet *net, struct ggnet_conn *c, int size, int response)
{
- gg_log_debug("ggnet_conn_data");
+ if (net->debug)
+ printf("ggnet_conn_data\n");
if (!response)
c->size = c->size + size;
@@ -209,7 +233,8 @@ ggnet_conn_data(struct ggnet *net, struct ggnet_conn *c, int size, int response)
void
ggnet_conn_del(struct ggnet *net, struct ggnet_conn *c)
{
- gg_log_debug("ggnet_conn_del");
+ if (net->debug)
+ printf("ggnet_conn_del\n");
/* UNSUPPORTED
if (c->proto == IPPROTO_TCP) {
@@ -227,8 +252,10 @@ ggnet_conn_del(struct ggnet *net, struct ggnet_conn *c)
*/
if (net->manage_connid) {
- if (net->conn_freeids_ptr == 0)
- gg_log_fatal("net->conn_freeids_ptr == 0");
+ if (net->conn_freeids_ptr == 0) {
+ printf("FATAL: net->conn_freeids_ptr == 0\n");
+ exit(1);
+ }
net->conn_freeids_ptr--;
net->conn_freeids[net->conn_freeids_ptr] = c->id;
}
@@ -342,7 +369,11 @@ nodegroup_add(struct ggnet *net, enum ggnet_grouptype type, void *param,
{
struct ggnet_nodegroup *group;
- group = xcalloc(1, sizeof(struct ggnet_nodegroup));
+ group = calloc(1, sizeof(struct ggnet_nodegroup));
+ if (!group) {
+ printf("could not allocate nodegroup\n");
+ exit(1);
+ }
group->type = type;
if (parent) {
group->parent = parent;
@@ -370,9 +401,12 @@ nodegroup_add(struct ggnet *net, enum ggnet_grouptype type, void *param,
static void
nodegroup_del(struct ggnet *net, struct ggnet_nodegroup *group)
{
- if (group->node_count || group->conn_count)
- gg_log_fatal("ggnet_nodegroup_del: trying to remove a used group !");
- gg_log_debug("ggnet_nodegroup_del");
+ if (group->node_count || group->conn_count) {
+ printf("FATAL: ggnet_nodegroup_del: trying to remove a used group !\n");
+ exit(1);
+ }
+ if (net->debug)
+ printf("ggnet_nodegroup_del\n");
net->cb_delgroup(net, group);
if (group->parent) {
diff --git a/libglouglou/libggnet.h b/libglouglou/libggnet.h
index 7eb14a8..11d3534 100644
--- a/libglouglou/libggnet.h
+++ b/libglouglou/libggnet.h
@@ -84,12 +84,14 @@ struct ggnet {
void (*cb_addgroup)(struct ggnet *, struct ggnet_nodegroup *, struct ggnet_nodegroup *);
void (*cb_delgroup)(struct ggnet *, struct ggnet_nodegroup *);
time_t time;
+ int debug;
};
struct ggnet *ggnet_new(int);
void ggnet_grouping_set(struct ggnet *, int,
void (*cb_addgroup)(struct ggnet *, struct ggnet_nodegroup *, struct ggnet_nodegroup *),
void (*cb_delgroup)(struct ggnet *, struct ggnet_nodegroup *));
+void ggnet_debug_set(struct ggnet *, int);
void ggnet_free(struct ggnet *);
struct ggnet_node *ggnet_node_add(struct ggnet *, struct in_addr *);
void ggnet_node_del(struct ggnet *, struct ggnet_node *);