summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore27
-rw-r--r--iftop.c6
-rw-r--r--ns_hash.c10
-rw-r--r--ns_hash.h11
-rw-r--r--resolver.c39
-rw-r--r--tui.h15
6 files changed, 74 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1ac7ca9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,27 @@
+*.o
+iftop
+
+Makefile
+Makefile.in
+
+aclocal.m4
+
+configure
+
+config.h
+config.h.in
+config.log
+config.status
+
+config/Makefile
+config/Makefile.in
+config/config.guess
+config/config.sub
+config/depcomp
+config/install-sh
+config/missing
+
+autom4te.cache/
+.deps/
+
+stamp-h1
diff --git a/iftop.c b/iftop.c
index a090dcf..e7f4ec2 100644
--- a/iftop.c
+++ b/iftop.c
@@ -331,6 +331,10 @@ static void handle_ip_packet(struct ip* iptr, int hw_dir)
assign_addr_pair(&ap, iptr, 0);
direction = 0;
}
+ else if(IP_V(iptr) == 6) {
+ assign_addr_pair(&ap, iptr, 0);
+ direction = 0;
+ }
/* Drop other uncertain packages. */
else
return;
@@ -713,7 +717,7 @@ void packet_init() {
if(have_hw_addr) {
fprintf(stderr, "MAC address is:");
for (i = 0; i < 6; ++i)
- fprintf(stderr, "%c%02x", i ? ':' : ' ', (unsigned int)if_hw_addr[i]);
+ fprintf(stderr, "%c%02hhx", i ? ':' : ' ', if_hw_addr[i]);
fprintf(stderr, "\n");
}
diff --git a/ns_hash.c b/ns_hash.c
index 219de95..1fdb00a 100644
--- a/ns_hash.c
+++ b/ns_hash.c
@@ -15,9 +15,9 @@
#define hash_table_size 256
int ns_hash_compare(void* a, void* b) {
- struct in6_addr* aa = (struct in6_addr*)a;
- struct in6_addr* bb = (struct in6_addr*)b;
- return IN6_ARE_ADDR_EQUAL(aa, bb);
+ struct addr_storage* aa = (struct addr_storage*)a;
+ struct addr_storage* bb = (struct addr_storage*)b;
+ return aa->af == bb->af && !memcmp(&aa->addr, &bb->addr, sizeof(aa->addr));
}
static int __inline__ hash_uint32(uint32_t n) {
@@ -29,7 +29,7 @@ static int __inline__ hash_uint32(uint32_t n) {
int ns_hash_hash(void* key) {
int hash;
- uint32_t* addr6 = (uint32_t*)((struct in6_addr *) key)->s6_addr;
+ uint32_t* addr6 = (uint32_t*) &((struct addr_storage *) key)->addr;
hash = ( hash_uint32(addr6[0])
+ hash_uint32(addr6[1])
@@ -40,7 +40,7 @@ int ns_hash_hash(void* key) {
}
void* ns_hash_copy_key(void* orig) {
- struct in6_addr* copy;
+ struct addr_storage* copy;
copy = xmalloc(sizeof *copy);
memcpy(copy, orig, sizeof *copy);
diff --git a/ns_hash.h b/ns_hash.h
index 8135d8f..bfab786 100644
--- a/ns_hash.h
+++ b/ns_hash.h
@@ -14,6 +14,17 @@
#include <arpa/inet.h>
#include "hash.h"
+struct addr_storage {
+ int af; /* AF_INET or AF_INET6 */
+ int len; /* sizeof(struct in_addr or in6_addr) */
+ union {
+ struct in_addr addr4;
+ struct in6_addr addr6;
+ } addr;
+#define as_addr4 addr.addr4
+#define as_addr6 addr.addr6
+};
+
hash_type* ns_hash_create(void);
#endif /* __NS_HASH_H_ */
diff --git a/resolver.c b/resolver.c
index adddbc1..2e662cc 100644
--- a/resolver.c
+++ b/resolver.c
@@ -25,17 +25,6 @@
#define RESOLVE_QUEUE_LENGTH 20
-struct addr_storage {
- int af; /* AF_INET or AF_INET6 */
- int len; /* sizeof(struct in_addr or in6_addr) */
- union {
- struct in_addr addr4;
- struct in6_addr addr6;
- } addr;
-#define as_addr4 addr.addr4
-#define as_addr6 addr.addr6
-};
-
struct addr_storage resolve_queue[RESOLVE_QUEUE_LENGTH];
pthread_cond_t resolver_queue_cond;
@@ -475,40 +464,34 @@ void resolve(int af, void* addr, char* result, int buflen) {
void **void_pp;
} u_hostname = { &hostname };
int added = 0;
- struct addr_storage *raddr;
+ struct addr_storage raddr;
if(options.dnsresolution == 1) {
- raddr = malloc(sizeof *raddr);
- memset(raddr, 0, sizeof *raddr);
- raddr->af = af;
- raddr->len = (af == AF_INET ? sizeof(struct in_addr)
+ memset(&raddr, 0, sizeof raddr);
+ raddr.af = af;
+ raddr.len = (af == AF_INET ? sizeof(struct in_addr)
: sizeof(struct in6_addr));
- memcpy(&raddr->addr, addr, raddr->len);
+ memcpy(&raddr.addr, addr, raddr.len);
pthread_mutex_lock(&resolver_queue_mutex);
- if(hash_find(ns_hash, raddr, u_hostname.void_pp) == HASH_STATUS_OK) {
- /* Found => already resolved, or on the queue, no need to keep
- * it around */
- free(raddr);
- }
- else {
+ if(hash_find(ns_hash, &raddr, u_hostname.void_pp) != HASH_STATUS_OK) {
hostname = xmalloc(INET6_ADDRSTRLEN);
- inet_ntop(af, &raddr->addr, hostname, INET6_ADDRSTRLEN);
+ inet_ntop(af, &raddr.addr, hostname, INET6_ADDRSTRLEN);
- hash_insert(ns_hash, raddr, hostname);
+ hash_insert(ns_hash, &raddr, hostname);
if(((head + 1) % RESOLVE_QUEUE_LENGTH) == tail) {
/* queue full */
}
else if ((af == AF_INET6)
- && (IN6_IS_ADDR_LINKLOCAL(&raddr->as_addr6)
- || IN6_IS_ADDR_SITELOCAL(&raddr->as_addr6))) {
+ && (IN6_IS_ADDR_LINKLOCAL(&raddr.as_addr6)
+ || IN6_IS_ADDR_SITELOCAL(&raddr.as_addr6))) {
/* Link-local and site-local stay numerical. */
}
else {
- resolve_queue[head] = *raddr;
+ resolve_queue[head] = raddr;
head = (head + 1) % RESOLVE_QUEUE_LENGTH;
added = 1;
}
diff --git a/tui.h b/tui.h
new file mode 100644
index 0000000..95f5bf3
--- /dev/null
+++ b/tui.h
@@ -0,0 +1,15 @@
+/*
+ * tui.h:
+ *
+ *
+ */
+
+#ifndef __TUI_H_ /* include guard */
+#define __TUI_H_
+
+void tui_print(void);
+void tui_init(void);
+void tui_loop(void);
+void tui_tick(int);
+
+#endif /* __TUI_H_ */