//设置WIFI 静态IP参数 int ManualWifiIps(void) { int iRet; iRet = GetIPAddress(_T("IP ADDRESS"), TRUE, glSysCtrl.szLocalIp); if( iRet!=0 ) { return iRet; } iRet = GetIPAddress(_T("SUB-NETWORK MASK"), TRUE, glSysCtrl.szMaskIp); if( iRet!=0 ) { return iRet; } iRet = GetIPAddress(_T("STANDARD GATEWAY"), TRUE, glSysCtrl.szGateIp); if( iRet!=0 ) { return iRet; } iRet = GetIPAddress(_T("DNS"), TRUE, glSysCtrl.szDnsIp); if( iRet!=0 ) { return iRet; } return 0; }
/** * Name: ToggleControls(bool showCheckbox, bool showIPEntry) * Desc: Shows or hides the ethernet controls and toggles * the ethernet checkbox and local ID entry, filling * each appropriately. **/ void DeviceSetupDialog::ToggleControls(bool showCheckbox, bool showIPEntry) { if(showCheckbox) { ethernetLabel.ShowWindow(SW_SHOW); ethernetCheck.ShowWindow(SW_SHOW); } else { ethernetLabel.ShowWindow(SW_HIDE); ethernetCheck.ShowWindow(SW_HIDE); } if(showIPEntry) { ethernetCheck.SetCheck(BST_CHECKED); ipAddressLabel.ShowWindow(SW_SHOW); ipEntry.ShowWindow(SW_SHOW); idEntry.EnableWindow(FALSE); // Fill the IP address entry ipEntry.SetWindowText(GetIPAddress()); } else { ethernetCheck.SetCheck(BST_UNCHECKED); ipAddressLabel.ShowWindow(SW_HIDE); ipEntry.ShowWindow(SW_HIDE); idEntry.EnableWindow(TRUE); // Fill the ID entry idEntry.SetWindowText(ToCString(GetID())); } }
bool Utilities::IsLocalHost(const String &sHostname) { USES_CONVERSION; SOCKADDR_IN addr; addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(T2A(sHostname)); struct hostent *host; if(addr.sin_addr.s_addr == INADDR_NONE) { host = NULL; host = gethostbyname(T2A(sHostname)); if (!host) return false; memcpy(&addr.sin_addr, host->h_addr_list[0], host->h_length); } String sIPAddress = GetIPAddress(addr); IPAddress address; address.TryParse(sIPAddress); if (LocalIPAddresses::Instance()->IsLocalIPAddress(address)) return true; else return false; }
BOOL CWlanInfoFileLogDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon CenterWindow(GetDesktopWindow()); // center to the hpc screen // TODO: Add extra initialization here g_bIsDetecingWLInfo = FALSE; g_bIsAlivePingThread = FALSE; // Get FileVer GetCurrentFileVersion(); // Get Wireless Name GetWirelessDriverName(g_tszWirelessName); // Get Current IP Address CString strCurIPAddr = GetIPAddress(); SetDlgItemText(IDC_EDIT_IPADDR, strCurIPAddr); // Get Default Gateway DWORD dwDHCP = -1; CString strKey = L""; TCHAR tszGateway[128] = _T(""); strKey.Format(L"\\Comm\\%s\\Parms\\TcpIp", g_tszWirelessName); CReg *regGateWay = new CReg(HKEY_LOCAL_MACHINE, strKey); dwDHCP = regGateWay->ValueDW(_T("EnableDHCP")); if (dwDHCP == 0) { regGateWay->ValueSZ(_T("DefaultGateway"), tszGateway, 32); } else if(dwDHCP == 1) { regGateWay->ValueSZ(_T("DhcpDefaultGateway"), tszGateway, 32); } SetDlgItemText(IDC_EDIT_IPADRESS, tszGateway); delete regGateWay; GetDlgItem(IDC_BUTTON_LOG_END)->EnableWindow(FALSE); return TRUE; // return TRUE unless you set the focus to a control }
void CNCFlashDlg::FlashByEthernet() { if (m_pTFTPServer) { delete m_pTFTPServer; m_pTFTPServer = NULL; } if (m_pFileBuffer) { delete[] m_pFileBuffer; m_pFileBuffer = NULL; } CBinFileParser* pBinFile = new CBinFileParser; pBinFile->SetBinFileName(m_strFlashFileName); m_pFileBuffer = new char[c_nBinFileBufLen]; ZeroMemory(m_pFileBuffer, c_nBinFileBufLen); int nDataSize = pBinFile->GetBinFileBuffer(m_pFileBuffer, c_nBinFileBufLen); if(nDataSize > 0) { CString strTips = _T("Firmware bin file verified okay."); UpdateStatusInfo(strTips, FALSE); m_pTFTPServer=new TFTPServer; DWORD dwIP = GetIPAddress(); //m_IPAddr.GetAddress(dwIP); m_pTFTPServer->SetParentDlg(this); m_pTFTPServer->SetClientPort(69); m_pTFTPServer->SetClientIP(dwIP); m_pTFTPServer->SetFileName(m_strFlashFileName); m_pTFTPServer->SetDataSource((BYTE*)m_pFileBuffer, nDataSize); //pServer->SetServerInfoWnd((CWnd*)(&(pDlg->m_ctlServerInfo))); m_pTFTPServer->FlashByEthernet(); // disable flash button ((CISPDlg*)GetParent())->EnableFlash(FALSE); } else { CString strTips1 =_T("Error: The file is not a properly formatted BIN file."); UpdateStatusInfo(strTips1, FALSE); CString strTips2 =_T("Please reselect a right file."); UpdateStatusInfo(strTips2, FALSE); AfxMessageBox(strTips1+strTips2, MB_OK); } delete pBinFile; }
void NczPlayer::Ban(const char * msg, int minutes) { //if (Config::GetInstance()->GetConfigData()->kick_ban) { CIFaceManager::GetInstance()->GetIengine()->ServerCommand(Helpers::format("banid %d %s\n", minutes, GetSteamID()).c_str()); Kick(msg); CIFaceManager::GetInstance()->GetIengine()->ServerCommand("writeid\n"); if(!Helpers::bStrEq("127.0.0.1", GetIPAddress())) { CIFaceManager::GetInstance()->GetIengine()->ServerCommand(Helpers::format("addip 1440 \"%s\"\n", GetIPAddress()).c_str()); CIFaceManager::GetInstance()->GetIengine()->ServerCommand("writeip\n"); } } }
BOOL CClient::SendItem(CClip *pClip) { CSendInfo Info; //Send all text over as UTF-8 CStringA dest; if(CTextConvert::ConvertToUTF8(GetComputerName(), dest)) { strncpy(Info.m_cComputerName, dest, sizeof(Info.m_cComputerName)); } if(CTextConvert::ConvertToUTF8(GetIPAddress(), dest)) { strncpy(Info.m_cIP, dest, sizeof(Info.m_cIP)); } if(CTextConvert::ConvertToUTF8(pClip->m_Desc, dest)) { strncpy(Info.m_cDesc, dest, sizeof(Info.m_cDesc)); } Info.m_cDesc[sizeof(Info.m_cDesc)-1] = 0; Info.m_cComputerName[sizeof(Info.m_cComputerName)-1] = 0; Info.m_cIP[sizeof(Info.m_cIP)-1] = 0; m_SendSocket.SetSocket(m_Connection); if(m_SendSocket.SendCSendData(Info, MyEnums::START) == FALSE) return FALSE; CClipFormat* pCF; INT_PTR count = pClip->m_Formats.GetSize(); //For each data type for(int i=0; i < count; i++) { pCF = &pClip->m_Formats.GetData()[i]; SendClipFormat(pCF); } if(m_SendSocket.SendCSendData(Info, MyEnums::END) == FALSE) return FALSE; theApp.m_lClipsSent++; return TRUE; }
BOOL WRRunDHCPClient(const char *pcInterface, BOOL bWait) { if (g_pidDhcpClient != 0) return TRUE; if (RunProgram(&g_pidDhcpClient, "/bin/dhcpc", pcInterface, NULL) == FALSE) return FALSE; if (bWait) { while (GetIPAddress (pcInterface) <= 0) tt_usleep (10000); } return TRUE; }
void APInfoThread(CWlanInfoFileLogDlg* context) { while(g_bIsDetecingWLInfo) { // Update Current IP Address CString strCurIPAddr = GetIPAddress(); context->SetDlgItemText(IDC_EDIT_IPADDR, strCurIPAddr); // Print WifiInfo PrintWifiInfo(context); Sleep(2000); } }
POP3Connection::ParseResult POP3Connection::_ProtocolPASS(const String &Parameter) { m_Password = Parameter; AccountLogon accountLogon; bool disconnect = false; _account = accountLogon.Logon(GetIPAddress(), m_Username, m_Password, disconnect); if (disconnect) { _SendData("-ERR Invalid user name or password. Too many invalid logon attempts."); return ResultDisconnect; } if (!_account) { if (m_Username.Find(_T("@")) == -1) _SendData("-ERR Invalid user name or password. Please use full email address as user name."); else _SendData("-ERR Invalid user name or password."); return ResultNormalResponse; } // Try to lock mailbox. if (!POP3Sessions::Instance()->Lock(_account->GetID())) { _SendData("-ERR Your mailbox is already locked"); return ResultNormalResponse; } if (!Application::Instance()->GetFolderManager()->GetInboxMessages((int) _account->GetID(), _messages)) { _SendData("+ERR Server error: Failed to fetch messages in Inbox."); return ResultNormalResponse; } _ResetMailbox(); _SendData("+OK Mailbox locked and ready" ); m_CurrentState = TRANSACTION; return ResultNormalResponse; }
void DriverStation::Initialize() { Serial.begin(9600); while (networkStatus != WL_CONNECTED) { Serial.print("Connecting to network..."); Serial.print(networkID); networkStatus = WiFI.begin(networkID, networkPassword); delay(5000); } Serial.println("Connecting..."); Serial.println(GetWiFiID()); Serial.println(GetIPAddress()); Serial.println(GetSignalStrength()); Udp.begin(localport); }
BOOL SetWlanHostSleepCfg(const char *pcInterface, int nGPIO) { int rt; int fd; unsigned long ipaddr; struct iwreq wrq; char buf[32]; int ret = WLAN_STATUS_SUCCESS; memset(buf, 0, sizeof(buf)); if (pcInterface == NULL) { fprintf(stderr, "illegal call function SetWlanChannel!\n"); return FALSE; } ipaddr = GetIPAddress(pcInterface); if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) return FALSE; memset(&wrq, 0, sizeof(wrq)); strcpy(wrq.ifr_name, pcInterface); /* broadcast=1 ; unicast=2 ; multicast=3 */ sprintf(buf, "03 %02x 0xa0 %08x", nGPIO, ipaddr);//set criteria/gpio/gap // sprintf(buf, "02 %02x 0xa0", nGPIO);//set criteria/gpio/gap wrq.u.data.pointer = buf; wrq.u.essid.length = strlen(buf) + 1; rt = ioctl(fd, WLANHOSTSLEEPCFG, &wrq); close(fd); if(rt >= 0) diag_printf("set host sleep config success %s\n", buf); return (rt >= 0 ? TRUE : FALSE); }
int main(void) { int sockfd,no_of_items[3],no_of_items_in_truck[3],i,num,rv; char cnt[50],temp[50],filename[50],buf[MAXDATASIZE],hostName[1024]; struct addrinfo *p,hints,*servinfo; socklen_t addr_len; struct sockaddr_storage their_addr; strcpy(filename,"Store-1.txt"); ReadFileAndGetValues(no_of_items,filename); memset(&cnt, '\0', sizeof cnt); for(i=0;i<3;i++) { sprintf(temp, "%d", no_of_items[i]); strcat(cnt,temp); strcat(cnt,","); } GetHostNames(hostName); CreateSocket("TCPClient",&sockfd,"21891",hostName); printf("Phase 1: store_1 has TCP port number %d and IP address %s.\n",GetPortNumber(sockfd),GetIPAddress(hostName)); printf("Phase 1: The outlet vector \"%s\" for store_1 has been sent to the central warehouse.\n",cnt); if(send(sockfd,&cnt,sizeof(cnt),0)==-1) { perror("recv"); } close(sockfd); printf("End of phase 1 for store_1.\n"); p=CreateSocket("UDPListener",&sockfd,"5891",hostName); printf("Phase 2: Store_1 has UDP port 5891 and IP Address %s.\n",GetIPAddress(hostName)); addr_len = sizeof their_addr; if ((num = recvfrom(sockfd, buf, MAXDATASIZE-1 , 0,(struct sockaddr *)&their_addr, &addr_len)) == -1) { perror("recvfrom"); exit(1); } buf[num] = '\0'; printf("Phase 2: Store_1 received the truck vector \"%s\" from the Central Warehouse.\n", buf); close(sockfd); GetCharToInt(no_of_items_in_truck,buf); CreateNewTruckVector(no_of_items,no_of_items_in_truck); memset(&cnt, '\0', sizeof cnt); for(i=0;i<3;i++) { sprintf(temp, "%d", no_of_items_in_truck[i]); strcat(cnt,temp); strcat(cnt,","); } p=CreateSocket("UDPTalker",&sockfd,"6891",NULL); printf("Phase 2: Store_1 has UDP port 6891 and IP Address %s.\n",GetIPAddress(hostName)); memset(&hints,0,sizeof hints); hints.ai_family=AF_INET; hints.ai_socktype=SOCK_DGRAM; if ((rv = getaddrinfo(hostName, "9891", &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return ; } if ((num = sendto(sockfd, cnt, strlen(cnt), 0, servinfo->ai_addr, servinfo->ai_addrlen)) == -1) { perror("talker: sendto"); exit(1); } printf("Phase 2: The updated truck vector \"%s\" has been sent to Store_2.\n",cnt); printf("Phase 2: Store_1 updated outlet vector is : %d,%d,%d,\n",no_of_items[0],no_of_items[1],no_of_items[2]); close(sockfd); p=CreateSocket("UDPListener",&sockfd,"7891",hostName); printf("Phase 2: Store_1 has UDP port 7891 and IP Address %s.\n",GetIPAddress(hostName)); addr_len = sizeof their_addr; if ((num = recvfrom(sockfd, buf, MAXDATASIZE-1 , 0,(struct sockaddr *)&their_addr, &addr_len)) == -1) { perror("recvfrom"); exit(1); } buf[num] = '\0'; printf("Phase 2: The truck vector \"%s\" has been received from Store_4.\n", buf); close(sockfd); GetCharToInt(no_of_items_in_truck,buf); CreateNewTruckVector(no_of_items,no_of_items_in_truck); memset(&cnt, '\0', sizeof cnt); for(i=0;i<3;i++) { sprintf(temp, "%d", no_of_items_in_truck[i]); strcat(cnt,temp); strcat(cnt,","); } p=CreateSocket("UDPTalker",&sockfd,"8891",NULL); printf("Phase 2: Store_1 has UDP port 8891 and IP Address %s.\n",GetIPAddress(hostName)); memset(&hints,0,sizeof hints); hints.ai_family=AF_INET; hints.ai_socktype=SOCK_DGRAM; if ((rv = getaddrinfo(hostName, "11891", &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return ; } if ((num = sendto(sockfd, cnt, strlen(cnt), 0, servinfo->ai_addr, servinfo->ai_addrlen)) == -1) { perror("talker: sendto"); exit(1); } printf("Phase 2: The updated truck vector \"%s\" has been sent to Store_2.\n",cnt); printf("Phase 2: Store_1 updated outlet vector is : %d,%d,%d,\n",no_of_items[0],no_of_items[1],no_of_items[2]); close(sockfd); printf("End of phase 2 for Store_1.\n"); return 0; }
void QAutoGenDialog::accept() { unsigned int i, iVehicles = m_txtVehicles->value(), iCar; QString strParam, strValue, strName, strType = m_comboVehicleType->currentText(); std::map<QString, QString> mapParams; std::map<QString, std::map<QString, AutoGenParameter> >::iterator iterParams = m_mapModels.find(strType), iterAssocParams; std::map<QString, AutoGenParameter>::iterator iterParam; QStringList listDepends; QStringList::iterator iterDepend; in_addr_t ipAddress, ipTemp; std::map<QString, QString> mapAssocModels; std::map<QString, QString>::iterator iterAssocModel; std::map<QString, QString> mapAssocModelTypes; std::map<QString, QString>::iterator iterAssocModelType; std::vector<std::pair<QString, QString> > vecAssocModelTypes; std::map<QString, std::map<QString, AutoGenParameter> > mapAssocModelParams; std::map<QString, std::map<QString, ModelParameter> >::iterator iterModelType = m_pMapParams->find(strType), iterModelParams; std::map<QString, ModelParameter>::iterator iterModelParam; std::set<QString> setDepends; std::set<QString>::iterator iterSetDepend; QAutoGenModelDialog * pDialog; int nResult; bool bAddressSet = false; std::map<QString, Rect>::iterator iterAddressParams; // get record list for different parameters for (iterAddressParams = m_mapMapSelections.begin(); iterAddressParams != m_mapMapSelections.end(); ++iterAddressParams) { switch (m_comboRegionType->currentItem()) { case 0: g_pMapDB->GetRecordsInRegion(m_mapRandomRecords[iterAddressParams->first], iterAddressParams->second); break; default: break; } } // make list of associated models for (iterParam = iterParams->second.begin(); iterParam != iterParams->second.end(); ++iterParam) { strParam = iterParam->first, strValue = iterParam->second.strValue; iterModelParam = iterModelType->second.find(strParam); if (iterParam->second.eType == AutoGenParamTypeNewModel) { vecAssocModelTypes.push_back(std::pair<QString, QString>(strParam, strValue)); mapAssocModelTypes.insert(vecAssocModelTypes.back()); } } for (i = 0; i < vecAssocModelTypes.size(); i++) { if (vecAssocModelTypes[i].second.compare(NULLMODEL_NAME) != 0) { pDialog = new QAutoGenModelDialog(vecAssocModelTypes[i].first, vecAssocModelTypes[i].second, this); m_mapModelIndexes[vecAssocModelTypes[i].second] = 0; iterModelParams = m_pMapParams->find(vecAssocModelTypes[i].second); iterAssocParams = m_mapModels.find(vecAssocModelTypes[i].second); iterAssocParams = mapAssocModelParams.insert(std::pair<QString, std::map<QString, AutoGenParameter> >(vecAssocModelTypes[i].first, iterAssocParams->second)).first; pDialog->m_pVecModelTypes = m_pVecModelTypes; pDialog->m_pAssocModelTypeMap = &mapAssocModelTypes; pDialog->m_pAssocModelTypes = &vecAssocModelTypes; pDialog->m_pModelParams = &iterModelParams->second; // generate auto-generator parameters pDialog->m_pParams = &iterAssocParams->second; pDialog->InitializeModelParams(); nResult = pDialog->exec(); delete pDialog; if (nResult == QDialog::Rejected) return; } } iCar = 0; qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); ipAddress = GetIPAddress(); for (i = 0; i < iVehicles; i++) { // create this vehicle while (m_pModelNames->find(strName = QString("%1%2").arg(strType).arg(iCar)) != m_pModelNames->end()) iCar++; for (iterParam = iterParams->second.begin(); iterParam != iterParams->second.end(); ++iterParam) { strParam = iterParam->first, strValue = iterParam->second.strValue; iterModelParam = iterModelType->second.find(strParam); switch (iterParam->second.eType & (~AutoGenParamTypeNoRandom)) { case AutoGenParamTypeNewModel: iterAssocModelType = mapAssocModelTypes.find(strParam); setDepends.insert(mapParams[iterAssocModelType->first] = GetAssocModel(iterAssocModelType->first, iterAssocModelType->second, mapAssocModels, mapAssocModelTypes, mapAssocModelParams, i)); break; case AutoGenParamTypeDepends: listDepends = QStringList::split(';', strValue); for (iterDepend = listDepends.begin(); iterDepend != listDepends.end(); ++iterDepend) setDepends.insert(*iterDepend); break; case AutoGenParamTypeIP: if (!bAddressSet && StringToIPAddress(strValue, ipTemp)) ipAddress = ipTemp; break; case AutoGenParamTypeRandom: mapParams[strParam] = GetRandomParameter(strParam, strValue, iterModelParam->second); break; case AutoGenParamTypeFile: mapParams[strParam] = GetFileParameter(strParam, strValue, i); break; default: mapParams[strParam] = strValue; break; } } while (m_pVehicleIPs->find(ipAddress) != m_pVehicleIPs->end()) ipAddress++; bAddressSet = true; mapParams[m_strIPAddressParam] = IPAddressToString(ipAddress); setDepends.erase("NULL"); mapParams[PARAM_DEPENDS] = QString::null; for (iterSetDepend = setDepends.begin(); iterSetDepend != setDepends.end(); ++iterSetDepend) { if (mapParams[PARAM_DEPENDS].isEmpty()) mapParams[PARAM_DEPENDS] = *iterSetDepend; else mapParams[PARAM_DEPENDS] += (';' + *iterSetDepend); } setDepends.clear(); m_pVehicleIPs->insert(ipAddress); m_pModels->insert(std::pair<QString, std::map<QString, QString> >(strName, mapParams)); m_pVehicleList->push_back(std::pair<QString, QString>(strName, strType)); m_pModelNames->insert(strName); mapAssocModels.clear(); iCar++; ipAddress++; } m_mapFileData.clear(); qApp->restoreOverrideCursor(); QDialog::accept(); }
AnsiString ProtocolParser::GetIPAddressString() const { return GetIPAddress().ToString(); }
int main(void) { int sockfd, new_fd,num,cameras[4],laptops[4],printers[4],i,rv,pos=0,j,k=0; struct addrinfo *p,hints,*servinfo; socklen_t addrLen,sin_size; struct sockaddr_storage their_addr; char truck[50],buf[MAXDATASIZE],hostName[1024],no_of_items[4][50],val[50]; GetHostNames(hostName); //strcpy(hostName,"localhost"); CreateSocket("TCPServer",&sockfd,"21891",NULL); if (listen(sockfd, BACKLOG) == -1) { perror("listen"); exit(1); } printf("Phase 1: The central warehouse has TCP Port #21891 and IP Address %s. \n",GetIPAddress(hostName)); for(i=0;i<4;i++) { sin_size = sizeof their_addr; new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size); if (new_fd == -1) { perror("accept"); continue; } if ((num=recv(new_fd, no_of_items[i], MAXDATASIZE-1, 0)) == -1 ) { perror("recv"); exit(1); } no_of_items[i][num]='\0'; printf("Phase 1: The central warehouse received information from store #%d : %s\n",i+1,no_of_items[i]); fflush(stdout); for(j=0;j<strlen(no_of_items[i]);j++) { if(no_of_items[i][j]==',') { if(k==0) { cameras[i]=atoi(val); k++; } else if(k==1) { laptops[i]=atoi(val); k++; } else { printers[i]=atoi(val); k=0; } pos=0; memset(&val,'\0',50); } else val[pos++] =no_of_items[i][j]; } close(new_fd); } close(sockfd); printf("End of Phase 1 for the central warehouse.\n"); memset(&truck,'\0',50); CalculateRequiredItems(cameras,laptops,printers,truck); p=CreateSocket("UDPTalker",&sockfd,"31891",NULL); GetHostNames(hostName); printf("Phase 2: The central warehouse has UDP port number : 31891 and IP Address : %s\n",GetIPAddress(hostName)); memset(&hints,0,sizeof hints); hints.ai_family=AF_INET; hints.ai_socktype=SOCK_DGRAM; if ((rv = getaddrinfo(hostName, "5891", &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return ; } printf("Phase 2: Sending the truck vector to outlet store store_1. The truck vector value is : %s\n",truck); if ((num = sendto(sockfd, truck, strlen(truck), 0, servinfo->ai_addr, servinfo->ai_addrlen)) == -1) { perror("talker: sendto"); exit(1); } close(sockfd); printf("Phase 2: The central warehouse has UDP port number : 32891 and IP Address : %s\n",GetIPAddress(hostName)); p=CreateSocket("UDPListener",&sockfd,"32891",hostName); addrLen = sizeof their_addr; if ((num = recvfrom(sockfd, buf, MAXDATASIZE-1 , 0,(struct sockaddr *)&their_addr, &addrLen)) == -1) { perror("recvfrom"); exit(1); } buf[num] = '\0'; printf("Phase 2: The final truck-vector is received from the outlet store store_4. The truck-vector value is : %s \n",buf); close(sockfd); printf("End of phase 2 for the central warehouse.\n"); return 0; }
void SMTPClientConnection::InternalParseData(const AnsiString &Request) { LOG_DEBUG("SMTPClientConnection::_ParseASCII()"); String sData = "RECEIVED: " + Request; LOG_SMTP_CLIENT(GetSessionID(), GetIPAddress().ToString(), sData); // Below 3 lines is fix of the problem that occurs when the remote server answers // with 2 line in his welcome message. String sMinus = "-"; if ((Request.GetLength() > 3) && (Request.GetAt(3) == sMinus.GetAt(0))) { LOG_DEBUG("SMTPClientConnection::~_ParseASCII() - 1"); return; } int lFirstSpace = Request.Find(" "); AnsiString sFirstWordTemp; if (lFirstSpace < 0) sFirstWordTemp = Request; else sFirstWordTemp = Request.Mid(0, lFirstSpace); sFirstWordTemp.MakeUpper(); int iCode = atoi(sFirstWordTemp); // We should not update all recipient's if we've just sent a // RCPT TO. We should only update the specific one we've just // sent to. // // Also, we should not update state if we've just sent QUIT to // the server. At the time we send QUIT, the message has already // been either accepted for delivery and rejected. Any error after // this isn't relvat. if (m_CurrentState != RCPTTOSENT && m_CurrentState != QUITSENT) { if (IsPermanentNegative(iCode)) { _UpdateAllRecipientsWithError(iCode, Request, false); _SendQUIT(); return; } else if (IsTransientNegative(iCode)) { _UpdateAllRecipientsWithError(iCode, Request, false); _SendQUIT(); return; } } switch (m_CurrentState) { case SENDUSERNAME: _ProtocolSendUsername(); break; case SENDPASSWORD: _ProtocolSendPassword(); break; case PASSWORDCHECK: if (!_ProtocolPassswordCheck(iCode, Request)) { // Authentication failed. We have just sent // a quit command. return; } break; } if (m_CurrentState == HELO) { if (iCode == 220) { String sComputerName = Utilities::ComputerName(); if (m_bUseSMTPAuth) { _SendData("EHLO " + sComputerName); _SetState(EHLOSENT); } else { _SendData("HELO " + sComputerName); _SetState(HELOSENT); } LOG_DEBUG("SMTPClientConnection::~_ParseASCII() - 2"); return ; } else { LOG_DEBUG("SMTPClientConnection::~_ParseASCII() - 3"); _UpdateAllRecipientsWithError(iCode, Request, false); _SendQUIT(); return; } } if (m_CurrentState == EHLOSENT) { // Ask the server to initiate login process. _SendData("AUTH LOGIN"); _SetState(SENDUSERNAME); return ; } if (m_CurrentState == HELOSENT) { if (IsPositiveCompletion(iCode)) { // --- Server accepted HELO. Go to HEADER/MAILFROM state. _SetState(MAILFROM); } else { _UpdateAllRecipientsWithError(iCode, Request, false); } } if (m_CurrentState == MAILFROM) { String sFrom = m_pDeliveryMessage->GetFromAddress(); String sData = "MAIL FROM:<" + sFrom + ">"; _SendData(sData); m_CurrentState = MAILFROMSENT; LOG_DEBUG("SMTPClientConnection::~_ParseASCII() - 4"); return; } if (m_CurrentState == MAILFROMSENT) { if (IsPositiveCompletion(iCode)) { // --- Server accepted mail from. Go to header/rcpt to state. m_CurrentState = RCPTTO; } else { LOG_DEBUG("SMTPClientConnection::~_ParseASCII() - 5"); _UpdateAllRecipientsWithError(iCode, Request, false); } } if (m_CurrentState == RCPTTO) { LOG_DEBUG("SMTPClientConnection::~_ParseASCII() - 6"); shared_ptr<MessageRecipient> pRecipient = _GetNextRecipient(); if (!pRecipient) { _SendQUIT(); return; } String sRecipient = pRecipient->GetAddress(); String sData = "RCPT TO:<" + sRecipient + ">"; _SendData(sData); m_CurrentState = RCPTTOSENT; return; } if (m_CurrentState == RCPTTOSENT) { if (m_iCurRecipient < m_vecRecipients.size()) { if (IsPositiveCompletion(iCode)) { _actualRecipients.insert(m_vecRecipients[m_iCurRecipient]); } else { _UpdateRecipientWithError(iCode, Request, m_vecRecipients[m_iCurRecipient], false); } } shared_ptr<MessageRecipient> pRecipient = _GetNextRecipient(); if (pRecipient) { // Send next recipient. _SendData("RCPT TO:<" + pRecipient->GetAddress() + ">"); m_CurrentState = RCPTTOSENT; } else { if (_actualRecipients.size() == 0) { _SendQUIT(); return; } m_CurrentState = DATAQUESTION; } } if (m_CurrentState == DATAQUESTION) { _SendData("DATA"); m_CurrentState = DATA; LOG_DEBUG("SMTPClientConnection::~_ParseASCII() - 7"); return; } if (m_CurrentState == DATA) { if (IsPositiveIntermediate(iCode)) { // Send the data! const String fileName = PersistentMessage::GetFileName(m_pDeliveryMessage); LOG_DEBUG("SMTPClientConnection::~_BEFORE SendFile"); _StartSendFile(fileName); LOG_DEBUG("SMTPClientConnection::~_AFTER SendFile"); return; } } if (m_CurrentState == DATASENT) { LOG_DEBUG("SMTPClientConnection::~_BEFORE SendQUIT"); _SendQUIT(); LOG_DEBUG("SMTPClientConnection::~_AFTER SendQUIT"); if (IsPositiveCompletion(iCode)) { _UpdateSuccessfulRecipients(); LOG_DEBUG("SMTPClientConnection::~_ParseASCII() - 9"); return; } else { _UpdateAllRecipientsWithError(iCode, Request, false); LOG_DEBUG("SMTPClientConnection::~_ParseASCII() - 10"); } return; } if (m_CurrentState == QUITSENT) { // We just received a reply on our QUIT. Time to disconnect. m_bPendingDisconnect = true; PostDisconnect(); } }
// target_network_adaptorで指定しているアダプター名にnetwork_addressを追加する。 long FirstFindAdaptorAddStaticIPAddress(const std::wstring &target_network_adaptor, const std::vector<NetworkAddress> &network_addres) { IWbemLocator *locator = nullptr; HRESULT hr = ::CoCreateInstance(CLSID_WbemLocator, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&locator)); /* CIMV2名前空間 */ IWbemServices *targetNamespace = nullptr; if(SUCCEEDED(hr)) { BSTR namespacePath = ::SysAllocString(L"root\\cimv2"); hr = locator->ConnectServer(namespacePath, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &targetNamespace); ::SysFreeString(namespacePath); } /* セキュリティ設定 */ if(SUCCEEDED(hr)) { hr = ::CoSetProxyBlanket(targetNamespace, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, nullptr, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_NONE); } /* クラスオブジェクト */ IWbemClassObject *wmi_class = nullptr; BSTR wmi_class_name = ::SysAllocString(L"Win32_NetworkAdapterConfiguration"); if(SUCCEEDED(hr)) { hr = targetNamespace->GetObjectW(wmi_class_name, 0, nullptr, &wmi_class, nullptr); } /* メソッド */ IWbemClassObject *wmi_method = nullptr; BSTR method_name = ::SysAllocString(L"EnableStatic"); if(SUCCEEDED(hr)) { hr = wmi_class->GetMethod(method_name, 0, &wmi_method, nullptr); } /* ネットワークアドレスのパラメーター */ IWbemClassObject *network_address_param = nullptr; if(SUCCEEDED(hr)) { hr = wmi_method->SpawnInstance(0, &network_address_param); } /* パラメーターにIPアドレス設定 */ if(SUCCEEDED(hr)) { VARIANT address_var; VARIANT subnet_mask_var; { SAFEARRAYBOUND sab[1] = {0}; sab[0].cElements = network_addres.size(); // IPアドレス address_var.vt = VT_ARRAY | VT_BSTR; address_var.parray = ::SafeArrayCreate(VT_BSTR, 1, sab); // サブネットマスク subnet_mask_var.vt = VT_ARRAY | VT_BSTR; subnet_mask_var.parray = ::SafeArrayCreate(VT_BSTR, 1, sab); // 配列に設定 LONG index = 0; for(auto iter = std::begin(network_addres); iter != std::end(network_addres); ++iter) { if(SUCCEEDED(hr)) { BSTR ip_address = ::SysAllocString(iter->GetIPAddress().c_str()); hr = ::SafeArrayPutElement(address_var.parray, &index, ip_address); ::SysFreeString(ip_address); } if(SUCCEEDED(hr)) { BSTR subnet_mask = ::SysAllocString(iter->GetSubnetMask().c_str()); hr = ::SafeArrayPutElement(subnet_mask_var.parray, &index, subnet_mask); ::SysFreeString(subnet_mask); } ++index; } } if(SUCCEEDED(hr)) { BSTR param_ip_address = ::SysAllocString(L"IPAddress"); hr = network_address_param->Put(param_ip_address, 0, &address_var, 0); ::SysFreeString(param_ip_address); } if(SUCCEEDED(hr)) { BSTR param_subnet_mask = ::SysAllocString(L"SubnetMask"); network_address_param->Put(param_subnet_mask, 0, &subnet_mask_var, 0); ::SysFreeString(param_subnet_mask); } ::VariantClear(&subnet_mask_var); ::VariantClear(&address_var); } /* ネットワークアダプターを探す */ IEnumWbemClassObject *adapter_enumerator = nullptr; if(SUCCEEDED(hr)) { hr = targetNamespace->CreateInstanceEnum(wmi_class_name, WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr, &adapter_enumerator); } /* ネットワークアダプター インスタンスへのパスを取得 */ BSTR network_adaptr_instance; if(SUCCEEDED(hr)) { // 対象のネットワークアダプターのインスタンス取得 IWbemClassObject *instance = nullptr; do { ULONG ret = 0u; hr = adapter_enumerator->Next(WBEM_INFINITE, (ULONG)1, &instance, &ret); if(SUCCEEDED(hr) && (ret != 0)) { BSTR desc_property = ::SysAllocString(L"Description"); VARIANT desc; hr = instance->Get(desc_property, 0, &desc, nullptr, nullptr); ::SysFreeString(desc_property); if(SUCCEEDED(hr)) { const std::wstring &adaptor_name = desc.bstrVal; ::VariantClear(&desc); auto b_find = adaptor_name.find(target_network_adaptor); if(b_find != std::wstring::npos) { break; // do_whileをぬける } } } else { break; // do_whileをぬける } } while(hr != WBEM_S_FALSE); // インスタンスへのパス取得 if(SUCCEEDED(hr)) { BSTR path_property = ::SysAllocString(L"__PATH"); VARIANT path_var; hr = instance->Get(path_property, 0, &path_var, nullptr, nullptr); ::SysFreeString(path_property); if(SUCCEEDED(hr)) { network_adaptr_instance = path_var.bstrVal; } ::VariantClear(&path_var); } SAFE_RELEASE(instance); } /* IPアドレスの設定 */ IWbemClassObject *result_class = nullptr; if(SUCCEEDED(hr)) { hr = targetNamespace->ExecMethod(network_adaptr_instance, method_name, 0, nullptr, network_address_param, &result_class, nullptr); } long result = -1; if(FAILED(hr)) { result = 1; } else { BSTR return_value = SysAllocString(L"ReturnValue"); VARIANT res_var; hr = result_class->Get(return_value, 0, &res_var, 0, 0); result = V_I4(&res_var); ::SysFreeString(return_value); ::VariantClear(&res_var); } SAFE_RELEASE(result_class); ::SysFreeString(network_adaptr_instance); SAFE_RELEASE(adapter_enumerator); SAFE_RELEASE(network_address_param); SAFE_RELEASE(wmi_method); ::SysFreeString(method_name); SAFE_RELEASE(wmi_class); ::SysFreeString(wmi_class_name); SAFE_RELEASE(targetNamespace); SAFE_RELEASE(locator); return result; }