12-05-2006 04:27 AM
12-05-2006 12:46 PM
12-07-2006 10:50 AM
I am not exactly sure if this is related to static versus dynamic IP addresses or something about how the DHCP server specified the host name. In either case, you can workaround it by getting the IP address using GetTCPHostAddr and then using the winsock functions inet_addr and gethostbyaddr to get the host name from the IP address. To call winsock functions you would normally need to link with the winsock library which is only available with the CVI Full SDK - but it is also possible to dynamically load the winsock DLL and call these functions. The following example shows this:
#include <windows.h>
#define inet_addr inet_addr_winsock
#define gethostbyaddr gethostbyaddr_winsock
#include <winsock.h>
#undef inet_addr
#undef gethostbyaddr
#include <tcpsupp.h>
#include <cvirte.h>
#include <ansi_c.h>
unsigned long (__stdcall * inet_addr)(const char *cp);
struct hostent * (__stdcall * gethostbyaddr)(const char *addr, int len, int type);
static BOOL LoadWinSockFuncs(void)
{
HMODULE wsock32 = NULL;
wsock32 = LoadLibrary("wsock32.dll");
if (wsock32 == NULL)
return FALSE;
inet_addr = (void *)GetProcAddress(wsock32, "inet_addr");
gethostbyaddr = (void *)GetProcAddress(wsock32, "gethostbyaddr");
if (inet_addr == NULL || gethostbyaddr == NULL)
{
FreeLibrary(wsock32);
return FALSE;
}
return TRUE;
}
void CVIFUNC_C RTmain (void)
{
char host[512];
int error;
HOSTENT *hostent;
unsigned int addr;
if (InitCVIRTE (0, 0, 0) == 0)
return;
error = GetTCPHostName(host, sizeof(host)); // may return "#Local Host"
error = GetTCPHostAddr(host, sizeof(host)); // returns the IP address
if (!LoadWinSockFuncs())
assert(0);
addr = inet_addr(host);
hostent = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET);
// now, hostent->h_name contains the name of the host
CloseCVIRTE ();
}
12-13-2006 09:02 AM
12-14-2006 09:15 AM
12-14-2006 10:01 AM
12-15-2006 09:38 AM