summaryrefslogtreecommitdiff
path: root/src/routingTree.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/routingTree.hpp')
-rw-r--r--src/routingTree.hpp45
1 files changed, 20 insertions, 25 deletions
diff --git a/src/routingTree.hpp b/src/routingTree.hpp
index 89b7c18..a2a5312 100644
--- a/src/routingTree.hpp
+++ b/src/routingTree.hpp
@@ -11,7 +11,7 @@
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl,
+ * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl,
* Christian Pointner <satp@wirdorange.org>
*
* This file is part of Anytun.
@@ -35,30 +35,29 @@
#include "anytunError.h"
-class RoutingTree {
+class RoutingTree
+{
public:
template <class BinaryType>
- static void walk(BinaryType bytes ,RoutingTreeNode * node,u_int8_t length,u_int16_t mux)
- {
- for (int i=0; i<(length/8); i++)
- {
- if (!node->nodes_[bytes[i]])
+ static void walk(BinaryType bytes ,RoutingTreeNode* node,u_int8_t length,u_int16_t mux) {
+ for(int i=0; i<(length/8); i++) {
+ if(!node->nodes_[bytes[i]]) {
node->nodes_[bytes[i]] = new RoutingTreeNode;
+ }
node=node->nodes_[bytes[i]];
}
- if (length%8)
- {
+ if(length%8) {
unsigned char idx=0xff;
idx <<=8-(length%8);
idx &= bytes[length/8];
unsigned char maxidx=0xff;
maxidx>>=(length%8);
maxidx|=idx;
- for (unsigned char i=idx; i<=maxidx; i++)
- {
- if (!node->nodes_[i])
+ for(unsigned char i=idx; i<=maxidx; i++) {
+ if(!node->nodes_[i]) {
node->nodes_[i] = new RoutingTreeNode;
+ }
node->nodes_[i]->valid_=true;
node->nodes_[i]->mux_=mux;
}
@@ -67,25 +66,20 @@ public:
node->mux_=mux;
}
}
-
+
template <class BinaryType>
- static u_int16_t find(BinaryType bytes ,RoutingTreeNode & root )
- {
+ static u_int16_t find(BinaryType bytes ,RoutingTreeNode& root) {
bool valid=0;
u_int16_t mux=0;
- RoutingTreeNode * node = &root;
- if (root.valid_)
- {
+ RoutingTreeNode* node = &root;
+ if(root.valid_) {
mux=root.mux_;
valid=1;
}
- for (size_t level=0;level<bytes.size();level++)
- {
- if (node->nodes_[bytes[level]])
- {
+ for(size_t level=0; level<bytes.size(); level++) {
+ if(node->nodes_[bytes[level]]) {
node=node->nodes_[bytes[level]];
- if(node->valid_)
- {
+ if(node->valid_) {
mux=node->mux_;
valid=1;
}
@@ -93,8 +87,9 @@ public:
break;
}
}
- if(!valid)
+ if(!valid) {
AnytunError::throwErr() << "no route";
+ }
return mux;
}