diff --git a/infrastructure-centred/owlps-listener/owlps-listenerd.c b/infrastructure-centred/owlps-listener/owlps-listenerd.c index 137bae9..6275162 100644 --- a/infrastructure-centred/owlps-listener/owlps-listenerd.c +++ b/infrastructure-centred/owlps-listener/owlps-listenerd.c @@ -799,6 +799,7 @@ void get_ip_addr(char *eth, char ip[16]) struct ifreq ifr; int sockfd ; struct sockaddr_in sa ; + struct in_addr ip_addr ; sockfd = socket(AF_INET, SOCK_DGRAM, 0) ; if(sockfd < 0) @@ -812,10 +813,9 @@ void get_ip_addr(char *eth, char ip[16]) if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0) return ; - strncpy(ip, - inet_ntoa(*(struct in_addr *) - &ifr.ifr_addr.sa_data[sizeof(sa.sin_port)]), - 16) ; + memcpy(&ip_addr, &ifr.ifr_addr.sa_data[sizeof(sa.sin_port)], + sizeof(ip_addr)) ; + strncpy(ip, inet_ntoa(ip_addr), 16) ; }