[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
This commit is contained in:
Matteo Cypriani 2010-11-23 18:29:32 +01:00
parent 2e16e62c44
commit 8474fef520
1 changed files with 35 additions and 43 deletions

View File

@ -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? BOOL is_explicit_packet = TRUE ; // Is the packet an explicit request?
int i ; // Iterator int i ; // Iterator
bzero(couple.mobile_ip_addr_bytes, 4) ; // Blank the IP
/* Common treatements */ /* Common treatements */
@ -505,15 +506,17 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
// is the packet type (beacon or not): // is the packet type (beacon or not):
raw_packet_type = data[rtap_bytes] ; 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: // Get the packet type (protocol, 2 bytes) from the LLC header:
memcpy((unsigned char*) &llc_packet_type, memcpy((unsigned char*) &llc_packet_type,
&data[rtap_bytes + IEEE80211_HEADER_SIZE + 6], 2) ; &data[rtap_bytes + IEEE80211_HEADER_SIZE + 6], 2) ;
llc_packet_type = ntohs(llc_packet_type) ; llc_packet_type = ntohs(llc_packet_type) ;
if (llc_packet_type == ETH_P_IP) // IP packet if (llc_packet_type != ETH_P_IP) // IP packet?
{ goto not_explicit_packet ;
packet_ip_header = (struct iphdr *) packet_ip_header = (struct iphdr *)
&data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE] ; &data[rtap_bytes + IEEE80211_HEADER_SIZE + LLC_HEADER_SIZE] ;
// Get the source IP: // Get the source IP:
@ -522,36 +525,25 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
if (GET_MODE() != MODE_PASSIVE) // If mode is active or mixed if (GET_MODE() != MODE_PASSIVE) // If mode is active or mixed
{ {
// Protocol for an explicit request is UDP // Protocol for an explicit request is UDP
if (packet_ip_header->protocol == IPPROTO_UDP) if (packet_ip_header->protocol != IPPROTO_UDP)
{ // Check destination port: goto not_explicit_packet ;
// Check destination port:
packet_udp_header = (struct udphdr *) packet_udp_header = (struct udphdr *)
&data[rtap_bytes + IEEE80211_HEADER_SIZE + &data[rtap_bytes + IEEE80211_HEADER_SIZE +
LLC_HEADER_SIZE + sizeof(struct iphdr)] ; LLC_HEADER_SIZE + sizeof(struct iphdr)] ;
if (ntohs(packet_udp_header->dest) != if (ntohs(packet_udp_header->dest) != GET_LISTENING_PORT())
GET_LISTENING_PORT()) goto not_explicit_packet ;
{
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 ;
} }
else // Packet is not data, so it is not a localisation request goto process_packet ;
{
not_explicit_packet :
if (GET_MODE() == MODE_ACTIVE) if (GET_MODE() == MODE_ACTIVE)
return ; return ;
is_explicit_packet = FALSE ; is_explicit_packet = FALSE ;
}
process_packet :
// Get 802.11 flags from the 802.11 header: // Get 802.11 flags from the 802.11 header:
raw_packet_flags = data[rtap_bytes+1] ; raw_packet_flags = data[rtap_bytes+1] ;