| 2002 | } |
| 2003 | |
| 2004 | DWORD WINAPI BroadcastThread(void *param) |
| 2005 | { |
| 2006 | using namespace Broadcast; |
| 2007 | |
| 2008 | int ID = (*(int*)param) - 1; |
| 2009 | |
| 2010 | sockaddr_in saServer; |
| 2011 | |
| 2012 | if(ID >= 8) |
| 2013 | { |
| 2014 | unsigned short port = 7590; |
| 2015 | char *portStr = NULL; |
| 2016 | if(NULL != (portStr = strchr(Broadcast::nextAddress[ID - 8], ':'))) |
| 2017 | { |
| 2018 | *portStr = 0; |
| 2019 | port = (unsigned short)atoi(portStr + 1); |
| 2020 | } |
| 2021 | |
| 2022 | hostent *localHost = gethostbyname(Broadcast::nextAddress[ID - 8]); |
| 2023 | char *localIP = inet_ntoa(*(struct in_addr *)*localHost->h_addr_list); |
| 2024 | |
| 2025 | saServer.sin_family = AF_INET; |
| 2026 | saServer.sin_addr.s_addr = inet_addr(localIP); |
| 2027 | saServer.sin_port = htons((u_short)(port)); |
| 2028 | safeprintf(itemResult[ID].address, 512, "%s:%d", Broadcast::nextAddress[ID-8], port); |
| 2029 | |
| 2030 | if(portStr) |
| 2031 | *portStr = ':'; |
| 2032 | }else{ |
| 2033 | saServer.sin_family = AF_INET; |
| 2034 | saServer.sin_addr.s_addr = inet_addr(RemoteData::localIP); |
| 2035 | saServer.sin_port = htons((u_short)(7590 + ID)); |
| 2036 | safeprintf(itemResult[ID].address, 512, "localhost:%d", 7590 + ID); |
| 2037 | } |
| 2038 | |
| 2039 | SOCKET sck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 2040 | if(connect(sck, (SOCKADDR*)&saServer, sizeof(saServer))) |
| 2041 | { |
| 2042 | closesocket(sck); |
| 2043 | |
| 2044 | safeprintf(itemResult[ID].message, 1024, "%s", GetLastErrorDesc()); |
| 2045 | safeprintf(itemResult[ID].pid, 16, "-"); |
| 2046 | EnterCriticalSection(&pipeSection); |
| 2047 | broadcastWorkers[ID] = 0; |
| 2048 | itemAvailable[ID] = false; |
| 2049 | LeaveCriticalSection(&pipeSection); |
| 2050 | }else{ |
| 2051 | PipeData data; |
| 2052 | data.cmd = DEBUG_REPORT_INFO; |
| 2053 | data.question = true; |
| 2054 | |
| 2055 | int result = RemoteData::SocketSend(sck, (char*)&data, sizeof(data), 2); |
| 2056 | if(!result || result == -1) |
| 2057 | { |
| 2058 | safeprintf(itemResult[ID].message, 1024, "Failed to request information to socket '%s'\r\n", GetLastErrorDesc()); |
| 2059 | safeprintf(itemResult[ID].pid, 16, "-"); |
| 2060 | EnterCriticalSection(&pipeSection); |
| 2061 | broadcastWorkers[ID] = 0; |
nothing calls this directly
no test coverage detected