示例#1
0
文件: environ.c 项目: mikekap/wine
static void test_GetComputerName(void)
{
    DWORD size;
    BOOL ret;
    LPSTR name;
    LPWSTR nameW;
    DWORD error;
    int name_len;

    size = 0;
    ret = GetComputerNameA((LPSTR)0xdeadbeef, &size);
    error = GetLastError();
    ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameA should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);

    /* Only Vista returns the computer name length as documented in the MSDN */
    if (size != 0)
    {
        size++; /* nul terminating character */
        name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
        ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
        ret = GetComputerNameA(name, &size);
        ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
        HeapFree(GetProcessHeap(), 0, name);
    }

    size = MAX_COMPUTERNAME_LENGTH + 1;
    name = HeapAlloc(GetProcessHeap(), 0, size * sizeof(name[0]));
    ok(name != NULL, "HeapAlloc failed with error %d\n", GetLastError());
    ret = GetComputerNameA(name, &size);
    ok(ret, "GetComputerNameA failed with error %d\n", GetLastError());
    trace("computer name is \"%s\"\n", name);
    name_len = strlen(name);
    ok(size == name_len, "size should be same as length, name_len=%d, size=%d\n", name_len, size);
    HeapFree(GetProcessHeap(), 0, name);

    size = 0;
    SetLastError(0xdeadbeef);
    ret = GetComputerNameW((LPWSTR)0xdeadbeef, &size);
    error = GetLastError();
    if (error == ERROR_CALL_NOT_IMPLEMENTED)
        win_skip("GetComputerNameW is not implemented\n");
    else
    {
        ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameW should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
        size++; /* nul terminating character */
        nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
        ok(nameW != NULL, "HeapAlloc failed with error %d\n", GetLastError());
        ret = GetComputerNameW(nameW, &size);
        ok(ret, "GetComputerNameW failed with error %d\n", GetLastError());
        HeapFree(GetProcessHeap(), 0, nameW);
    }
}
示例#2
0
std::string EnvironmentImpl::nodeNameImpl()
{
	char name[MAX_COMPUTERNAME_LENGTH + 1];
	DWORD size = sizeof(name);
	if (GetComputerNameA(name, &size) == 0) throw SystemException("Cannot get computer name");
	return std::string(name);
}
示例#3
0
int kde_gethostname(char *__name, size_t __len)
{
  DWORD len = __len;
  if (0==GetComputerNameA(__name, &len))
    return -1;
  return 0;
}
void do_date(void)
{
    OSVERSIONINFOA verinfo;
    CHAR buf[128];
    time_t t = time(NULL);
    DWORD dwSize;
    CHAR szComp[MAX_PATH], szUser[MAX_PATH];

    // OS info
    verinfo.dwOSVersionInfoSize = sizeof(verinfo);
    GetVersionExA(&verinfo);
    sprintf(buf, "Microsoft Windows [Version %u.%u.%u]",
        verinfo.dwMajorVersion, verinfo.dwMinorVersion, verinfo.dwBuildNumber);
    if (nyarlathotep_p)
        do_nyarlathotep_buffer(buf);
    puts(buf);

    // computer_name - user_name
    dwSize = MAX_PATH;
    GetComputerNameA(szComp, &dwSize);
    dwSize = MAX_PATH;
    GetUserNameA(szUser, &dwSize);
    sprintf(buf, "%s - %s", szComp, szUser);
    if (nyarlathotep_p)
        do_nyarlathotep_buffer(buf);
    puts(buf);

    // Thu Nov 28 14:52:58     2013
    strftime(buf, 64, "%a %b %d %H:%M:%S     %Y", localtime(&t));
    if (nyarlathotep_p)
        do_nyarlathotep_buffer(buf);
    puts(buf);
}
示例#5
0
/**
 * Retrieve the name of the system. 'name_size' is size of the buffer pointed
 * to by 'name'.
 * Returns the length of the name.
 */
unsigned pixie_get_host_name(char *name, unsigned name_size)
{
#ifdef WIN32
	/*
	BOOL WINAPI GetComputerName(
	  __out    LPTSTR lpBuffer,
	__inout  LPDWORD lpnSize
	);
	Return Value: If the function succeeds, the return value is a nonzero value.
	The variable 'lpnsize' must be set to the length of the number of
	bytes in the string, and it be set to the resulting length */
	if (GetComputerNameA(name, &name_size))
		return name_size;
	else
		return 0;
#else
	/*
	int gethostname(char *name, size_t namelen)
	'namelen' is the size of the 'name' buffer.
	Returns 0 on success, -1 on failure
	*/
	if (gethostname(name, name_size) == 0) {
		/* If the buffer is too small, it might not nul terminate the
		 * string, so let's guarantee a nul-termination */
		name[name_size-1] = '\0';
		return name_size;
	} else
		return 0;
#endif
}
示例#6
0
string IMVLFile::GetCompName() 
{
	char buf[1024];
	DWORD dwCompNameLen = 1024;
	GetComputerNameA(buf, &dwCompNameLen);
	return string(buf);
}
示例#7
0
char *iupdrvGetComputerName(void)
{
  DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
  char* str = iupStrGetMemory(size);
  GetComputerNameA((LPSTR)str, &size);
  return str;
}
示例#8
0
	std::string GetComputerName_w()
	{
		char computerName[MAX_COMPUTERNAME_LENGTH + 1];
		DWORD t = MAX_COMPUTERNAME_LENGTH + 1;
		GetComputerNameA(computerName, &t);
		return computerName;
	}
示例#9
0
std::string CSystem::getComputerName()
{
	char computerName[256] = {};
	DWORD length = 256;
	GetComputerNameA(computerName, &length);
	return computerName;
}
示例#10
0
std::string getComputer(){
    inoutsize=INFO_BUFFER_SIZE;
    if( !GetComputerNameA( infoBuf, &inoutsize ) ){
        return "";
    }
    std::string ret = infoBuf;
    return ret;
}
示例#11
0
std::string CPlatform::ComputerName()
{
	std::string name;
	char info[256] = {};
	DWORD size = 256;
	GetComputerNameA(info, &size);
	name.append((char*)info, size);
	return name;
}
示例#12
0
//摘要信息
const std::string GetSummary(HANDLE hProcess)
{
	std::string strRet;
	char szTemp[1024] = {0};

	PROCESS_MEMORY_COUNTERS memInfo;
	GetProcessMemoryInfo(hProcess, &memInfo, sizeof(PROCESS_MEMORY_COUNTERS));
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "WorkingSetSize=%.2fM\r\n", (double)memInfo.WorkingSetSize/(1024*1024));
	strRet += szTemp;
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "PagefileUsage=%.2fM\r\n", (double)memInfo.PagefileUsage /(1024*1024));
	strRet += szTemp;

	char szName[1024] = {0};
	DWORD cchName = _countof(szName);
	::GetUserNameA(szName, &cchName);
	szName[cchName] = 0;
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "UserName=%s\r\n", szName);
	strRet += szTemp;

	memset(szName, 0, sizeof(szName));
	cchName = _countof(szName);
	GetComputerNameA(szName, &cchName);
	szName[cchName] = 0;
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "ComputerName=%s\r\n", szName);
	strRet += szTemp;

	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "OSVer=%s\r\n", GetOSVer().c_str());	
	strRet += szTemp;

	SYSTEM_INFO	SystemInfo = {0};
	GetSystemInfo(&SystemInfo);
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "CPU=%d processor(s), type %d arch %d\r\n", SystemInfo.dwNumberOfProcessors, SystemInfo.dwProcessorType, SystemInfo.wProcessorArchitecture);
	strRet += szTemp;
  
  //YYBrowser Begin
  //GlobalMemoryStatus这个api本身就是有bug的。详细:http://msdn.microsoft.com/en-us/library/aa366586(v=vs.85).aspx
  //改为GlobalMemoryStatusEx.add by hzz 2014-10-28 14:43:42
	MEMORYSTATUSEX memoryStatus;
	memoryStatus.dwLength = sizeof(MEMORYSTATUSEX);
	GlobalMemoryStatusEx(&memoryStatus);
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "MemoryLoad=%d\r\n", memoryStatus.dwMemoryLoad);
	strRet += szTemp;
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "TotalPhys=%.2fM\r\n", (double)memoryStatus.ullTotalPhys/(1024*1024));
	strRet += szTemp;
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "AvailPhys=%.2fM\r\n", (double)memoryStatus.ullAvailPhys/(1024*1024));
	strRet += szTemp;
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "TotalVirtual=%.2fM\r\n", (double)memoryStatus.ullTotalVirtual/(1024*1024));
	strRet += szTemp;
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "AvailVirtual=%.2fM\r\n", (double)memoryStatus.ullAvailVirtual/(1024*1024));
	strRet += szTemp;
  //YYBrowser End
	UINT driveType = GetDriveType(NULL);
	_snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "DriveType=%d\r\n", driveType);
	strRet += szTemp;

	return strRet;
}
示例#13
0
文件: test.cpp 项目: abma/injector
//program to test GetComputerNameA hook
int main(){
	char buf[512];
	unsigned long len = sizeof(buf);
	if (GetComputerNameA(buf, &len)) {
		printf("GetComputerNameA returns: \"%s\"\n", buf);
	} else {
		printf("Call of GetComputerNameA failed!\n");
	}
	return 0;
}
示例#14
0
文件: xolehlp.c 项目: sriemer/wine
static BOOL is_local_machineA( const CHAR *server )
{
    static const CHAR dot[] = ".";
    CHAR buffer[MAX_COMPUTERNAME_LENGTH + 1];
    DWORD len = sizeof(buffer) / sizeof(buffer[0]);

    if (!server || !strcmp( server, dot )) return TRUE;
    if (GetComputerNameA( buffer, &len ) && !lstrcmpiA( server, buffer )) return TRUE;
    return FALSE;
}
示例#15
0
const char* system_hostname( void )
{
	unsigned long size = 255;
	static char hostname[256] = {0};
	if( hostname[0] )
		return hostname;
	strcpy( hostname, "<unknown>" );
	GetComputerNameA( hostname, &size );
	hostname[255] = 0;
	return hostname;
}
示例#16
0
/***********************************************************************
 *              GetComputerNameExA         (KERNEL32.@)
 */
BOOL WINAPI GetComputerNameExA(COMPUTER_NAME_FORMAT type, LPSTR name, LPDWORD size)
{
    char buf[256];
    int len = sizeof(buf) - 1, ret;
    TRACE("%d, %p, %p\n", type, name, size);
    switch( type )
    {
    case ComputerNameNetBIOS:
    case ComputerNamePhysicalNetBIOS:
        ret = GetComputerNameA (name, size);
        if (!ret && GetLastError() == ERROR_BUFFER_OVERFLOW)
            SetLastError( ERROR_MORE_DATA );
        return ret;

    case ComputerNameDnsHostname:
    case ComputerNamePhysicalDnsHostname:
        ret = dns_hostname (buf, &len);
        break;
    case ComputerNameDnsDomain:
    case ComputerNamePhysicalDnsDomain:
        ret = dns_domainname (buf, &len);
        break;
    case ComputerNameDnsFullyQualified:
    case ComputerNamePhysicalDnsFullyQualified:
        ret = dns_fqdn (buf, &len);
        break;
    default:
        SetLastError (ERROR_INVALID_PARAMETER);
        return FALSE;
    }

    if ( ret )
    {
        TRACE ("-> %s (%d)\n", debugstr_a (buf), len);
        if ( *size < len + 1 )
        {
            *size = len + 1;
            SetLastError( ERROR_MORE_DATA );
            ret = FALSE;
        }
        else
        {
            memcpy( name, buf, len );
            name[len] = 0;
            *size = len;
            ret = TRUE;
        }
    }

    return ret;
}
示例#17
0
/* Windows replacement for gethostname() */
int mingw_compat_gethostname(char *name, size_t len) {
  char buf[MAX_COMPUTERNAME_LENGTH + 1];
  int r;
  DWORD len1 = sizeof(buf);

  r = GetComputerNameA(buf, &len1);
  if (r==0) {
    name[0] = '\0';
  } else {
    strncpy(name, buf, len-1);
    name[len-1] = '\0';
  }
  return 0;
}
示例#18
0
文件: System.cpp 项目: starand/cpp
bool GetCompName(string& sOutCompName)
{
	char szBuffer[MAX_COMPUTERNAME_LENGTH + 1];
	DWORD dwBufferLength = MAX_COMPUTERNAME_LENGTH;

	bool bResult = false;
	if (GetComputerNameA(szBuffer, &dwBufferLength) != 0)
	{
		sOutCompName = szBuffer;
		bResult = true;
	}

	return bResult;
}
示例#19
0
/* Implementation of :u filename modifier. */
static int
apply_u_mod(const char *path, char *buf, size_t buf_len)
{
	if(!is_unc_path(path))
	{
		DWORD size = buf_len - 2;
		snprintf(buf, buf_len, "//");
		GetComputerNameA(buf + 2, &size);
		return 0;
	}
	snprintf(buf, buf_len, "%s", path);
	break_at(buf + 2, '/');
	return 0;
}
示例#20
0
文件: bsdname.c 项目: basecq/q2dos
/*
 * Get hostname excluding domain-name
 */
int _get_machine_name (char *buf, int size)
{
  int     rc;
  DWORD   sz  = size;
  HMODULE mod = GetModuleHandle ("KERNEL32.DLL");
  BOOL (WINAPI *_GetComputerNameExA) (int, char*, DWORD*) = NULL;
  typedef BOOL (WINAPI *gcn_ex) (int, char*, DWORD*);

  if (mod)
     _GetComputerNameExA = (gcn_ex) GetProcAddress (mod, "GetComputerNameExA");

  if (!_GetComputerNameExA)
       rc = GetComputerNameA (buf, &sz);
  else rc = (*_GetComputerNameExA) (ComputerNameDnsHostname, buf, &sz);

  rc = rc ? 0 : -1;
  TCP_CONSOLE_MSG (2, ("_get_machine_name(): \"%s\", rc %d\n", buf, rc));
  return (rc);
}
示例#21
0
void MachineInfo::make_info()
{
	//FunctionHooks* FH = new FunctionHooks;
	
	DWORD size;
	size = MAX_COMPUTERNAME_LENGTH + 1;
	
	GetComputerNameA(this->PC_Name, &size); // Wpisanie nazwy komputera

	size = UNLEN + 1;

	GetUserNameA(this->Username, &size); // Wpisanie nazwy u¿ytkownika

	
	/*----------------Wpisanie informacji o maksymalnym taktowaniu CPU--------------------*/
	SYSTEM_INFO sysInfo;
	GetSystemInfo(&sysInfo);
	size = sysInfo.dwNumberOfProcessors * sizeof(PROCESSOR_POWER_INFORMATION);
	LPBYTE buf = new BYTE[size];
	CallNtPowerInformation(ProcessorInformation, NULL, 0, buf, size);
	PPROCESSOR_POWER_INFORMATION cpuinfo = (PPROCESSOR_POWER_INFORMATION)buf;
	std::string full_cpu_ratio = intToStr(cpuinfo->MaxMhz) + "GHz";
	full_cpu_ratio.erase(3, 1);
	full_cpu_ratio.insert(1, ".");
	memcpy(this->CPU_clock, full_cpu_ratio.c_str(), sizeof(full_cpu_ratio));
	/*------------------------------------------------------------------------------------*/


	/*-----------------------Sprawdzenie wersji systemu Windows---------------------------*/
	if (IsWindows8Point1OrGreater())memcpy(this->OS, "Windows 8.1", sizeof("Windows 8.1"));
	else
	if (IsWindows7OrGreater())memcpy(this->OS, "Windows 7", sizeof("Windows 7"));
	else
	if (IsWindowsVistaOrGreater())memcpy(this->OS, "Windows Vista", sizeof("Windows Vista"));
	else
	if (IsWindowsXPOrGreater())memcpy(this->OS, "Windows XP", sizeof("Windows XP"));
	/*------------------------------------------------------------------------------------*/

}
示例#22
0
文件: CLog.cpp 项目: happy0123/log
    // 获取主机名称 // copied from logging.cc
    void GetHostName(string* hostname)
    {
#if defined(HAVE_SYS_UTSNAME_H)
        struct utsname buf;
        if (0 != uname(&buf)) {
            // ensure null termination on failure
            *buf.nodename = '\0';
        }
        *hostname = buf.nodename;
#elif defined(WIN32)
        char buf[MAX_COMPUTERNAME_LENGTH + 1];
        DWORD len = MAX_COMPUTERNAME_LENGTH + 1;
        if (GetComputerNameA(buf, &len)) {
            *hostname = buf;
        } else {
            hostname->clear();
        }
#else
        //# warning There is no way to retrieve the host name.
        *hostname = "(unknown)";
#endif
    }
示例#23
0
static int
Win32_GetComputerName(Jim_Interp *interp, int objc, Jim_Obj * const *objv)
{
    char name[MAX_COMPUTERNAME_LENGTH + 1];
    DWORD size = MAX_COMPUTERNAME_LENGTH;
    int r = JIM_OK;

    if (objc != 1) {
        Jim_WrongNumArgs(interp, 1, objv, "");
        return JIM_ERR;
    }

    if (GetComputerNameA(name, &size)) {
        Jim_Obj *nameObj = Jim_NewStringObj(interp, name, size);
        Jim_SetResult(interp, nameObj);
    } else {
        Jim_SetResult(interp,
            Win32ErrorObj(interp, "GetComputerName", GetLastError()));
        r = JIM_ERR;
    }

    return r;
}
示例#24
0
/* Sample code, not for use in production; see RFC 1750 */
void get_random_info(char seed[16])
{
    MD5_CTX c;
    struct {
        MEMORYSTATUS m;
        SYSTEM_INFO s;
        FILETIME t;
        LARGE_INTEGER pc;
        DWORD tc;
        DWORD l;
        char hostname[MAX_COMPUTERNAME_LENGTH + 1];
    } r;

    MD5Init(&c);
    GlobalMemoryStatus(&r.m);
    GetSystemInfo(&r.s);
    GetSystemTimeAsFileTime(&r.t);
    QueryPerformanceCounter(&r.pc);
    r.tc = GetTickCount();
    r.l = MAX_COMPUTERNAME_LENGTH + 1;
    GetComputerNameA(r.hostname, &r.l);
    MD5Update(&c, &r, sizeof r);
    MD5Final(seed, &c);
}
示例#25
0
文件: wutsname.cpp 项目: Marlinc/0ad
int uname(struct utsname* un)
{
	OSVERSIONINFOW vi = { sizeof(OSVERSIONINFOW) };
	GetVersionExW(&vi);

	// OS implementation name
	sprintf_s(un->sysname, ARRAY_SIZE(un->sysname), "%ls", wversion_Family());

	// release info
	const wchar_t* vs = vi.szCSDVersion;
	int sp;
	if(swscanf_s(vs, L"Service Pack %d", &sp) == 1)
		sprintf_s(un->release, ARRAY_SIZE(un->release), "SP %d", sp);
	else
		un->release[0] = '\0';

	// version
	sprintf_s(un->version, ARRAY_SIZE(un->version), "%ls.%lu", wversion_String(), vi.dwBuildNumber & 0xFFFF);

	// node name
	{
		WinScopedPreserveLastError s;	// GetComputerName
		DWORD bufSize = sizeof(un->nodename);
		WARN_IF_FALSE(GetComputerNameA(un->nodename, &bufSize));
	}

	// hardware type
	SYSTEM_INFO si;
	GetSystemInfo(&si);
	if(si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
		strcpy_s(un->machine, ARRAY_SIZE(un->machine), "x64");
	else
		strcpy_s(un->machine, ARRAY_SIZE(un->machine), "x86");

	return 0;
}
示例#26
0
/******************************************************************************
 * ReportEventA [ADVAPI32.@]
 */
BOOL WINAPI
ReportEventA(IN HANDLE hEventLog,
             IN WORD wType,
             IN WORD wCategory,
             IN DWORD dwEventID,
             IN PSID lpUserSid,
             IN WORD wNumStrings,
             IN DWORD dwDataSize,
             IN LPCSTR *lpStrings,
             IN LPVOID lpRawData)
{
    NTSTATUS Status;
    PANSI_STRING *Strings;
    ANSI_STRING ComputerName;
    WORD i;
    CHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
    DWORD dwSize;
    LARGE_INTEGER SystemTime;
    ULONG Seconds;

    TRACE("%p, %u, %u, %lu, %p, %u, %lu, %p, %p\n",
          hEventLog, wType, wCategory, dwEventID, lpUserSid,
          wNumStrings, dwDataSize, lpStrings, lpRawData);

    Strings = HeapAlloc(GetProcessHeap(),
                        HEAP_ZERO_MEMORY,
                        wNumStrings * sizeof(PANSI_STRING));
    if (!Strings)
    {
        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
        return FALSE;
    }

    for (i = 0; i < wNumStrings; i++)
    {
        Strings[i] = HeapAlloc(GetProcessHeap(),
                               HEAP_ZERO_MEMORY,
                               sizeof(ANSI_STRING));
        if (Strings[i])
        {
            RtlInitAnsiString(Strings[i], lpStrings[i]);
        }
    }

    dwSize = MAX_COMPUTERNAME_LENGTH + 1;
    GetComputerNameA(szComputerName, &dwSize);
    RtlInitAnsiString(&ComputerName, szComputerName);

    NtQuerySystemTime(&SystemTime);
    RtlTimeToSecondsSince1970(&SystemTime, &Seconds);

    RpcTryExcept
    {
        Status = ElfrReportEventA(hEventLog,
        Seconds,
        wType,
        wCategory,
        dwEventID,
        wNumStrings,
        dwDataSize,
        (PRPC_STRING)&ComputerName,
        lpUserSid,
        (PRPC_STRING*)Strings,
        lpRawData,
        0,
        NULL,
        NULL);
    }
    RpcExcept(EXCEPTION_EXECUTE_HANDLER)
    {
        Status = I_RpcMapWin32Status(RpcExceptionCode());
    }
    RpcEndExcept;

    for (i = 0; i < wNumStrings; i++)
    {
        if (Strings[i] != NULL)
            HeapFree(GetProcessHeap(), 0, Strings[i]);
    }

    HeapFree(GetProcessHeap(), 0, Strings);

    if (!NT_SUCCESS(Status))
    {
        SetLastError(RtlNtStatusToDosError(Status));
        return FALSE;
    }

    return TRUE;
}
DWORD GetHWIDchunk(int chunk)
{	VU("GetHWIDchunk");

	int res = -1;

	switch (chunk)
	{
	case 1:
		{
			//CPUID
			char cpudata[0x50];
			memset(cpudata, 0, 0x50);
				
			__asm
			{
				pushad
				lea edi, cpudata
				add edi, 0x4C
				mov esi, 0x80000004

				mov eax, 0x80000000
				cpuid
				cmp eax, esi
				jl errora
			loopa:
				mov eax, esi
				cpuid

				mov [edi], edx
				mov [edi-4], ecx
				mov [edi-8], ebx
				mov [edi-12], eax
				sub edi, 0x10

				dec esi
				cmp esi, 0x7FFFFFFF
				jne loopa

				mov res, 1
				jmp exita
			errora:
				mov res, 0
			exita:
				popad
			}

			PrintBuffer((BYTE *)cpudata, 0x50, 16);
			info("GetHWIDchunk(%d) %d res", chunk, res);

			if (res = 1) return GetCRC32(cpudata, 0x50);
		
			info("GetHWIDchunk() Fail, returning default for request %d.", chunk);
			return 0xBAADD00D;
		}
		break;
	case 2:
		{
			//windows installation date
			char windir[256];
			memset(windir, 0, 256);
			GetWindowsDirectoryA(windir, 255);
			info("GetHWIDchunk()  Windows folder = %s", windir);

			struct _stat32 f_stats; 

			if (_stat32(windir, &f_stats) == 0)
			{
				char timebuf[256];
				_ctime32_s(timebuf, 26, &f_stats.st_ctime);
				info("GetHWIDchunk() Windows folder (%s) creation date = %s", windir, timebuf);

				if (strstr(timebuf, V(" 201")) == NULL && strstr(timebuf, V(" 200")) == NULL) return 0xBAADD00D;

				return f_stats.st_ctime ^ GetCRC32(windir, 20);
			}


			info("GetHWIDchunk() Fail, returning default for request %d.", chunk);
			return 0xBAADD00D;
		}
		break;
	case 3:
		{
			char compname[256];
			memset(compname, 0, 256);
			DWORD maxlen = 256;
			GetComputerNameA(compname, &maxlen);

			return GetCRC32(compname, sizeof(compname));
		}
		break;
	default:
		return 0;
	}

	return 0;

	VE();
}
int n_GCreateMyOperationMsg( DWORD dwFlags, DWORD dwMsgNum, char* lpszPictureName, char* lpszObjectName, char* lpszTagName, char* lpszObjectName1, char* lpszActionName, float doValueOld, float doValueNew, char* pszComment )
{

    MSG_RTDATA_INSTANCECOMMENT_STRUCT   MsgCreateEx;
    MSG_RTDATA_STRUCT                                                   MsgRTData;          // for comment dialog
    CMN_ERROR                                                                          scError;   
    int                                                                                                   iRet= FALSE;
    DWORD                                                                                     dwServiceID = 0;
    BOOL                                                                                           bOK;
    SYSTEMTIME                                                                          time;
    DWORD                                                                                     dwBufSize   = 256;

    char szComputerName[256] = "";
    char* szCurrentUser = NULL;
    char * pszServerPrefix = NULL;
//    char* pszPrefix;        // to define the type of WinCC project
//    char* lpszParent;
    char szTmp[256] = "";   // for diagnosis output

    printf("Start n_GCreateMyOperationMsg \r\n");

    //======================================
    // INIT_MESSAGE_STRUCT
    //======================================
    memset(&MsgCreateEx,0,sizeof(MsgCreateEx));
    memset(&MsgRTData,0,sizeof(MsgRTData));
    memset(&scError,0,sizeof(scError));

    GetLocalTime(&time);
    MsgCreateEx.stMsgTime = time;
    MsgRTData.stMsgTime = time;
   
    MsgCreateEx.dwMsgNr = dwMsgNum;             
    MsgRTData.dwMsgNr = dwMsgNum;
   
    MsgCreateEx.wPValueUsed = (WORD)(0x0000 );  // no real process value used
    MsgRTData.wPValueUsed = (WORD)(0x0000 );
    MsgCreateEx.wTextValueUsed  = 0x03FF;       // text values 1 .. 10 used for textblocks 1 .. 10
    MsgRTData.wTextValueUsed    = 0x03FF;       // text values 1 .. 10 used for textblocks 1 .. 10
    MsgCreateEx.dwFlags =  MSG_FLAG_TEXTVALUES;
    MsgRTData.dwFlags = MSG_FLAG_COMMENT | MSG_FLAG_TEXTVALUES;

    MsgCreateEx.dwMsgState = MSG_STATE_COME;     
    MsgRTData.dwMsgState = MSG_STATE_COME;     

    //======================================
    // INITIALIZATION PROCESS VALUE BLOCKS 1..10
    //======================================
    GetComputerNameA(szComputerName, &dwBufSize);
//    sprintf(szTmp, "Computername = %s  \r\n", szComputerName);
    strncpy ( MsgCreateEx.mtTextValue[0].szText, szComputerName, sizeof (MsgCreateEx.mtTextValue[0].szText) - 1);     // Computer Name

//    printf("Start n_GCreateMyOperationMsg \r\n");

    szCurrentUser = GetTagChar("@local::@CurrentUser");
    strncpy ( MsgCreateEx.mtTextValue[1].szText, szCurrentUser, sizeof (MsgCreateEx.mtTextValue[1].szText) - 1);     // Current User Name

    MsgCreateEx.wPValueUsed  = (WORD)(MsgCreateEx.wPValueUsed | 0x000C);
     MsgCreateEx.dPValue[2] = doValueOld;            // old value
     MsgCreateEx.dPValue[3] = doValueNew;            // new value

    strncpy ( MsgCreateEx.mtTextValue[4].szText, lpszPictureName, sizeof (MsgCreateEx.mtTextValue[4].szText) - 1);     // lpszPictureName
    strncpy ( MsgCreateEx.mtTextValue[5].szText, lpszObjectName, sizeof (MsgCreateEx.mtTextValue[5].szText) - 1);     // lpszObjectName

    strncpy ( MsgCreateEx.mtTextValue[6].szText, lpszTagName, sizeof (MsgCreateEx.mtTextValue[6].szText) - 1);     // lpszTagName
    strncpy ( MsgCreateEx.mtTextValue[7].szText, lpszActionName, sizeof (MsgCreateEx.mtTextValue[7].szText) - 1);     // lpszActionName
    strncpy ( MsgCreateEx.mtTextValue[8].szText, lpszObjectName1, sizeof (MsgCreateEx.mtTextValue[8].szText) - 1);     // lpszObjectName1
    //======================================


    //======================================
    // START_MESSAGE_SERVICE
    //======================================
    memset(&scError,0,sizeof(scError));


    // GetServerPrefix to determine MC or Server
    GetServerTagPrefix(&pszServerPrefix, NULL, NULL);   //Return-Type: void
     if (NULL == pszServerPrefix)
    {
        printf("Serverapplication or Single Client\r\n");
        bOK = MSRTStartMsgService( &dwServiceID, NULL, NULL, 0, NULL, &scError ); // activate service
    }
    else   
    {
        printf("MultiClient with Prefix : %s\r\n",pszServerPrefix);   //Return - Type :char*
        bOK = MSRTStartMsgServiceMC( &dwServiceID, NULL, NULL, 0, NULL,pszServerPrefix, &scError ); // activate service
    }

    if (bOK == FALSE)
    {
       printf("n_GCreateMyOperationMsg() - Unable to start message service! \r\n");
       sprintf(szTmp, " Error1 = 0x%0x, Errortext = %s \r\n", scError.dwError1, scError.szErrorText);
       printf(szTmp);
     
       return (-101);
    }
    //======================================


    //======================================
    // PARSE PARAMETERS
    //======================================
    if (  ( dwFlags & FLAG_COMMENT_PARAMETER )  && ( NULL != pszComment  ) )
    {
      strncpy(MsgCreateEx.szComment, pszComment, sizeof (MsgCreateEx.szComment) - 1);
      MsgCreateEx.dwFlags |= MSG_FLAG_COMMENT;
    }

    if ( dwFlags & FLAG_COMMENT_DIALOG )
      MsgCreateEx.dwFlags |= MSG_FLAG_COMMENT;
    //======================================


    //======================================
    // CREATE MESSAGE
    //======================================
    bOK = MSRTCreateMsgInstanceWithComment(dwServiceID, &MsgCreateEx, &scError) ;
    if ( TRUE == bOK)
    {
        if (FLAG_COMMENT_DIALOG == (dwFlags & FLAG_COMMENT_DIALOG) )
        {
               BOOL   bOkay;
               HWND hWnd = FindWindow(NULL, "WinCC-Runtime - ");

              memset(&scError,0,sizeof(scError));
              bOkay=  MSRTDialogComment (hWnd,  &MsgRTData,  &scError);
              if (TRUE == bOkay)
              {
                      MSG_COMMENT_STRUCT    mComment;
                      mComment.dwMsgNr = dwMsgNum;
                      mComment.stTime = time;
                      sprintf( mComment.szUser, MsgCreateEx.szUser, sizeof(mComment.szUser) - 1 );

                      memset(&scError,0,sizeof(scError));
                      bOkay = MSRTGetComment (dwServiceID, &mComment, &scError);
                      if (TRUE == bOkay)
                      {
                            strncpy(MsgCreateEx.szComment, mComment.szText, sizeof (MsgCreateEx.szComment) - 1);
                     }
              }
              else
              {
                      printf("#E201: n_GCreateMyOperationMsg()  - Error at MSRTGetComment()  szErrorText="%s" error2=%d\r\n", scError.szErrorText, scError.dwError2);
                      iRet = -201;
              }
       }
 
    }


    if(bOK == FALSE)
    {
      printf ("#E301: n_GCreateMyOperationMsg()  - Error at MSRTCreateMsgInstanceWithComment()  szErrorText="%s"\r\n", scError.szErrorText);
      iRet = -301;
    }
    //======================================


    //======================================
    // STOP_MESSAGE_SERVICE
    //======================================
    bOK= MSRTStopMsgService(    dwServiceID, &scError);
    printf("End n_GCreateMyOperationMsg \r\n");
    return (iRet);
}
示例#29
0
文件: eventlog.c 项目: AndreRH/wine
static void test_readwrite(void)
{
    HANDLE handle;
    PSID user;
    DWORD sidsize, count;
    BOOL ret, sidavailable;
    BOOL on_vista = FALSE; /* Used to indicate Vista, W2K8 or Win7 */
    DWORD i;
    char *localcomputer = NULL;
    DWORD size;

    if (pCreateWellKnownSid)
    {
        sidsize = SECURITY_MAX_SID_SIZE;
        user = HeapAlloc(GetProcessHeap(), 0, sidsize);
        SetLastError(0xdeadbeef);
        pCreateWellKnownSid(WinInteractiveSid, NULL, user, &sidsize);
        sidavailable = TRUE;
    }
    else
    {
        win_skip("Skipping some SID related tests\n");
        sidavailable = FALSE;
        user = NULL;
    }

    /* Write an event with an incorrect event type. This will fail on Windows 7
     * but succeed on all others, hence it's not part of the struct.
     */
    handle = OpenEventLogA(NULL, eventlogname);
    if (!handle)
    {
        /* Intermittently seen on NT4 when tests are run immediately after boot */
        win_skip("Could not get a handle to the eventlog\n");
        goto cleanup;
    }

    count = 0xdeadbeef;
    GetNumberOfEventLogRecords(handle, &count);
    if (count != 0)
    {
        /* Needed for W2K3 without a service pack */
        win_skip("We most likely opened the Application eventlog\n");
        CloseEventLog(handle);
        Sleep(2000);

        handle = OpenEventLogA(NULL, eventlogname);
        count = 0xdeadbeef;
        GetNumberOfEventLogRecords(handle, &count);
        if (count != 0)
        {
            win_skip("We didn't open our new eventlog\n");
            CloseEventLog(handle);
            goto cleanup;
        }
    }

    SetLastError(0xdeadbeef);
    ret = ReportEventA(handle, 0x20, 0, 0, NULL, 0, 0, NULL, NULL);
    if (!ret && GetLastError() == ERROR_CRC)
    {
        win_skip("Win7 fails when using incorrect event types\n");
        ret = ReportEventA(handle, 0, 0, 0, NULL, 0, 0, NULL, NULL);
        ok(ret, "Expected success : %d\n", GetLastError());
    }
    else
    {
        void *buf;
        DWORD read, needed = 0;
        EVENTLOGRECORD *record;

        ok(ret, "Expected success : %d\n", GetLastError());

        /* Needed to catch earlier Vista (with no ServicePack for example) */
        buf = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTLOGRECORD));
        if (!(ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
                                  0, buf, sizeof(EVENTLOGRECORD), &read, &needed)) &&
            GetLastError() == ERROR_INSUFFICIENT_BUFFER)
        {
            buf = HeapReAlloc(GetProcessHeap(), 0, buf, needed);
            ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
                                0, buf, needed, &read, &needed);
        }
        if (ret)
        {
            record = (EVENTLOGRECORD *)buf;

            /* Vista and W2K8 return EVENTLOG_SUCCESS, Windows versions before return
             * the written eventtype (0x20 in this case).
             */
            if (record->EventType == EVENTLOG_SUCCESS)
                on_vista = TRUE;
        }
        HeapFree(GetProcessHeap(), 0, buf);
    }

    /* This will clear the eventlog. The record numbering for new
     * events however differs on Vista SP1+. Before Vista the first
     * event would be numbered 1, on Vista SP1+ it's higher as we already
     * had at least one event (more in case of multiple test runs without
     * a reboot).
     */
    ClearEventLogA(handle, NULL);
    CloseEventLog(handle);

    /* Write a bunch of events while using different event sources */
    for (i = 0; i < sizeof(read_write)/sizeof(read_write[0]); i++)
    {
        DWORD oldest;
        BOOL run_sidtests = read_write[i].evt_sid & sidavailable;

        /* We don't need to use RegisterEventSource to report events */
        if (i % 2)
            handle = OpenEventLogA(NULL, read_write[i].evt_src);
        else
            handle = RegisterEventSourceA(NULL, read_write[i].evt_src);
        ok(handle != NULL, "Expected a handle\n");

        SetLastError(0xdeadbeef);
        ret = ReportEventA(handle, read_write[i].evt_type, read_write[i].evt_cat,
                           read_write[i].evt_id, run_sidtests ? user : NULL,
                           read_write[i].evt_numstrings, 0, read_write[i].evt_strings, NULL);
        ok(ret, "Expected ReportEvent success : %d\n", GetLastError());

        count = 0xdeadbeef;
        SetLastError(0xdeadbeef);
        ret = GetNumberOfEventLogRecords(handle, &count);
        ok(ret, "Expected GetNumberOfEventLogRecords success : %d\n", GetLastError());
        todo_wine
        ok(count == (i + 1), "Expected %d records, got %d\n", i + 1, count);

        oldest = 0xdeadbeef;
        ret = GetOldestEventLogRecord(handle, &oldest);
        ok(ret, "Expected GetOldestEventLogRecord success : %d\n", GetLastError());
        todo_wine
        ok(oldest == 1 ||
           (oldest > 1 && oldest != 0xdeadbeef), /* Vista SP1+, W2K8 and Win7 */
           "Expected oldest to be 1 or higher, got %d\n", oldest);
        if (oldest > 1 && oldest != 0xdeadbeef)
            on_vista = TRUE;

        SetLastError(0xdeadbeef);
        if (i % 2)
            ret = CloseEventLog(handle);
        else
            ret = DeregisterEventSource(handle);
        ok(ret, "Expected success : %d\n", GetLastError());
    }

    handle = OpenEventLogA(NULL, eventlogname);
    count = 0xdeadbeef;
    ret = GetNumberOfEventLogRecords(handle, &count);
    ok(ret, "Expected success\n");
    todo_wine
    ok(count == i, "Expected %d records, got %d\n", i, count);
    CloseEventLog(handle);

    if (count == 0)
    {
        skip("No events were written to the eventlog\n");
        goto cleanup;
    }

    /* Report only once */
    if (on_vista)
        skip("There is no DWORD alignment enforced for UserSid on Vista, W2K8 or Win7\n");

    if (on_vista && pGetComputerNameExA)
    {
        /* New Vista+ behavior */
        size = 0;
        SetLastError(0xdeadbeef);
        pGetComputerNameExA(ComputerNameDnsFullyQualified, NULL, &size);
        localcomputer = HeapAlloc(GetProcessHeap(), 0, size);
        pGetComputerNameExA(ComputerNameDnsFullyQualified, localcomputer, &size);
    }
    else
    {
        size = MAX_COMPUTERNAME_LENGTH + 1;
        localcomputer = HeapAlloc(GetProcessHeap(), 0, size);
        GetComputerNameA(localcomputer, &size);
    }

    /* Read all events from our created eventlog, one by one */
    handle = OpenEventLogA(NULL, eventlogname);
    ok(handle != NULL, "Failed to open Event Log, got %d\n", GetLastError());
    i = 0;
    for (;;)
    {
        void *buf;
        DWORD read, needed;
        EVENTLOGRECORD *record;
        char *sourcename, *computername;
        int k;
        char *ptr;
        BOOL run_sidtests = read_write[i].evt_sid & sidavailable;

        buf = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTLOGRECORD));
        SetLastError(0xdeadbeef);
        ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
                            0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
        ok(!ret, "Expected failure\n");
        if (!ret && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
        {
            HeapFree(GetProcessHeap(), 0, buf);
            ok(GetLastError() == ERROR_HANDLE_EOF, "record %d, got %d\n", i, GetLastError());
            break;
        }

        buf = HeapReAlloc(GetProcessHeap(), 0, buf, needed);
        ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
                            0, buf, needed, &read, &needed);
        ok(ret, "Expected success: %d\n", GetLastError());

        record = (EVENTLOGRECORD *)buf;

        ok(record->Length == read,
           "Expected %d, got %d\n", read, record->Length);
        ok(record->Reserved == 0x654c664c,
           "Expected 0x654c664c, got %d\n", record->Reserved);
        ok(record->RecordNumber == i + 1 ||
           (on_vista && (record->RecordNumber > i + 1)),
           "Expected %d or higher, got %d\n", i + 1, record->RecordNumber);
        ok(record->EventID == read_write[i].evt_id,
           "Expected %d, got %d\n", read_write[i].evt_id, record->EventID);
        ok(record->EventType == read_write[i].evt_type,
           "Expected %d, got %d\n", read_write[i].evt_type, record->EventType);
        ok(record->NumStrings == read_write[i].evt_numstrings,
           "Expected %d, got %d\n", read_write[i].evt_numstrings, record->NumStrings);
        ok(record->EventCategory == read_write[i].evt_cat,
           "Expected %d, got %d\n", read_write[i].evt_cat, record->EventCategory);

        sourcename = (char *)((BYTE *)buf + sizeof(EVENTLOGRECORD));
        ok(!lstrcmpA(sourcename, read_write[i].evt_src), "Expected '%s', got '%s'\n",
           read_write[i].evt_src, sourcename);

        computername = (char *)((BYTE *)buf + sizeof(EVENTLOGRECORD) + lstrlenA(sourcename) + 1);
        ok(!lstrcmpiA(computername, localcomputer), "Expected '%s', got '%s'\n",
           localcomputer, computername);

        /* Before Vista, UserSid was aligned on a DWORD boundary. Next to that if
         * no padding was actually required a 0 DWORD was still used for padding. No
         * application should be relying on the padding as we are working with offsets
         * anyway.
         */

        if (!on_vista)
        {
            DWORD calculated_sidoffset = sizeof(EVENTLOGRECORD) + lstrlenA(sourcename) + 1 + lstrlenA(computername) + 1;

            /* We are already DWORD aligned, there should still be some padding */
            if ((((UINT_PTR)buf + calculated_sidoffset) % sizeof(DWORD)) == 0)
                ok(*(DWORD *)((BYTE *)buf + calculated_sidoffset) == 0, "Expected 0\n");

            ok((((UINT_PTR)buf + record->UserSidOffset) % sizeof(DWORD)) == 0, "Expected DWORD alignment\n");
        }

        if (run_sidtests)
        {
            ok(record->UserSidLength == sidsize, "Expected %d, got %d\n", sidsize, record->UserSidLength);
        }
        else
        {
            ok(record->StringOffset == record->UserSidOffset, "Expected offsets to be the same\n");
            ok(record->UserSidLength == 0, "Expected 0, got %d\n", record->UserSidLength);
        }

        ok(record->DataLength == 0, "Expected 0, got %d\n", record->DataLength);

        ptr = (char *)((BYTE *)buf + record->StringOffset);
        for (k = 0; k < record->NumStrings; k++)
        {
            ok(!lstrcmpA(ptr, two_strings[k]), "Expected '%s', got '%s'\n", two_strings[k], ptr);
            ptr += lstrlenA(ptr) + 1;
        }

        ok(record->Length == *(DWORD *)((BYTE *)buf + record->Length - sizeof(DWORD)),
           "Expected the closing DWORD to contain the length of the record\n");

        HeapFree(GetProcessHeap(), 0, buf);
        i++;
    }
    CloseEventLog(handle);

    /* Test clearing a real eventlog */
    handle = OpenEventLogA(NULL, eventlogname);
    ok(handle != NULL, "Failed to open Event Log, got %d\n", GetLastError());

    SetLastError(0xdeadbeef);
    ret = ClearEventLogA(handle, NULL);
    ok(ret, "Expected success\n");

    count = 0xdeadbeef;
    ret = GetNumberOfEventLogRecords(handle, &count);
    ok(ret, "Expected success\n");
    ok(count == 0, "Expected an empty eventlog, got %d records\n", count);

    CloseEventLog(handle);

cleanup:
    HeapFree(GetProcessHeap(), 0, localcomputer);
    HeapFree(GetProcessHeap(), 0, user);
}
示例#30
0
void *ioc_alive_listen(void *data)
{
  aliveRecord *prec = (aliveRecord *) data;
  struct rpvtStruct *prpvt;

  SOCKET tcp_sockfd;
  int sflag;

  SOCKET client_sockfd;

  struct sockaddr_in l_addr;

  osiSocklen_t socklen;

  char *q;
  
  // key and value lengths, key length of zero means it doesn't exist
  int env_len[ENV_CNT][2]; 

  uint32_t msg32;
  uint16_t msg16, len16;
  uint8_t  len8;

  int length;
  int number;
  int type;

#if defined (vxWorks)
  BOOT_PARAMS bootparams;
#endif
#if defined (linux) || defined (darwin)
  char *user;
  char *group;
  char *hostname;
  char hostname_buffer[129];
#endif
#if defined (_WIN32)
  char *user;
  char user_buffer[80];
  char *machine;
  char machine_buffer[20];
#endif

  int i;

  prpvt = prec->rpvt;

#if defined (vxWorks)
  type = 1;
#elif defined (linux)
  type = 2;
#elif defined (darwin)
  type = 3;
#elif defined (_WIN32)
  type = 4;
#else
  type = 0;
#endif
  
#ifdef vxWorks
  bzero( (char *) &l_addr, sizeof( struct sockaddr_in) );
  l_addr.sin_len = sizeof( struct sockaddr_in);
#else
  memset( &l_addr, 0, sizeof( struct sockaddr_in) );
#endif
  l_addr.sin_family = AF_INET;
  l_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  l_addr.sin_port = htons(prpvt->orig_port);

  if( (tcp_sockfd = epicsSocketCreate(AF_INET, SOCK_STREAM, 0))
      == INVALID_SOCKET )
    {
      perror("socket");
      prec->ipsts = aliveIPSTS_INOPERABLE;
      monitor_field(prec, (void *) &prec->ipsts);
      return NULL;
    }

  sflag = 1;
  // not the end of the world if this option doesn't work
  setsockopt(tcp_sockfd, SOL_SOCKET, SO_REUSEADDR, (void *) &sflag,
             sizeof(sflag));


  if( bind(tcp_sockfd, (struct sockaddr *) &l_addr, 
           sizeof(struct sockaddr_in)) )
    {
      perror("TCP bind");
      prec->ipsts = aliveIPSTS_INOPERABLE;
      monitor_field(prec, (void *) &prec->ipsts);
      return NULL;
    }
  
  socklen = sizeof(struct sockaddr_in);
  if( getsockname( tcp_sockfd, (struct sockaddr *) &l_addr, &socklen) )
    {
      perror("TCP getsockname");
      prec->ipsts = aliveIPSTS_INOPERABLE;
      monitor_field(prec, (void *) &prec->ipsts);
      return NULL;
    }    
  // wait to use result until we know listen() works

  if( listen(tcp_sockfd, 5) )
    {
      perror("TCP listen");
      prec->ipsts = aliveIPSTS_INOPERABLE;
      monitor_field(prec, (void *) &prec->ipsts);
      return NULL;
    }

  prec->iport = ntohs(l_addr.sin_port);
  monitor_field(prec, (void *) &prec->iport);
  prec->ipsts = aliveIPSTS_OPERABLE;
  monitor_field(prec, (void *) &prec->ipsts);

  // request remote read
  prpvt->flags |= ((uint16_t) 1);
  
  while(1)
    {
      struct sockaddr r_addr;
      osiSocklen_t r_len = sizeof( r_addr);

      client_sockfd = epicsSocketAccept( tcp_sockfd, &r_addr, &r_len);
      if (client_sockfd == INVALID_SOCKET)
        continue;

      // fault flag can't happen, but just in case
      if( prec->isup || prpvt->fault_flag || !prpvt->ready_flag || 
          ( ((struct sockaddr_in *)&r_addr)->sin_addr.s_addr != prpvt->h_addr.sin_addr.s_addr) )
        {
          epicsSocketDestroy(client_sockfd);
          continue;
        }

      // TCP protocol version
      msg16 = htons(PROTOCOL_VERSION);
      send( client_sockfd, (void *) &msg16, sizeof(uint16_t), 0);

      // IOC type, currently 1 = vxworks, 2 = linux, 3 = darwin
      msg16 = htons(type);
      send( client_sockfd, (void *) &msg16, sizeof(uint16_t), 0);

      number = 0;
      length = 10;  // from version + type + number + length
#if defined (vxWorks)
      memset( &bootparams, 0, sizeof( BOOT_PARAMS) );
      bootStringToStruct( sysBootLine, &bootparams);
      // don't check to see if it returns EOS, as it's zeroed out

      length += 12; // bootparams.unitNum, bootparams.procNum, bootparams.flags
      length += 12; // 8-bit lengths below
      length += ((uint8_t) strlen(bootparams.bootDev) );
      length += ((uint8_t) strlen(bootparams.hostName) );
      length += ((uint8_t) strlen(bootparams.bootFile) );
      length += ((uint8_t) strlen(bootparams.ead) );
      length += ((uint8_t) strlen(bootparams.bad) );
      length += ((uint8_t) strlen(bootparams.had) );
      length += ((uint8_t) strlen(bootparams.gad) );
      length += ((uint8_t) strlen(bootparams.usr) );
      length += ((uint8_t) strlen(bootparams.passwd) );
      length += ((uint8_t) strlen(bootparams.targetName) );
      length += ((uint8_t) strlen(bootparams.startupScript) );
      length += ((uint8_t) strlen(bootparams.other) );
#endif
#if defined (linux) || defined (darwin)
      {
        uid_t user_id;
        gid_t group_id;
        struct passwd *passwd_entry;
        struct group *group_entry;

        user_id = getuid();
        passwd_entry = getpwuid(user_id);
        if( passwd_entry != NULL)
          user = passwd_entry->pw_name;
        else
          user = NULL;

        group_id = getgid();
        group_entry = getgrgid(group_id);
        if( group_entry != NULL)
          group = group_entry->gr_name;
        else
          group = NULL;

        if( gethostname( hostname_buffer, 128) )
          hostname = NULL;
        else
          {
            hostname_buffer[128] = '\0';
            hostname = hostname_buffer;
          }
      }

      //      flag == 2 or 3
      length += 1; // 8-bit string length
      if( user != NULL)
        length += ((uint8_t) strlen(user) );
      length += 1; // 8-bit string length
      if( group != NULL)
        length += ((uint8_t) strlen(group) );
      length += 1; // 8-bit string length
      if( hostname != NULL)
        length += ((uint8_t) strlen(hostname) );
#endif
#if defined (_WIN32)
      {
        uint32_t size;

        length += 2; // two variable lengths

        size = 80;
        if (GetUserNameA(user_buffer, &size))
          {
            user = user_buffer;
            length += ((uint8_t)strlen(user));
          }
        else
          user = NULL;

        size = 20;
        if (GetComputerNameA(machine_buffer, &size))
          {
            machine = machine_buffer;
            length += ((uint8_t)strlen(machine));
          }
        else
          machine = NULL;
      }
#endif
      for( i = 0; i < ENV_CNT; i++)
        {
          if( prpvt->env[i][0] == '\0')
            env_len[i][0] = 0;
          else
            {
              number++;
              length += 3; // 8-bit key & 16-bit value string lengths
              env_len[i][0] = strlen(prpvt->env[i]);
              length += env_len[i][0];
              q = getenv(prpvt->env[i]);
              if( q == NULL)
                env_len[i][1] = 0;
              else
                {
                  env_len[i][1] = strlen(q);
                  // if size is greater that 16-bit max, truncate to zero
                  if( env_len[i][1] > 65535)
                    env_len[i][1] = 0;
                  length += env_len[i][1];
                }
            }
        }

      /* printf("%d\n", length); fflush(stdout); */

      msg32 = htonl( length);
      send( client_sockfd, (void *) &msg32, sizeof(uint32_t), 0);
      msg16 = htons( number);
      send( client_sockfd, (void *) &msg16, sizeof(uint16_t), 0);

      for( i = 0; i < ENV_CNT; i++)
        {
          if( env_len[i][0] == 0)
            continue;

          len8 = env_len[i][0];
          send( client_sockfd, (void *) &len8, sizeof(uint8_t), 0);
          send( client_sockfd, prpvt->env[i], len8, 0);

          q = getenv(prpvt->env[i]);
          len16 = env_len[i][1];
          msg16 = htons( len16);
          send( client_sockfd, (void *) &msg16, sizeof(uint16_t), 0);
          if( len16)
            send( client_sockfd, q, len16, 0);
        }

#ifdef vxWorks
      bootparam_send( client_sockfd, bootparams.bootDev);
      msg32 = htonl(bootparams.unitNum);
      send( client_sockfd, (void *) &msg32, sizeof(uint32_t), 0);
      msg32 = htonl(bootparams.procNum);
      send( client_sockfd, (void *) &msg32, sizeof(uint32_t), 0);
      bootparam_send( client_sockfd, bootparams.hostName);
      bootparam_send( client_sockfd, bootparams.bootFile);
      bootparam_send( client_sockfd, bootparams.ead);
      bootparam_send( client_sockfd, bootparams.bad);
      bootparam_send( client_sockfd, bootparams.had);
      bootparam_send( client_sockfd, bootparams.gad);
      bootparam_send( client_sockfd, bootparams.usr);
      bootparam_send( client_sockfd, bootparams.passwd);
      msg32 = htonl( bootparams.flags);
      send( client_sockfd, (void *) &msg32, sizeof(uint32_t), 0);
      bootparam_send( client_sockfd, bootparams.targetName);
      bootparam_send( client_sockfd, bootparams.startupScript);
      bootparam_send( client_sockfd, bootparams.other);
#endif
#if defined (linux) || defined (darwin)
      if( user == NULL)
        len8 = 0;
      else
        len8 = strlen( user);
      send( client_sockfd, (void *) &len8, sizeof(uint8_t), 0);
      if( user != NULL)
        send( client_sockfd, user, len8, 0);

      if( group == NULL)
        len8 = 0;
      else
        len8 = strlen( group);
      send( client_sockfd, (void *) &len8, sizeof(uint8_t), 0);
      if( group != NULL)
        send( client_sockfd, group, len8, 0);

      if( hostname == NULL)
        len8 = 0;
      else
        len8 = strlen( hostname);
      send( client_sockfd, (void *) &len8, sizeof(uint8_t), 0);
      if( hostname != NULL)
        send( client_sockfd, hostname, len8, 0);
#endif
#if defined (_WIN32)
	  if (user == NULL)
		  len8 = 0;
	  else
		  len8 = strlen(user);
	  send(client_sockfd, (void *)&len8, sizeof(uint8_t), 0);
	  if (user != NULL)
		  send(client_sockfd, user, len8, 0);

	  if (machine == NULL)
		  len8 = 0;
	  else
		  len8 = strlen(machine);
	  send(client_sockfd, (void *)&len8, sizeof(uint8_t), 0);
	  if (machine != NULL)
		  send(client_sockfd, machine, len8, 0);
#endif
      epicsSocketDestroy( client_sockfd);

      // turn off request flag
      prpvt->flags &= ~((uint16_t) 1);
      // if itrigger was set, unset it
      if( prec->itrig)
        {
          prec->itrig = 0; 

          monitor_field(prec, (void *) &prec->itrig);
        }
    }

  return NULL;
}