aboutsummaryrefslogtreecommitdiffstats
path: root/libglouglou
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-12-04 16:25:13 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-12-04 16:25:13 +0100
commit44ac0805dbc4ac5ed6a312f58a544599c2ec665d (patch)
tree0408edf9e7ede12de42322a8cb33caf0c9fa6221 /libglouglou
parentTODO reorganisation (diff)
downloadglouglou-44ac0805dbc4ac5ed6a312f58a544599c2ec665d.tar.xz
glouglou-44ac0805dbc4ac5ed6a312f58a544599c2ec665d.zip
correctly handle node names and add function node_update_name()
Diffstat (limited to 'libglouglou')
-rw-r--r--libglouglou/libggnet.c18
-rw-r--r--libglouglou/libggnet.h9
2 files changed, 22 insertions, 5 deletions
diff --git a/libglouglou/libggnet.c b/libglouglou/libggnet.c
index 7ccfa00..424ee16 100644
--- a/libglouglou/libggnet.c
+++ b/libglouglou/libggnet.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <string.h>
#include "libglouglou.h"
#include "libggnet.h"
@@ -34,7 +35,7 @@ ggnet_node_add(struct ggnet *net, struct in_addr *addr)
n = xcalloc(1, sizeof(struct ggnet_node));
n->addr.s_addr = addr->s_addr;
- n->namelen = NODENAME_WAITING;
+ n->namelen = GGNET_NODENAME_WAITING;
n->lastseen = net->time;
LIST_INSERT_HEAD(&net->node_list, n, entry);
net->node_count++;
@@ -50,7 +51,6 @@ ggnet_node_del(struct ggnet *net, struct ggnet_node *n)
gg_log_debug("ggnet_node_del: ggnet_node_del");
LIST_REMOVE(n, entry);
- free(n->name);
free(n);
net->node_count--;
}
@@ -66,6 +66,20 @@ ggnet_node_find(struct ggnet *net, struct in_addr *remote)
return NULL;
}
+void
+node_update_name(struct ggnet *net, struct ggnet_node *n, char *name, int len)
+{
+ if (!name) {
+ snprintf(n->name, sizeof(n->name), "%x", n->addr.s_addr);
+ n->namelen = sizeof(n->addr.s_addr);
+ } else {
+ if (len > sizeof(n->name))
+ len = sizeof(n->name);
+ strncpy(n->name, name, len);
+ n->namelen = len;
+ }
+}
+
struct ggnet_conn *
ggnet_conn_add(struct ggnet *net, struct in_addr *src, int src_port,
struct in_addr *dst, int dst_port, int proto, int size)
diff --git a/libglouglou/libggnet.h b/libglouglou/libggnet.h
index 228b48a..10116f2 100644
--- a/libglouglou/libggnet.h
+++ b/libglouglou/libggnet.h
@@ -10,6 +10,7 @@
#include <bsd/sys/queue.h>
#endif
+#define GGNET_DNSNAME_MAX 30
#define GGNET_CONN_FREEIDS_COUNT 65536 /* 2^16 as freeids are u_int16_t */
struct ggnet_node {
@@ -18,9 +19,9 @@ struct ggnet_node {
time_t lastseen;
int used;
short namelen;
-#define NODENAME_WAITING -1
-#define NODENAME_FAILED -2
- char *name;
+#define GGNET_NODENAME_WAITING -1
+#define GGNET_NODENAME_FAILED -2
+ char name[GGNET_DNSNAME_MAX];
};
enum ggnet_connstate {
@@ -58,6 +59,8 @@ 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 *);
struct ggnet_node *ggnet_node_find(struct ggnet *, struct in_addr *);
+void ggnet_node_update_name(struct ggnet *, struct ggnet_node *,
+ char *, int);
struct ggnet_conn *ggnet_conn_add(struct ggnet *, struct in_addr *, int,
struct in_addr *, int, int, int);
void ggnet_conn_data(struct ggnet *, struct ggnet_conn *,