This is the c code
#include "c_dll_4_vb.h"
Code:
long __stdcall Resolve_Name_To_Ip
(char *pcDomainToResolve, char szReturnIP[500], int &iSize)
{
WSADATA wsaData;
LPTSTR CompName = new char[255];
LPDWORD CompSize = new unsigned long(255);
struct sockaddr_in dest;
struct hostent *hp;
char *dest_ip;
unsigned int addr = 0;
strcpy(CompName,pcDomainToResolve);
if(WSAStartup(MAKEWORD(2,1), &wsaData) != 0)
{ WSACleanup();
return -100;
}
hp = gethostbyname(CompName);
if(!hp)
{ addr = inet_addr(CompName);
}
if((!hp) && (addr == INADDR_NONE))
{// Unable to resolve domain ip.
WSACleanup();
return -200;
}
hp = gethostbyname(CompName);
if(hp != NULL)
memcpy(&(dest.sin_addr),hp->h_addr,hp->h_length);
else
dest.sin_addr.s_addr = addr;
if(hp)
dest.sin_family = hp->h_addrtype;
else
dest.sin_family = AF_INET;
dest_ip = inet_ntoa(dest.sin_addr);
iSize = strlen(dest_ip);
// Allow the string to return to the proper size.
strncpy(szReturnIP, dest_ip, strlen(dest_ip));
dest_ip = NULL;
hp = NULL;
addr = 0;
dest.sin_family = NULL;
dest.sin_addr.s_addr = NULL;
dest.sin_addr.S_un.S_addr = NULL;
dest.sin_port = NULL;
delete [] CompName;
delete [] CompSize;
WSACleanup();
return (0);
}
This is the header:
Code:
#include <windows.h>
#include <winsock.h>
#include <stdio.h>
// Function is used to resolve a domain name to an IP address.
// The return values are: -100 = Incorrect version of Winsock
// -200 = Cant resolve domain.
long __stdcall Resolve_Name_To_Ip
(char *pcDomainToResolve, char szReturnIP[500], int &iSize);