C4DownloadDlg::C4DownloadDlg(const char *szDLType) : C4GUI::Dialog(C4GUI_ProgressDlgWdt, 100, FormatString(LoadResStr("IDS_CTL_DL_TITLE"), szDLType).getData(), false), szError(NULL) { #ifdef HAVE_WINSOCK fWinSock = AcquireWinSock(); #endif // add all elements - will be reposisioned when text is displayed AddElement(pIcon = new C4GUI::Icon(C4Rect(), C4GUI::Ico_NetWait)); AddElement(pStatusLabel = new C4GUI::Label("", C4Rect(), ACenter, C4GUI_MessageFontClr, &::GraphicsResource.TextFont, false)); pProgressBar = NULL; // created when necessary AddElement(pCancelBtn = new C4GUI::CancelButton(C4Rect())); }
void C4Network2Client::AddLocalAddrs(int16_t iPortTCP, int16_t iPortUDP) { // set up address struct sockaddr_in addr; ZeroMem(&addr, sizeof addr); addr.sin_family = AF_INET; // get local address(es) in_addr **ppAddr = NULL; #ifdef HAVE_WINSOCK bool fGotWinSock = AcquireWinSock(); if (fGotWinSock) #endif { // get local host name char szLocalHostName[128 + 1]; *szLocalHostName = '\0'; ::gethostname(szLocalHostName, 128); // get hostent-struct hostent *ph = ::gethostbyname(szLocalHostName); // check type, get addr list if (ph) if (ph->h_addrtype != AF_INET) ph = NULL; else ppAddr = reinterpret_cast<in_addr **>(ph->h_addr_list); } // add address(es) for (;;) { if (iPortTCP >= 0) { addr.sin_port = htons(iPortTCP); AddAddr(C4Network2Address(addr, P_TCP), false); } if (iPortUDP >= 0) { addr.sin_port = htons(iPortUDP); AddAddr(C4Network2Address(addr, P_UDP), false); } // get next if (!ppAddr || !*ppAddr) break; addr.sin_addr = **ppAddr++; } #ifdef HAVE_WINSOCK if (fGotWinSock) ReleaseWinSock(); #endif }
void C4Network2Client::AddLocalAddrs(int16_t iPortTCP, int16_t iPortUDP) { // set up address struct sockaddr_in addr; ZeroMem(&addr, sizeof addr); addr.sin_family = AF_INET; // get local address(es) in_addr **ppAddr = NULL; #ifdef HAVE_WINSOCK bool fGotWinSock = AcquireWinSock(); if (fGotWinSock) { // get local host name char szLocalHostName[128+1]; *szLocalHostName = '\0'; ::gethostname(szLocalHostName, 128); // get hostent-struct hostent *ph = ::gethostbyname(szLocalHostName); // check type, get addr list if (ph) { if (ph->h_addrtype != AF_INET) ph = NULL; else ppAddr = reinterpret_cast<in_addr **>(ph->h_addr_list); } } #else std::vector<in_addr*> addr_vec; struct ifaddrs* addrs; getifaddrs(&addrs); for(struct ifaddrs* addr = addrs; addr != NULL; addr = addr->ifa_next) { struct sockaddr* ad = addr->ifa_addr; if(ad == NULL) continue; if(ad->sa_family == AF_INET && (~addr->ifa_flags & IFF_LOOPBACK)) // Choose only non-loopback IPv4 devices addr_vec.push_back(&reinterpret_cast<sockaddr_in*>(ad)->sin_addr); } addr_vec.push_back(NULL); ppAddr = &addr_vec[0]; #endif // add address(es) for (;;) { if (iPortTCP >= 0) { addr.sin_port = htons(iPortTCP); AddAddr(C4Network2Address(addr, P_TCP), false); } if (iPortUDP >= 0) { addr.sin_port = htons(iPortUDP); AddAddr(C4Network2Address(addr, P_UDP), false); } // get next if (!ppAddr || !*ppAddr) break; addr.sin_addr = **ppAddr++; } #ifdef HAVE_WINSOCK if (fGotWinSock) ReleaseWinSock(); #else if(addrs) freeifaddrs(addrs); #endif }