From eff2455897046a2cbd28bda5d4c3b45fb742cfcb Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Wed, 13 Oct 2010 17:42:00 +0200 Subject: [PATCH] [Listener] Send IP in Hello messages --- .../owlps-listener/owlps-listener.h | 1 + .../owlps-listener/owlps-listenerd.c | 43 ++++++++++++++++--- libowlps/owlps.h | 1 + 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/infrastructure-centred/owlps-listener/owlps-listener.h b/infrastructure-centred/owlps-listener/owlps-listener.h index cf0adf2..ef14216 100644 --- a/infrastructure-centred/owlps-listener/owlps-listener.h +++ b/infrastructure-centred/owlps-listener/owlps-listener.h @@ -78,6 +78,7 @@ int capture(void) ; void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) ; void get_mac_addr(char *eth, unsigned char mac_bytes[6]) ; +void get_ip_addr(char *eth, char *ip_bytes) ; #ifdef USE_PTHREAD void autocalibrate(void) ; diff --git a/infrastructure-centred/owlps-listener/owlps-listenerd.c b/infrastructure-centred/owlps-listener/owlps-listenerd.c index cc13621..bb79a7b 100644 --- a/infrastructure-centred/owlps-listener/owlps-listenerd.c +++ b/infrastructure-centred/owlps-listener/owlps-listenerd.c @@ -8,7 +8,8 @@ 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 ; struct sockaddr_in aggregation_server ; @@ -101,10 +102,12 @@ int main(int argc, char *argv[]) } #endif // USE_PTHREAD - get_mac_addr(GET_WIFI_IFACE(), mac) ; - mac_string = mac_bytes_to_string(mac) ; + get_mac_addr(GET_WIFI_IFACE(), my_mac) ; + mac_string = mac_bytes_to_string(my_mac) ; printf("My MAC address is: %s\n", 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 @@ -530,7 +533,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, printf("This packet is a Retry.\n") ; #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: memcpy(couple.mobile_mac_addr_bytes, &data[rtap_bytes+10], 6) ; 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 *** */ #ifdef USE_PTHREAD @@ -805,7 +837,8 @@ void autocalibrate_hello() GET_AUTOCALIBRATION_PORT(), &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) { diff --git a/libowlps/owlps.h b/libowlps/owlps.h index 9423f61..f9fe4d1 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -89,6 +89,7 @@ typedef struct _request typedef struct _autocalibration_hello { unsigned char ap_mac_addr_bytes[6]; + char ap_ip_addr[16] ; } autocalibration_hello ; typedef struct _autocalibration_order