|
@@ -26,6 +26,16 @@ const char* socket_strerror(int err) {
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+bool is_ipv4(const char* host) {
|
|
|
|
|
+ struct sockaddr_in sin;
|
|
|
|
|
+ return inet_pton(AF_INET, host, &sin) == 1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool is_ipv6(const char* host) {
|
|
|
|
|
+ struct sockaddr_in6 sin6;
|
|
|
|
|
+ return inet_pton(AF_INET6, host, &sin6) == 1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
int Resolver(const char* host, sockaddr_u* addr) {
|
|
int Resolver(const char* host, sockaddr_u* addr) {
|
|
|
if (inet_pton(AF_INET, host, &addr->sin.sin_addr) == 1) {
|
|
if (inet_pton(AF_INET, host, &addr->sin.sin_addr) == 1) {
|
|
|
addr->sa.sa_family = AF_INET; // host is ipv4, so easy ;)
|
|
addr->sa.sa_family = AF_INET; // host is ipv4, so easy ;)
|
|
@@ -35,7 +45,6 @@ int Resolver(const char* host, sockaddr_u* addr) {
|
|
|
#ifdef ENABLE_IPV6
|
|
#ifdef ENABLE_IPV6
|
|
|
if (inet_pton(AF_INET6, host, &addr->sin6.sin6_addr) == 1) {
|
|
if (inet_pton(AF_INET6, host, &addr->sin6.sin6_addr) == 1) {
|
|
|
addr->sa.sa_family = AF_INET6; // host is ipv6
|
|
addr->sa.sa_family = AF_INET6; // host is ipv6
|
|
|
- return 0;
|
|
|
|
|
}
|
|
}
|
|
|
struct addrinfo* ais = NULL;
|
|
struct addrinfo* ais = NULL;
|
|
|
struct addrinfo hint;
|
|
struct addrinfo hint;
|