From 8474fef52077a4ae30bbdeac05839ff09c8cb4c9 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 23 Nov 2010 18:29:32 +0100 Subject: [PATCH] [Listener] Reorganise implicit/explicit code Reorganise read_packet() code for detection of implicit/explicit requests. Quite buggy, it was. Word of the day: OMG GOTOZ LOL111 --- .../owlps-listener/owlps-listenerd.c | 78 +++++++++---------- 1 file changed, 35 insertions(+), 43 deletions(-) diff --git a/infrastructure-centred/owlps-listener/owlps-listenerd.c b/infrastructure-centred/owlps-listener/owlps-listenerd.c index 42c8eb2..0e93896 100644 --- a/infrastructure-centred/owlps-listener/owlps-listenerd.c +++ b/infrastructure-centred/owlps-listener/owlps-listenerd.c @@ -492,6 +492,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, BOOL is_explicit_packet = TRUE ; // Is the packet an explicit request? int i ; // Iterator + bzero(couple.mobile_ip_addr_bytes, 4) ; // Blank the IP /* Common treatements */ @@ -505,53 +506,44 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, // is the packet type (beacon or not): raw_packet_type = data[rtap_bytes] ; - if (raw_packet_type == RAW_PACKET_TYPE_DATA) // Data packet + if (raw_packet_type != RAW_PACKET_TYPE_DATA) // Data packet? + goto not_explicit_packet ; + + // Get the packet type (protocol, 2 bytes) from the LLC header: + memcpy((unsigned char*) &llc_packet_type, + &data[rtap_bytes + IEEE80211_HEADER_SIZE + 6], 2) ; + llc_packet_type = ntohs(llc_packet_type) ; + + if (llc_packet_type != ETH_P_IP) // IP packet? + goto not_explicit_packet ; + + packet_ip_header = (struct iphdr *) + &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE] ; + // Get the source IP: + memcpy(couple.mobile_ip_addr_bytes, &packet_ip_header->saddr, 4) ; + + if (GET_MODE() != MODE_PASSIVE) // If mode is active or mixed { - // Get the packet type (protocol, 2 bytes) from the LLC header: - memcpy((unsigned char*) &llc_packet_type, - &data[rtap_bytes + IEEE80211_HEADER_SIZE + 6], 2) ; - llc_packet_type = ntohs(llc_packet_type) ; + // Protocol for an explicit request is UDP + if (packet_ip_header->protocol != IPPROTO_UDP) + goto not_explicit_packet ; - if (llc_packet_type == ETH_P_IP) // IP packet - { - packet_ip_header = (struct iphdr *) - &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE] ; - // Get the source IP: - memcpy(couple.mobile_ip_addr_bytes, &packet_ip_header->saddr, 4) ; - - if (GET_MODE() != MODE_PASSIVE) // If mode is active or mixed - { - // Protocol for an explicit request is UDP - if (packet_ip_header->protocol == IPPROTO_UDP) - { // Check destination port: - packet_udp_header = (struct udphdr *) - &data[rtap_bytes + IEEE80211_HEADER_SIZE + - LLC_HEADER_SIZE + sizeof(struct iphdr)] ; - if (ntohs(packet_udp_header->dest) != - GET_LISTENING_PORT()) - { - if (GET_MODE() == MODE_ACTIVE) - return ; - is_explicit_packet = FALSE ; - } - } - } - } - else if (GET_MODE() != MODE_ACTIVE) // Passive or mixed mode - { - is_explicit_packet = FALSE ; - bzero(couple.mobile_ip_addr_bytes, 4) ; // Blank the IP - } - else // Active mode and not an IP packet, so it is not a request - return ; + // Check destination port: + packet_udp_header = (struct udphdr *) + &data[rtap_bytes + IEEE80211_HEADER_SIZE + + LLC_HEADER_SIZE + sizeof(struct iphdr)] ; + if (ntohs(packet_udp_header->dest) != GET_LISTENING_PORT()) + goto not_explicit_packet ; } - else // Packet is not data, so it is not a localisation request - { - if (GET_MODE() == MODE_ACTIVE) - return ; - is_explicit_packet = FALSE ; - } + goto process_packet ; + + not_explicit_packet : + if (GET_MODE() == MODE_ACTIVE) + return ; + is_explicit_packet = FALSE ; + + process_packet : // Get 802.11 flags from the 802.11 header: raw_packet_flags = data[rtap_bytes+1] ;