#pragma once
#define WIN32_LEAN_AND_MEAN
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;
// need link with Ws2_32.lib
#pragma comment(lib, "Ws2_32.lib")
bool IPDw2Str(DWORD dwIP,std::string& strIP)
{
char _strIP[256] = { 0 };
WORD add1, add2, add3, add4;
add1 = (WORD)(dwIP & 255);
add2 = (WORD)((dwIP >> 8) & 255);
add3 = (WORD)((dwIP >> 16) & 255);
add4 = (WORD)((dwIP >> 24) & 255);
int nconvert = sprintf_s(_strIP,"%d.%d.%d.%d", add4, add3, add2, add1);
strIP = _strIP;
if (nconvert>0)
{
return true;
}
else
{
return false;
}
}
bool IPStr2Dw(std::string strIP, DWORD& dwIP)
{
dwIP = htonl(inet_addr(strIP.c_str()));
if (INADDR_NONE == dwIP)
{
return false;
}
else
{
return true;
}
}