Commit 0bbf593e authored by Bruno Randolf's avatar Bruno Randolf

code cosmetics and smaller fixes

parent 9e67cdd2
This diff is collapsed.
...@@ -53,7 +53,6 @@ static void update_statistics(struct packet_info* pkt); ...@@ -53,7 +53,6 @@ static void update_statistics(struct packet_info* pkt);
struct packet_info current_packet; struct packet_info current_packet;
/* no, i dont want to implement a linked list now */ /* no, i dont want to implement a linked list now */
struct node_info nodes[MAX_NODES]; struct node_info nodes[MAX_NODES];
struct essid_info essids[MAX_ESSIDS]; struct essid_info essids[MAX_ESSIDS];
struct split_info splits; struct split_info splits;
...@@ -67,6 +66,7 @@ struct config conf = { ...@@ -67,6 +66,7 @@ struct config conf = {
static int mon; /* monitoring socket */ static int mon; /* monitoring socket */
int int
main(int argc, char** argv) main(int argc, char** argv)
{ {
...@@ -98,41 +98,41 @@ main(int argc, char** argv) ...@@ -98,41 +98,41 @@ main(int argc, char** argv)
{ {
handle_user_input(); handle_user_input();
if (!conf.paused && len != -1) { if (conf.paused || len == -1) {
/* no packet received or paused: just wait 100ms */
usleep(100000);
continue;
}
#if DO_DEBUG #if DO_DEBUG
dump_packet(buffer, len); dump_packet(buffer, len);
#endif #endif
memset(&current_packet,0,sizeof(current_packet)); memset(&current_packet,0,sizeof(current_packet));
if (!parse_packet(buffer, len)) { if (!parse_packet(buffer, len)) {
DEBUG("parsing failed\n"); DEBUG("parsing failed\n");
continue; continue;
} }
if (filter_packet(&current_packet))
continue;
n = node_update(&current_packet);
update_history(&current_packet); if (filter_packet(&current_packet))
update_statistics(&current_packet); continue;
check_ibss_split(&current_packet, n); n = node_update(&current_packet);
if (conf.rport) { update_history(&current_packet);
net_send_packet(); update_statistics(&current_packet);
continue; check_ibss_split(&current_packet, n);
}
if (conf.rport) {
net_send_packet();
continue;
}
#if !DO_DEBUG #if !DO_DEBUG
update_display(&current_packet, n); update_display(&current_packet, n);
#endif #endif
}
else
usleep(100000);
} }
return 0; return 0;
} }
static int static int
init_packet_socket(char* devname) init_packet_socket(char* devname)
{ {
...@@ -140,7 +140,6 @@ init_packet_socket(char* devname) ...@@ -140,7 +140,6 @@ init_packet_socket(char* devname)
int fd; int fd;
int ifindex; int ifindex;
/* an alternative could be to use the pcap library */
fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (fd < 0) if (fd < 0)
err(1, "could not create socket"); err(1, "could not create socket");
...@@ -164,22 +163,6 @@ init_packet_socket(char* devname) ...@@ -164,22 +163,6 @@ init_packet_socket(char* devname)
} }
#if 0
static void
device_address(int fd, const char *if_name)
{
struct ifreq req;
strncpy(req.ifr_name, if_name, IFNAMSIZ);
req.ifr_addr.sa_family = AF_INET;
ioctl(fd, SIOCGIFHWADDR, &req);
// ioctl(fd, SIOCGIFADDR, &req);
DEBUG("hw %s\n", ether_sprintf((const unsigned char *)&req.ifr_hwaddr.sa_data));
}
#endif
static int static int
device_index(int fd, const char *if_name) device_index(int fd, const char *if_name)
{ {
...@@ -231,7 +214,7 @@ device_promisc(int fd, const char *if_name, int on) ...@@ -231,7 +214,7 @@ device_promisc(int fd, const char *if_name, int on)
static int static int
device_get_arptype(int fd, const char *device) device_get_arptype(int fd, const char *device)
{ {
struct ifreq ifr; struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr)); memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
...@@ -286,7 +269,7 @@ get_options(int argc, char** argv) ...@@ -286,7 +269,7 @@ get_options(int argc, char** argv)
case 'e': case 'e':
conf.do_filter = 1; conf.do_filter = 1;
convert_string_to_mac(optarg, conf.filtermac); convert_string_to_mac(optarg, conf.filtermac);
printf("%s\n",ether_sprintf(conf.filtermac)); printf("%s\n", ether_sprintf(conf.filtermac));
break; break;
case 'h': case 'h':
default: default:
...@@ -297,6 +280,7 @@ get_options(int argc, char** argv) ...@@ -297,6 +280,7 @@ get_options(int argc, char** argv)
} }
} }
void void
finish_all(int sig) finish_all(int sig)
{ {
...@@ -311,6 +295,7 @@ finish_all(int sig) ...@@ -311,6 +295,7 @@ finish_all(int sig)
exit(0); exit(0);
} }
static void static void
copy_nodeinfo(struct node_info* n, struct packet_info* p) copy_nodeinfo(struct node_info* n, struct packet_info* p)
{ {
...@@ -332,8 +317,9 @@ copy_nodeinfo(struct node_info* n, struct packet_info* p) ...@@ -332,8 +317,9 @@ copy_nodeinfo(struct node_info* n, struct packet_info* p)
n->olsr_count++; n->olsr_count++;
if (p->wlan_bssid[0] != 0xff && if (p->wlan_bssid[0] != 0xff &&
! (p->wlan_bssid[0] == 0 && p->wlan_bssid[1] == 0 && p->wlan_bssid[2] == 0 && ! (p->wlan_bssid[0] == 0 && p->wlan_bssid[1] == 0 && p->wlan_bssid[2] == 0 &&
p->wlan_bssid[3] == 0 && p->wlan_bssid[4] == 0 && p->wlan_bssid[5] == 0)) p->wlan_bssid[3] == 0 && p->wlan_bssid[4] == 0 && p->wlan_bssid[5] == 0)) {
memcpy(n->wlan_bssid, p->wlan_bssid, 6); memcpy(n->wlan_bssid, p->wlan_bssid, 6);
}
if ((p->wlan_type & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && if ((p->wlan_type & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
(p->wlan_type & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) { (p->wlan_type & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
n->tsfl = *(unsigned long*)(&p->wlan_tsf[0]); n->tsfl = *(unsigned long*)(&p->wlan_tsf[0]);
...@@ -350,20 +336,21 @@ copy_nodeinfo(struct node_info* n, struct packet_info* p) ...@@ -350,20 +336,21 @@ copy_nodeinfo(struct node_info* n, struct packet_info* p)
n->channel = p->wlan_channel; n->channel = p->wlan_channel;
} }
static int static int
node_update(struct packet_info* pkt) node_update(struct packet_info* pkt)
{ {
int i; int i;
if (pkt->wlan_src[0] == 0 && pkt->wlan_src[1] == 0 && pkt->wlan_src[2] == 0 && if (pkt->wlan_src[0] == 0 && pkt->wlan_src[1] == 0 && pkt->wlan_src[2] == 0 &&
pkt->wlan_src[3] == 0 && pkt->wlan_src[4] == 0 && pkt->wlan_src[5] == 0) pkt->wlan_src[3] == 0 && pkt->wlan_src[4] == 0 && pkt->wlan_src[5] == 0) {
return -1; return -1;
}
for (i=0;i<MAX_NODES;i++) { for (i = 0; i < MAX_NODES; i++) {
if (nodes[i].status == 1) { if (nodes[i].status == 1) {
/* check existing node */ /* check existing node */
if (memcmp(pkt->wlan_src, nodes[i].last_pkt.wlan_src, 6) == 0) { if (memcmp(pkt->wlan_src, nodes[i].last_pkt.wlan_src, 6) == 0) {
//wprintw(list_win,"found");
copy_nodeinfo(&nodes[i], pkt); copy_nodeinfo(&nodes[i], pkt);
return i; return i;
} }
...@@ -396,7 +383,7 @@ check_ibss_split(struct packet_info* pkt, int pkt_node) ...@@ -396,7 +383,7 @@ check_ibss_split(struct packet_info* pkt, int pkt_node)
DEBUG("bssid %s\n", ether_sprintf(pkt->wlan_bssid)); DEBUG("bssid %s\n", ether_sprintf(pkt->wlan_bssid));
/* find essid */ /* find essid */
for (i=0; i<MAX_ESSIDS; i++) { for (i = 0; i < MAX_ESSIDS; i++) {
if (essids[i].num_nodes == 0) { if (essids[i].num_nodes == 0) {
/* unused entry */ /* unused entry */
break; break;
...@@ -409,33 +396,33 @@ check_ibss_split(struct packet_info* pkt, int pkt_node) ...@@ -409,33 +396,33 @@ check_ibss_split(struct packet_info* pkt, int pkt_node)
} }
/* find node if already recorded */ /* find node if already recorded */
for (n=0; n<essids[i].num_nodes && n<MAX_NODES; n++) { for (n = 0; n < essids[i].num_nodes && n < MAX_NODES; n++) {
if (essids[i].nodes[n] == pkt_node) { if (essids[i].nodes[n] == pkt_node) {
DEBUG("SPLIT node found %d\n", n); DEBUG("SPLIT node found %d\n", n);
break; break;
} }
} }
DEBUG("SPLIT at essid %d count %d node %d\n",i, essids[i].num_nodes, n); DEBUG("SPLIT at essid %d count %d node %d\n", i, essids[i].num_nodes, n);
/* new essid */ /* new essid */
if (essids[i].num_nodes==0) { if (essids[i].num_nodes == 0) {
DEBUG("SPLIT new essid '%s'\n",pkt->wlan_essid); DEBUG("SPLIT new essid '%s'\n", pkt->wlan_essid);
strncpy(essids[i].essid, pkt->wlan_essid, MAX_ESSID_LEN); strncpy(essids[i].essid, pkt->wlan_essid, MAX_ESSID_LEN);
} }
/* new node */ /* new node */
if (essids[i].num_nodes==0 || essids[i].nodes[n] != pkt_node) { if (essids[i].num_nodes == 0 || essids[i].nodes[n] != pkt_node) {
DEBUG("SPLIT recorded new node nr %d %d %s\n", n, pkt_node, DEBUG("SPLIT recorded new node nr %d %d %s\n", n, pkt_node,
ether_sprintf(pkt->wlan_src) ); ether_sprintf(pkt->wlan_src) );
essids[i].nodes[n] = pkt_node; essids[i].nodes[n] = pkt_node;
essids[i].num_nodes = n+1; essids[i].num_nodes = n + 1;
nodes[pkt_node].essid = i; nodes[pkt_node].essid = i;
} }
/* check for split */ /* check for split */
essids[i].split = 0; essids[i].split = 0;
for (n=0; n<essids[i].num_nodes && n<MAX_NODES; n++) { for (n = 0; n < essids[i].num_nodes && n < MAX_NODES; n++) {
node = &nodes[essids[i].nodes[n]]; node = &nodes[essids[i].nodes[n]];
DEBUG("SPLIT %d. node %d src %s", n, DEBUG("SPLIT %d. node %d src %s", n,
essids[i].nodes[n], ether_sprintf(node->last_pkt.wlan_src)); essids[i].nodes[n], ether_sprintf(node->last_pkt.wlan_src));
...@@ -444,17 +431,15 @@ check_ibss_split(struct packet_info* pkt, int pkt_node) ...@@ -444,17 +431,15 @@ check_ibss_split(struct packet_info* pkt, int pkt_node)
if (node->wlan_mode == WLAN_MODE_AP) if (node->wlan_mode == WLAN_MODE_AP)
continue; continue;
if (last_bssid && memcmp(last_bssid,node->wlan_bssid,6) != 0) { if (last_bssid && memcmp(last_bssid, node->wlan_bssid, 6) != 0) {
essids[i].split = 1; essids[i].split = 1;
//XXX count number of different bssids DEBUG("SPLIT *** DETECTED!!!\n");
DEBUG("SPLIT *** DETECTED!!! %d different bssids\n", essids[i].split);
} }
last_bssid = node->wlan_bssid; last_bssid = node->wlan_bssid;
} }
/* if a split occurred on this essid, record it */ /* if a split occurred on this essid, record it */
//XXX record a list of all split essids if (essids[i].split > 0) {
if (essids[i].split>0) {
DEBUG("SPLIT *** new record %d\n", i); DEBUG("SPLIT *** new record %d\n", i);
splits.count = 1; splits.count = 1;
splits.essid[0] = i; splits.essid[0] = i;
...@@ -466,9 +451,10 @@ check_ibss_split(struct packet_info* pkt, int pkt_node) ...@@ -466,9 +451,10 @@ check_ibss_split(struct packet_info* pkt, int pkt_node)
static int static int
filter_packet(struct packet_info* pkt) { filter_packet(struct packet_info* pkt)
{
//TODO add filter for packet types: OLSR, BEACON, CONTROL //TODO add filter for packet types: OLSR, BEACON, CONTROL
return (conf.do_filter && 0 != memcmp(current_packet.wlan_src, conf.filtermac, sizeof(conf.filtermac))); return (conf.do_filter && memcmp(current_packet.wlan_src, conf.filtermac, sizeof(conf.filtermac)) != 0);
} }
...@@ -491,7 +477,7 @@ static void ...@@ -491,7 +477,7 @@ static void
update_statistics(struct packet_info* p) { update_statistics(struct packet_info* p) {
stats.packets++; stats.packets++;
stats.bytes += p->len; stats.bytes += p->len;
if (p->rate >= 0 && p->rate < MAX_RATES) { if (p->rate > 0 && p->rate < MAX_RATES) {
stats.airtimes += p->len / p->rate; stats.airtimes += p->len / p->rate;
stats.packets_per_rate[p->rate]++; stats.packets_per_rate[p->rate]++;
stats.bytes_per_rate[p->rate] += p->len; stats.bytes_per_rate[p->rate] += p->len;
...@@ -499,7 +485,7 @@ update_statistics(struct packet_info* p) { ...@@ -499,7 +485,7 @@ update_statistics(struct packet_info* p) {
if (p->wlan_type >= 0 && p->wlan_type < MAX_FSTYPE) { if (p->wlan_type >= 0 && p->wlan_type < MAX_FSTYPE) {
stats.packets_per_type[p->wlan_type]++; stats.packets_per_type[p->wlan_type]++;
stats.bytes_per_type[p->wlan_type] += p->len; stats.bytes_per_type[p->wlan_type] += p->len;
if (p->rate >= 0 && p->rate < MAX_RATES) if (p->rate > 0 && p->rate < MAX_RATES)
stats.airtime_per_type[p->wlan_type] += p->len / p->rate; stats.airtime_per_type[p->wlan_type] += p->len / p->rate;
} }
} }
...@@ -26,13 +26,13 @@ ...@@ -26,13 +26,13 @@
#define DO_DEBUG 0 #define DO_DEBUG 0
#endif #endif
#define MAX_NODES 255 #define MAX_NODES 255
#define MAX_ESSIDS 255 #define MAX_ESSIDS 255
#define MAX_BSSIDS 255 #define MAX_BSSIDS 255
#define MAX_HISTORY 255 #define MAX_HISTORY 255
#define MAX_ESSID_LEN 255 #define MAX_ESSID_LEN 255
#define MAX_RATES 55 /* 54M + 1 for array index */ #define MAX_RATES 55 /* 54M + 1 for array index */
#define MAX_FSTYPE 0xff #define MAX_FSTYPE 0xff
#define PKT_TYPE_IP 0x08 #define PKT_TYPE_IP 0x08
#define PKT_TYPE_OLSR 0x10 #define PKT_TYPE_OLSR 0x10
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#define WLAN_MODE_IBSS 0x02 #define WLAN_MODE_IBSS 0x02
#define WLAN_MODE_STA 0x04 #define WLAN_MODE_STA 0x04
#define NODE_TIMEOUT 60 /* seconds */ #define NODE_TIMEOUT 60 /* seconds */
struct packet_info { struct packet_info {
int pkt_types; int pkt_types;
...@@ -140,7 +140,7 @@ struct config { ...@@ -140,7 +140,7 @@ struct config {
int node_timeout; int node_timeout;
unsigned char filtermac[6]; unsigned char filtermac[6];
/* this isnt exactly config, but... */ /* this isn't exactly config, but wtf... */
int arphrd; // the device ARP type int arphrd; // the device ARP type
int paused; int paused;
int do_filter; int do_filter;
......
...@@ -106,13 +106,13 @@ parse_prism_header(unsigned char** buf, int len) ...@@ -106,13 +106,13 @@ parse_prism_header(unsigned char** buf, int len)
* let's make sure here that SNR is always positive, so we * let's make sure here that SNR is always positive, so we
* don't have do handle special cases later * don't have do handle special cases later
*/ */
if (((int)ph->noise.data)<0) { if (((int)ph->noise.data) < 0) {
/* new madwifi */ /* new madwifi */
current_packet.signal = ph->signal.data; current_packet.signal = ph->signal.data;
current_packet.noise = ph->noise.data; current_packet.noise = ph->noise.data;
current_packet.snr = ph->rssi.data; current_packet.snr = ph->rssi.data;
} }
else if (((int)ph->rssi.data)<0) { else if (((int)ph->rssi.data) < 0) {
/* broadcom hack */ /* broadcom hack */
current_packet.signal = ph->rssi.data; current_packet.signal = ph->rssi.data;
current_packet.noise = -95; current_packet.noise = -95;
...@@ -126,12 +126,12 @@ parse_prism_header(unsigned char** buf, int len) ...@@ -126,12 +126,12 @@ parse_prism_header(unsigned char** buf, int len)
} }
/* just in case...*/ /* just in case...*/
if (current_packet.snr<0) if (current_packet.snr < 0)
current_packet.snr = -current_packet.snr; current_packet.snr = -current_packet.snr;
if (current_packet.snr>99) if (current_packet.snr > 99)
current_packet.snr = 99; current_packet.snr = 99;
current_packet.rate = ph->rate.data/2; current_packet.rate = ph->rate.data / 2;
DEBUG("devname: %s\n", ph->devname); DEBUG("devname: %s\n", ph->devname);
DEBUG("signal: %d -> %d\n", ph->signal.data, current_packet.signal); DEBUG("signal: %d -> %d\n", ph->signal.data, current_packet.signal);
...@@ -167,19 +167,20 @@ parse_radiotap_header(unsigned char** buf, int len) ...@@ -167,19 +167,20 @@ parse_radiotap_header(unsigned char** buf, int len)
DEBUG("%08x\n", present); DEBUG("%08x\n", present);
/* check for header extension - ignore for now, just advance current position */ /* check for header extension - ignore for now, just advance current position */
while (present & 0x80000000 && b-*buf < rh->it_len) { while (present & 0x80000000 && b - *buf < rh->it_len) {
DEBUG("extension\n"); DEBUG("extension\n");
b = b + 4; b = b + 4;
present = *(__le32*)b; present = *(__le32*)b;
} }
present = rh->it_present; // in case it move present = rh->it_present; // in case it moved
/* radiotap bitmap has 32 bit, but we are only interrested until /* radiotap bitmap has 32 bit, but we are only interrested until
* bit 12 (IEEE80211_RADIOTAP_DB_ANTSIGNAL) => i<13 */ * bit 12 (IEEE80211_RADIOTAP_DB_ANTSIGNAL) => i<13 */
for (i=0; i<13 && b-*buf < rh->it_len; i++) { for (i = 0; i < 13 && b - *buf < rh->it_len; i++) {
if ((present >> i) & 1) { if ((present >> i) & 1) {
DEBUG("1"); DEBUG("1");
switch (i) { switch (i) {
/* just ignore the following (advance position only): */ /* just ignore the following (advance position only) */
case IEEE80211_RADIOTAP_TSFT: case IEEE80211_RADIOTAP_TSFT:
DEBUG("[+8]"); DEBUG("[+8]");
b = b + 8; b = b + 8;
...@@ -209,7 +210,7 @@ parse_radiotap_header(unsigned char** buf, int len) ...@@ -209,7 +210,7 @@ parse_radiotap_header(unsigned char** buf, int len)
/* we are only interrested in these: */ /* we are only interrested in these: */
case IEEE80211_RADIOTAP_RATE: case IEEE80211_RADIOTAP_RATE:
DEBUG("[rate %0x]", *b); DEBUG("[rate %0x]", *b);
current_packet.rate = (*b)/2; current_packet.rate = (*b) / 2;
b++; b++;
break; break;
case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
...@@ -234,7 +235,7 @@ parse_radiotap_header(unsigned char** buf, int len) ...@@ -234,7 +235,7 @@ parse_radiotap_header(unsigned char** buf, int len)
} }
} }
if (current_packet.snr>99) if (current_packet.snr > 99)
current_packet.snr = 99; current_packet.snr = 99;
DEBUG("\nrate: %d\n", current_packet.rate); DEBUG("\nrate: %d\n", current_packet.rate);
...@@ -311,7 +312,7 @@ parse_80211_header(unsigned char** buf, int len) ...@@ -311,7 +312,7 @@ parse_80211_header(unsigned char** buf, int len)
case IEEE80211_STYPE_PROBE_RESP: case IEEE80211_STYPE_PROBE_RESP:
memcpy(current_packet.wlan_tsf, &whm->u.beacon.timestamp, 8); memcpy(current_packet.wlan_tsf, &whm->u.beacon.timestamp, 8);
ieee802_11_parse_elems(whm->u.beacon.variable, ieee802_11_parse_elems(whm->u.beacon.variable,
len - sizeof(struct ieee80211_mgmt) - 4, &current_packet); len - sizeof(struct ieee80211_mgmt) - 4 /* FCS */, &current_packet);
DEBUG("ESSID %s \n", current_packet.wlan_essid ); DEBUG("ESSID %s \n", current_packet.wlan_essid );
DEBUG("CHAN %d \n", current_packet.wlan_channel ); DEBUG("CHAN %d \n", current_packet.wlan_channel );
if (whm->u.beacon.capab_info & WLAN_CAPABILITY_IBSS) if (whm->u.beacon.capab_info & WLAN_CAPABILITY_IBSS)
...@@ -323,22 +324,25 @@ parse_80211_header(unsigned char** buf, int len) ...@@ -323,22 +324,25 @@ parse_80211_header(unsigned char** buf, int len)
break; break;
} }
if (sa != NULL) if (sa != NULL) {
memcpy(current_packet.wlan_src, sa, 6); memcpy(current_packet.wlan_src, sa, 6);
if (da != NULL)
memcpy(current_packet.wlan_dst, da, 6);
if (bssid!=NULL)
memcpy(current_packet.wlan_bssid, bssid, 6);
if (sa != NULL)
DEBUG("SA %s\n", ether_sprintf(sa)); DEBUG("SA %s\n", ether_sprintf(sa));
if (da != NULL) }
if (da != NULL) {
memcpy(current_packet.wlan_dst, da, 6);
DEBUG("DA %s\n", ether_sprintf(da)); DEBUG("DA %s\n", ether_sprintf(da));
if (bssid!=NULL) }
if (bssid!=NULL) {
memcpy(current_packet.wlan_bssid, bssid, 6);
DEBUG("BSSID %s\n", ether_sprintf(bssid)); DEBUG("BSSID %s\n", ether_sprintf(bssid));
}
*buf = *buf + hdrlen; /* only data frames contain more info, otherwise stop parsing */
return len - hdrlen; if ((current_packet.wlan_type & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) {
*buf = *buf + hdrlen;
return len - hdrlen;
}
return 0;
} }
...@@ -352,11 +356,9 @@ parse_ip_header(unsigned char** buf, int len) ...@@ -352,11 +356,9 @@ parse_ip_header(unsigned char** buf, int len)
/* check type in LLC header */ /* check type in LLC header */
*buf = *buf + 6; *buf = *buf + 6;
if (**buf != 0x08) /* not IP */ if (**buf != 0x08) /* not IP */
return -1; return -1;
(*buf)++; (*buf)++;
if (**buf != 0x00) if (**buf != 0x00)
return -1; return -1;
(*buf)++; (*buf)++;
...@@ -376,8 +378,8 @@ parse_ip_header(unsigned char** buf, int len) ...@@ -376,8 +378,8 @@ parse_ip_header(unsigned char** buf, int len)
if (ih->protocol != 17) /* UDP */ if (ih->protocol != 17) /* UDP */
return 0; return 0;
*buf = *buf + ih->ihl*4; *buf = *buf + ih->ihl * 4;
return len - ih->ihl*4; return len - ih->ihl * 4;
} }
...@@ -423,20 +425,20 @@ parse_olsr_packet(unsigned char** buf, int len) ...@@ -423,20 +425,20 @@ parse_olsr_packet(unsigned char** buf, int len)
current_packet.pkt_types |= PKT_TYPE_OLSR_LQ; current_packet.pkt_types |= PKT_TYPE_OLSR_LQ;
if (msgtype == HELLO_MESSAGE) { if (msgtype == HELLO_MESSAGE) {
number = (ntohs(oh->olsr_msg[0].olsr_msgsize)-12) / sizeof(struct hellomsg); number = (ntohs(oh->olsr_msg[0].olsr_msgsize) - 12) / sizeof(struct hellomsg);
DEBUG("HELLO %d\n", number); DEBUG("HELLO %d\n", number);
current_packet.olsr_neigh = number; current_packet.olsr_neigh = number;
} }
if (msgtype == LQ_HELLO_MESSAGE) { if (msgtype == LQ_HELLO_MESSAGE) {
number = (ntohs(oh->olsr_msg[0].olsr_msgsize)-16) / 12; number = (ntohs(oh->olsr_msg[0].olsr_msgsize) - 16) / 12;
DEBUG("LQ_HELLO %d (%d)\n", number, (ntohs(oh->olsr_msg[0].olsr_msgsize)-16)); DEBUG("LQ_HELLO %d (%d)\n", number, (ntohs(oh->olsr_msg[0].olsr_msgsize) - 16));
current_packet.olsr_neigh = number; current_packet.olsr_neigh = number;
} }
#if 0
/* XXX: tc messages are relayed. so we would have to find the originating node (IP) /* XXX: tc messages are relayed. so we would have to find the originating node (IP)
and store the information there. skip for now */ and store the information there. skip for now */
/*
if (msgtype == TC_MESSAGE) { if (msgtype == TC_MESSAGE) {
number = (ntohs(oh->olsr_msg[0].olsr_msgsize)-12) / sizeof(struct tcmsg); number = (ntohs(oh->olsr_msg[0].olsr_msgsize)-12) / sizeof(struct tcmsg);
DEBUG("TC %d\n", number); DEBUG("TC %d\n", number);
...@@ -448,21 +450,22 @@ parse_olsr_packet(unsigned char** buf, int len) ...@@ -448,21 +450,22 @@ parse_olsr_packet(unsigned char** buf, int len)
DEBUG("LQ_TC %d (%d)\n", number, (ntohs(oh->olsr_msg[0].olsr_msgsize)-16)); DEBUG("LQ_TC %d (%d)\n", number, (ntohs(oh->olsr_msg[0].olsr_msgsize)-16));
current_packet.olsr_tc = number; current_packet.olsr_tc = number;
} }
*/ #endif
if (msgtype == HNA_MESSAGE) { if (msgtype == HNA_MESSAGE) {
/* same here, but we assume that nodes which relay a HNA with a default gateway /* same here, but we assume that nodes which relay a HNA with a default gateway
know how to contact the gw, so have a indirect connection to a GW themselves */ know how to contact the gw, so have a indirect connection to a GW themselves */
struct hnapair* hna; struct hnapair* hna;
number = (ntohs(oh->olsr_msg[0].olsr_msgsize)-12) / sizeof(struct hnapair); number = (ntohs(oh->olsr_msg[0].olsr_msgsize) - 12) / sizeof(struct hnapair);
DEBUG("HNA NUM: %d (%d) [%d]\n", number, ntohs(oh->olsr_msg[0].olsr_msgsize),sizeof(struct hnapair) ); DEBUG("HNA NUM: %d (%d) [%d]\n", number, ntohs(oh->olsr_msg[0].olsr_msgsize),
for (i=0; i<number; i++) { sizeof(struct hnapair) );
for (i = 0; i < number; i++) {
hna = &(oh->olsr_msg[0].message.hna.hna_net[i]); hna = &(oh->olsr_msg[0].message.hna.hna_net[i]);
DEBUG("HNA %s", ip_sprintf(hna->addr)); DEBUG("HNA %s", ip_sprintf(hna->addr));
DEBUG("/%s\n", ip_sprintf(hna->netmask)); DEBUG("/%s\n", ip_sprintf(hna->netmask));
if (hna->addr==0 && hna->netmask==0) if (hna->addr == 0 && hna->netmask == 0)
current_packet.pkt_types |= PKT_TYPE_OLSR_GW; current_packet.pkt_types |= PKT_TYPE_OLSR_GW;
} }
} }
/* done for good */
return 0; return 0;
} }
...@@ -33,7 +33,7 @@ struct pkt_names mgmt_names[] = { ...@@ -33,7 +33,7 @@ struct pkt_names mgmt_names[] = {
{ 'a', "ASOCRQ" }, /* IEEE80211_STYPE_ASSOC_REQ 0x0000 */ { 'a', "ASOCRQ" }, /* IEEE80211_STYPE_ASSOC_REQ 0x0000 */
{ 'A', "ASOCRP" }, /* IEEE80211_STYPE_ASSOC_RESP 0x0010 */ { 'A', "ASOCRP" }, /* IEEE80211_STYPE_ASSOC_RESP 0x0010 */
{ 'a', "REASRQ" }, /* IEEE80211_STYPE_REASSOC_REQ 0x0020 */ { 'a', "REASRQ" }, /* IEEE80211_STYPE_REASSOC_REQ 0x0020 */
{ 'A', "REASRP" }, /* IEEE80211_STYPE_REASSOC_RESP 0x0030 */ { 'A', "REASRP" }, /* IEEE80211_STYPE_REASSOC_RESP 0x0030 */
{ 'p', "PROBRQ" }, /* IEEE80211_STYPE_PROBE_REQ 0x0040 */ { 'p', "PROBRQ" }, /* IEEE80211_STYPE_PROBE_REQ 0x0040 */
{ 'P', "PROBRP" }, /* IEEE80211_STYPE_PROBE_RESP 0x0050 */ { 'P', "PROBRP" }, /* IEEE80211_STYPE_PROBE_RESP 0x0050 */
{}, {}, /* unused */ {}, {}, /* unused */
...@@ -79,15 +79,15 @@ struct pkt_names data_names[] = { ...@@ -79,15 +79,15 @@ struct pkt_names data_names[] = {
inline int inline int
normalize(float oval, float max_val, float max) { normalize(float oval, int max_val, int max) {
int val; int val;
val=(oval/max_val