[Listener] Send IP in Hello messages
This commit is contained in:
parent
4b2fbf3188
commit
eff2455897
|
@ -78,6 +78,7 @@ int capture(void) ;
|
||||||
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) ;
|
||||||
void get_mac_addr(char *eth, unsigned char mac_bytes[6]) ;
|
void get_mac_addr(char *eth, unsigned char mac_bytes[6]) ;
|
||||||
|
void get_ip_addr(char *eth, char *ip_bytes) ;
|
||||||
|
|
||||||
#ifdef USE_PTHREAD
|
#ifdef USE_PTHREAD
|
||||||
void autocalibrate(void) ;
|
void autocalibrate(void) ;
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
|
|
||||||
char *program_name = NULL ;
|
char *program_name = NULL ;
|
||||||
unsigned char mac[6] ; // AP MAC address
|
unsigned char my_mac[6] ; // AP MAC address
|
||||||
|
char my_ip[16] ; // AP IP address
|
||||||
|
|
||||||
int aggregation_sockfd ;
|
int aggregation_sockfd ;
|
||||||
struct sockaddr_in aggregation_server ;
|
struct sockaddr_in aggregation_server ;
|
||||||
|
@ -101,10 +102,12 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
#endif // USE_PTHREAD
|
#endif // USE_PTHREAD
|
||||||
|
|
||||||
get_mac_addr(GET_WIFI_IFACE(), mac) ;
|
get_mac_addr(GET_WIFI_IFACE(), my_mac) ;
|
||||||
mac_string = mac_bytes_to_string(mac) ;
|
mac_string = mac_bytes_to_string(my_mac) ;
|
||||||
printf("My MAC address is: %s\n", mac_string) ;
|
printf("My MAC address is: %s\n", mac_string) ;
|
||||||
free(mac_string) ;
|
free(mac_string) ;
|
||||||
|
get_ip_addr(GET_WIFI_IFACE(), my_ip) ;
|
||||||
|
printf("My IP address is: %s\n", my_ip) ;
|
||||||
|
|
||||||
ret = capture() ; // Capture loop
|
ret = capture() ; // Capture loop
|
||||||
|
|
||||||
|
@ -530,7 +533,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
printf("This packet is a Retry.\n") ;
|
printf("This packet is a Retry.\n") ;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
memcpy(couple.ap_mac_addr_bytes, mac, 6) ; // Copy AP MAC
|
memcpy(couple.ap_mac_addr_bytes, my_mac, 6) ; // Copy AP MAC
|
||||||
// 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, &data[rtap_bytes+10], 6) ;
|
||||||
couple.start_time = header->ts ; // Capture time is in the pcap header
|
couple.start_time = header->ts ; // Capture time is in the pcap header
|
||||||
|
@ -786,6 +789,35 @@ void get_mac_addr(char *eth, unsigned char mac_bytes[6])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get our own IP address and copy it to 'ip'.
|
||||||
|
*/
|
||||||
|
void get_ip_addr(char *eth, char ip[16])
|
||||||
|
{
|
||||||
|
struct ifreq ifr;
|
||||||
|
int sockfd ;
|
||||||
|
struct sockaddr_in sa ;
|
||||||
|
|
||||||
|
sockfd = socket(AF_INET, SOCK_DGRAM, 0) ;
|
||||||
|
if(sockfd < 0)
|
||||||
|
perror("Cannot open socket to read IP address") ;
|
||||||
|
|
||||||
|
strncpy(ifr.ifr_name, eth, IFNAMSIZ) ;
|
||||||
|
|
||||||
|
if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
strncpy(ip,
|
||||||
|
inet_ntoa(*(struct in_addr *)
|
||||||
|
&ifr.ifr_addr.sa_data[sizeof(sa.sin_port)]),
|
||||||
|
16) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* *** Autocalibration functions *** */
|
/* *** Autocalibration functions *** */
|
||||||
#ifdef USE_PTHREAD
|
#ifdef USE_PTHREAD
|
||||||
|
|
||||||
|
@ -805,7 +837,8 @@ void autocalibrate_hello()
|
||||||
GET_AUTOCALIBRATION_PORT(),
|
GET_AUTOCALIBRATION_PORT(),
|
||||||
&serv, &client) ;
|
&serv, &client) ;
|
||||||
|
|
||||||
memcpy(&message.ap_mac_addr_bytes, mac, 6) ;
|
memcpy(&message.ap_mac_addr_bytes, my_mac, 6) ;
|
||||||
|
strncpy(message.ap_ip_addr, my_ip, 16) ;
|
||||||
|
|
||||||
while (run)
|
while (run)
|
||||||
{
|
{
|
||||||
|
|
|
@ -89,6 +89,7 @@ typedef struct _request
|
||||||
typedef struct _autocalibration_hello
|
typedef struct _autocalibration_hello
|
||||||
{
|
{
|
||||||
unsigned char ap_mac_addr_bytes[6];
|
unsigned char ap_mac_addr_bytes[6];
|
||||||
|
char ap_ip_addr[16] ;
|
||||||
} autocalibration_hello ;
|
} autocalibration_hello ;
|
||||||
|
|
||||||
typedef struct _autocalibration_order
|
typedef struct _autocalibration_order
|
||||||
|
|
Loading…
Reference in New Issue