[Listener] read_packet(): drop the data variable
This commit is contained in:
parent
7671163f62
commit
b4ee915e2d
|
@ -514,8 +514,6 @@ int capture()
|
|||
void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||
const u_char *packet)
|
||||
{
|
||||
// Copy packet address into data:
|
||||
const u_char *data = packet ;
|
||||
uint16_t rtap_bytes ; // Received data size
|
||||
uint32_t rtap_presentflags ;
|
||||
uint_fast16_t rtap_position ;
|
||||
|
@ -543,9 +541,9 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
|
||||
/* 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):
|
||||
memcpy(&rtap_bytes, &data[2], sizeof(rtap_bytes)) ;
|
||||
memcpy(&rtap_bytes, &packet[2], sizeof(rtap_bytes)) ;
|
||||
// Radiotap header is little-endian
|
||||
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
|
||||
// the type of the packet (Management, Control or Data) and its subtype
|
||||
// (QoS, etc.):
|
||||
raw_packet_fc1 = data[rtap_bytes] ;
|
||||
raw_packet_fc1 = packet[rtap_bytes] ;
|
||||
|
||||
if (! IS_DATA_FRAME(raw_packet_fc1)) // Data frame?
|
||||
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
|
||||
// bit is 0 the frame comes from a STA. That's what we want for an
|
||||
// explicit packet:
|
||||
raw_packet_fc2 = data[rtap_bytes+1] ;
|
||||
raw_packet_fc2 = packet[rtap_bytes+1] ;
|
||||
|
||||
if (! IS_FRAME_FROM_STA(raw_packet_fc2))
|
||||
goto not_explicit_packet ;
|
||||
|
||||
// Get the packet type (protocol, 2 bytes) from the LLC header:
|
||||
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) ;
|
||||
|
||||
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] ;
|
||||
&packet[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE] ;
|
||||
// Get the source IP:
|
||||
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:
|
||||
packet_udp_header = (struct udphdr *)
|
||||
&data[rtap_bytes + ieee80211_header_size +
|
||||
LLC_HEADER_SIZE + sizeof(struct iphdr)] ;
|
||||
&packet[rtap_bytes + ieee80211_header_size +
|
||||
LLC_HEADER_SIZE + sizeof(struct iphdr)] ;
|
||||
|
||||
if (GET_AUTOCALIBRATION() && ntohs(packet_udp_header->dest) ==
|
||||
GET_AUTOCALIBRATION_REQUEST_PORT())
|
||||
|
@ -613,7 +611,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
process_packet :
|
||||
|
||||
// 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
|
||||
if (IS_RETRY(raw_packet_flags))
|
||||
|
@ -621,7 +619,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
#endif // DEBUG
|
||||
|
||||
// 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:
|
||||
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))
|
||||
{
|
||||
packet_type =
|
||||
data[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
|
||||
+ sizeof(struct iphdr) + sizeof(struct udphdr)] ;
|
||||
packet[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
|
||||
+ sizeof(struct iphdr) + sizeof(struct udphdr)] ;
|
||||
switch(packet_type)
|
||||
{
|
||||
case PACKET_TYPE_NORMAL :
|
||||
|
@ -659,20 +657,20 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
if (GET_VERBOSE())
|
||||
printf("\nExplicit calibration packet received.\n") ;
|
||||
couple.direction =
|
||||
data[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
|
||||
+ sizeof(struct iphdr) + sizeof(struct udphdr) + 9];
|
||||
packet[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
|
||||
+ sizeof(struct iphdr) + sizeof(struct udphdr) + 9];
|
||||
memcpy(&couple.x_position,
|
||||
&data[rtap_bytes + ieee80211_header_size
|
||||
+ LLC_HEADER_SIZE + sizeof(struct iphdr)
|
||||
+ sizeof(struct udphdr) + 10], sizeof(float)) ;
|
||||
&packet[rtap_bytes + ieee80211_header_size
|
||||
+ LLC_HEADER_SIZE + sizeof(struct iphdr)
|
||||
+ sizeof(struct udphdr) + 10], sizeof(float)) ;
|
||||
memcpy(&couple.y_position,
|
||||
&data[rtap_bytes + ieee80211_header_size
|
||||
+ LLC_HEADER_SIZE + sizeof(struct iphdr)
|
||||
+ sizeof(struct udphdr) + 14], sizeof(float)) ;
|
||||
&packet[rtap_bytes + ieee80211_header_size
|
||||
+ LLC_HEADER_SIZE + sizeof(struct iphdr)
|
||||
+ sizeof(struct udphdr) + 14], sizeof(float)) ;
|
||||
memcpy(&couple.z_position,
|
||||
&data[rtap_bytes + ieee80211_header_size
|
||||
+ LLC_HEADER_SIZE + sizeof(struct iphdr)
|
||||
+ sizeof(struct udphdr) + 18], sizeof(float)) ;
|
||||
&packet[rtap_bytes + ieee80211_header_size
|
||||
+ LLC_HEADER_SIZE + sizeof(struct iphdr)
|
||||
+ sizeof(struct udphdr) + 18], sizeof(float)) ;
|
||||
break ;
|
||||
|
||||
case PACKET_TYPE_AUTOCALIBRATION :
|
||||
|
@ -703,8 +701,9 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
}
|
||||
else
|
||||
memcpy(&couple.request_time,
|
||||
&data[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
|
||||
+ sizeof(struct iphdr) + sizeof(struct udphdr) + 1],
|
||||
&packet[rtap_bytes + ieee80211_header_size +
|
||||
LLC_HEADER_SIZE + sizeof(struct iphdr) +
|
||||
sizeof(struct udphdr) + 1],
|
||||
sizeof(TIMESTAMP)) ;
|
||||
}
|
||||
|
||||
|
@ -722,7 +721,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
|
||||
// Get rtap flags:
|
||||
memcpy(&rtap_presentflags,
|
||||
&data[RTAP_P_PRESENTFLAGS], RTAP_L_PRESENTFLAGS) ;
|
||||
&packet[RTAP_P_PRESENTFLAGS], RTAP_L_PRESENTFLAGS) ;
|
||||
// Radiotap header is little-endian
|
||||
rtap_presentflags = le32toh(rtap_presentflags) ;
|
||||
|
||||
|
@ -760,7 +759,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
|||
break ;
|
||||
case RTAP_ANTENNASIGNALDBM:
|
||||
memcpy(&(couple.antenna_signal_dbm),
|
||||
&data[rtap_position], RTAP_L_ANTENNASIGNALDBM) ;
|
||||
&packet[rtap_position], RTAP_L_ANTENNASIGNALDBM) ;
|
||||
check[RTAP_ANTENNASIGNALDBM] = TRUE;
|
||||
if (GET_VERBOSE())
|
||||
printf("Antenna signal: %d dBm\n",
|
||||
|
|
Loading…
Reference in New Issue