use inet_ntop properly

This commit is contained in:
Jeff Becker 2016-06-29 16:10:43 -04:00
parent 44f0bad2a6
commit 50286fd173
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B

View File

@ -433,10 +433,12 @@ namespace net
if (cur_ifname == ifname && cur->ifa_addr && cur->ifa_addr->sa_family == af)
{
// match
size_t sz = 128;
char * addr = new char[sz];
// this probably won't screw up (right?)
inet_ntop(af, cur->ifa_addr->sa_data, addr, sizeof(in6_addr));
char * addr = new char[INET6_ADDRSTRLEN];
bzero(addr, INET6_ADDRSTRLEN);
if(af == AF_INET)
inet_ntop(af, &((sockaddr_in *)cur->ifa_addr)->sin_addr, addr, INET6_ADDRSTRLEN);
else
inet_ntop(af, &((sockaddr_in6 *)cur->ifa_addr)->sin6_addr, addr, INET6_ADDRSTRLEN);
freeifaddrs(addrs);
std::string cur_ifaddr(addr);
return boost::asio::ip::address::from_string(cur_ifaddr);