Cleaned File

unix_test
anulax1225 ago%!(EXTRA string=1 year)
parent 71c558d7bf
commit 0884bcaf1c
  1. 14
      bakanet/src/bakanet/dns_lookup.cpp
  2. 1
      bakanet/src/bakanet/dns_lookup.h
  3. 4
      bakanet/src/bakanet/ip_address.cpp
  4. 4
      bakanet/src/bakanet/ip_address.h

@ -14,22 +14,24 @@ namespace Bk::Net {
hints.ai_family = ai_family;
hints.ai_socktype = SOCK_STREAM;
if ((status = getaddrinfo(host_name.c_str(), NULL, &hints, &res)) != 0) {
if ((status = getaddrinfo(host_name.c_str(), NULL, &hints, &res)) != 0)
{
output.push_back("");
return output;
}
for(p = res;p != NULL; p = p->ai_next) {
for(p = res;p != NULL; p = p->ai_next)
{
void *addr;
if (p->ai_family == AF_INET) { // IPv4
if (p->ai_family == AF_INET)
{
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
addr = &(ipv4->sin_addr);
} else { // IPv6
} else
{
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
addr = &(ipv6->sin6_addr);
}
// convert the IP to a string
inet_ntop(p->ai_family, addr, ip_address, sizeof ip_address);
output.push_back(ip_address);
}

@ -8,6 +8,7 @@
#include <arpa/inet.h>
#include "ip_version.h"
#include "ip_address.h"
namespace Bk::Net {
std::vector<std::string> dns_lookup(const std::string &host_name, IpVersion ipv);

@ -2,8 +2,8 @@
#include <string.h>
namespace Bk::Net {
IpAddress::IpAddress(const char* ip)
: str(ip)
IpAddress::IpAddress(const char* ip, IpVersion ipv)
: str(ip), version(ipv)
{
if (inet_pton(AF_INET, str, &bytes) <= 0) perror("Bad IP");
}

@ -12,12 +12,12 @@ namespace Bk::Net {
class IpAddress
{
public:
IpAddress(const char* ip);
IpAddress(const char* ip, IpVersion ipv = IpVersion::IPv4);
static void from_dns(char* dns);
const char* str;
in_addr bytes;
IpVersion version = IpVersion::IPv4;
IpVersion version;
};
}
Loading…
Cancel
Save