[Listener] read_packet(): drop the data variable

This commit is contained in:
Matteo Cypriani 2011-03-10 19:31:18 +01:00
parent 7671163f62
commit b4ee915e2d
1 changed files with 28 additions and 29 deletions

View File

@ -514,8 +514,6 @@ int capture()
void read_packet(u_char *args, const struct pcap_pkthdr *header, void read_packet(u_char *args, const struct pcap_pkthdr *header,
const u_char *packet) const u_char *packet)
{ {
// Copy packet address into data:
const u_char *data = packet ;
uint16_t rtap_bytes ; // Received data size uint16_t rtap_bytes ; // Received data size
uint32_t rtap_presentflags ; uint32_t rtap_presentflags ;
uint_fast16_t rtap_position ; uint_fast16_t rtap_position ;
@ -543,9 +541,9 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
/* Common treatements */ /* Common treatements */
// Copy 2 bytes from the 3rd data byte, that is the size of the rtap // Copy 2 bytes from the 3rd packet byte, that is the size of the rtap
// header (changes with the flags): // header (changes with the flags):
memcpy(&rtap_bytes, &data[2], sizeof(rtap_bytes)) ; memcpy(&rtap_bytes, &packet[2], sizeof(rtap_bytes)) ;
// Radiotap header is little-endian // Radiotap header is little-endian
rtap_bytes = le16toh(rtap_bytes) ; rtap_bytes = le16toh(rtap_bytes) ;
@ -553,7 +551,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
// is the first byte of the Frame Control (FC) field, which contains // is the first byte of the Frame Control (FC) field, which contains
// the type of the packet (Management, Control or Data) and its subtype // the type of the packet (Management, Control or Data) and its subtype
// (QoS, etc.): // (QoS, etc.):
raw_packet_fc1 = data[rtap_bytes] ; raw_packet_fc1 = packet[rtap_bytes] ;
if (! IS_DATA_FRAME(raw_packet_fc1)) // Data frame? if (! IS_DATA_FRAME(raw_packet_fc1)) // Data frame?
goto not_explicit_packet ; goto not_explicit_packet ;
@ -566,21 +564,21 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
// first bit is "To DS" and the second is "From DS", so if the second // first bit is "To DS" and the second is "From DS", so if the second
// bit is 0 the frame comes from a STA. That's what we want for an // bit is 0 the frame comes from a STA. That's what we want for an
// explicit packet: // explicit packet:
raw_packet_fc2 = data[rtap_bytes+1] ; raw_packet_fc2 = packet[rtap_bytes+1] ;
if (! IS_FRAME_FROM_STA(raw_packet_fc2)) if (! IS_FRAME_FROM_STA(raw_packet_fc2))
goto not_explicit_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(&llc_packet_type, memcpy(&llc_packet_type,
&data[rtap_bytes + ieee80211_header_size + 6], 2) ; &packet[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 ; goto not_explicit_packet ;
packet_ip_header = (struct iphdr *) packet_ip_header = (struct iphdr *)
&data[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE] ; &packet[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE] ;
// Get the source IP: // Get the source IP:
memcpy(couple.mobile_ip_addr_bytes, &packet_ip_header->saddr, 4) ; memcpy(couple.mobile_ip_addr_bytes, &packet_ip_header->saddr, 4) ;
@ -592,8 +590,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
// Check destination port: // Check destination port:
packet_udp_header = (struct udphdr *) packet_udp_header = (struct udphdr *)
&data[rtap_bytes + ieee80211_header_size + &packet[rtap_bytes + ieee80211_header_size +
LLC_HEADER_SIZE + sizeof(struct iphdr)] ; LLC_HEADER_SIZE + sizeof(struct iphdr)] ;
if (GET_AUTOCALIBRATION() && ntohs(packet_udp_header->dest) == if (GET_AUTOCALIBRATION() && ntohs(packet_udp_header->dest) ==
GET_AUTOCALIBRATION_REQUEST_PORT()) GET_AUTOCALIBRATION_REQUEST_PORT())
@ -613,7 +611,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
process_packet : 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 = packet[rtap_bytes+1] ;
#ifdef DEBUG #ifdef DEBUG
if (IS_RETRY(raw_packet_flags)) if (IS_RETRY(raw_packet_flags))
@ -621,7 +619,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
#endif // DEBUG #endif // DEBUG
// Source MAC address is 10 bytes after the 802.11 packet type: // Source MAC address is 10 bytes after the 802.11 packet type:
memcpy(couple.mobile_mac_addr_bytes, &data[rtap_bytes+10], 6) ; memcpy(couple.mobile_mac_addr_bytes, &packet[rtap_bytes+10], 6) ;
// Drop the packet if it comes from the AP itself: // Drop the packet if it comes from the AP itself:
if (mac_equals(my_mac_bytes, couple.mobile_mac_addr_bytes)) if (mac_equals(my_mac_bytes, couple.mobile_mac_addr_bytes))
@ -646,8 +644,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
&& ! IS_RETRY(raw_packet_flags)) && ! IS_RETRY(raw_packet_flags))
{ {
packet_type = packet_type =
data[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE packet[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
+ sizeof(struct iphdr) + sizeof(struct udphdr)] ; + sizeof(struct iphdr) + sizeof(struct udphdr)] ;
switch(packet_type) switch(packet_type)
{ {
case PACKET_TYPE_NORMAL : case PACKET_TYPE_NORMAL :
@ -659,20 +657,20 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
if (GET_VERBOSE()) if (GET_VERBOSE())
printf("\nExplicit calibration packet received.\n") ; printf("\nExplicit calibration packet received.\n") ;
couple.direction = couple.direction =
data[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE packet[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
+ sizeof(struct iphdr) + sizeof(struct udphdr) + 9]; + sizeof(struct iphdr) + sizeof(struct udphdr) + 9];
memcpy(&couple.x_position, memcpy(&couple.x_position,
&data[rtap_bytes + ieee80211_header_size &packet[rtap_bytes + ieee80211_header_size
+ LLC_HEADER_SIZE + sizeof(struct iphdr) + LLC_HEADER_SIZE + sizeof(struct iphdr)
+ sizeof(struct udphdr) + 10], sizeof(float)) ; + sizeof(struct udphdr) + 10], sizeof(float)) ;
memcpy(&couple.y_position, memcpy(&couple.y_position,
&data[rtap_bytes + ieee80211_header_size &packet[rtap_bytes + ieee80211_header_size
+ LLC_HEADER_SIZE + sizeof(struct iphdr) + LLC_HEADER_SIZE + sizeof(struct iphdr)
+ sizeof(struct udphdr) + 14], sizeof(float)) ; + sizeof(struct udphdr) + 14], sizeof(float)) ;
memcpy(&couple.z_position, memcpy(&couple.z_position,
&data[rtap_bytes + ieee80211_header_size &packet[rtap_bytes + ieee80211_header_size
+ LLC_HEADER_SIZE + sizeof(struct iphdr) + LLC_HEADER_SIZE + sizeof(struct iphdr)
+ sizeof(struct udphdr) + 18], sizeof(float)) ; + sizeof(struct udphdr) + 18], sizeof(float)) ;
break ; break ;
case PACKET_TYPE_AUTOCALIBRATION : case PACKET_TYPE_AUTOCALIBRATION :
@ -703,8 +701,9 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
} }
else else
memcpy(&couple.request_time, memcpy(&couple.request_time,
&data[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE &packet[rtap_bytes + ieee80211_header_size +
+ sizeof(struct iphdr) + sizeof(struct udphdr) + 1], LLC_HEADER_SIZE + sizeof(struct iphdr) +
sizeof(struct udphdr) + 1],
sizeof(TIMESTAMP)) ; sizeof(TIMESTAMP)) ;
} }
@ -722,7 +721,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
// Get rtap flags: // Get rtap flags:
memcpy(&rtap_presentflags, memcpy(&rtap_presentflags,
&data[RTAP_P_PRESENTFLAGS], RTAP_L_PRESENTFLAGS) ; &packet[RTAP_P_PRESENTFLAGS], RTAP_L_PRESENTFLAGS) ;
// Radiotap header is little-endian // Radiotap header is little-endian
rtap_presentflags = le32toh(rtap_presentflags) ; rtap_presentflags = le32toh(rtap_presentflags) ;
@ -760,7 +759,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
break ; break ;
case RTAP_ANTENNASIGNALDBM: case RTAP_ANTENNASIGNALDBM:
memcpy(&(couple.antenna_signal_dbm), memcpy(&(couple.antenna_signal_dbm),
&data[rtap_position], RTAP_L_ANTENNASIGNALDBM) ; &packet[rtap_position], RTAP_L_ANTENNASIGNALDBM) ;
check[RTAP_ANTENNASIGNALDBM] = TRUE; check[RTAP_ANTENNASIGNALDBM] = TRUE;
if (GET_VERBOSE()) if (GET_VERBOSE())
printf("Antenna signal: %d dBm\n", printf("Antenna signal: %d dBm\n",