mirror of
https://github.com/jslightham/cpp-utils.git
synced 2026-03-09 18:12:26 +01:00
Initial commit
This commit is contained in:
26
ip.h
Normal file
26
ip.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef IP_UTIL_H
|
||||
#define IP_UTIL_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#define CLOSE_SOCKET closesocket
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
typedef SOCKET socket_t;
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#define CLOSE_SOCKET close
|
||||
typedef int socket_t;
|
||||
#endif
|
||||
|
||||
bool is_valid_ipv4(const std::string &ip) {
|
||||
struct in_addr addr;
|
||||
return inet_pton(AF_INET, ip.c_str(), &addr) == 1;
|
||||
}
|
||||
|
||||
#endif // IP_UTIL_H
|
||||
Reference in New Issue
Block a user