Esempio n. 1
0
                    void GetLocalAddresses(std::set<std::string>& addrs)
                    {
                        IP_ADAPTER_ADDRESSES outAddrs[64];

                        DWORD outAddrsSize = sizeof(outAddrs);

                        DWORD error = ::GetAdaptersAddresses(AF_UNSPEC, 0, NULL, &outAddrs[0], &outAddrsSize);

                        if (ERROR_SUCCESS != error)
                            throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Error getting local addresses list");

                        for (IP_ADAPTER_ADDRESSES* outAddr = &outAddrs[0]; NULL != outAddr; outAddr = outAddr->Next)
                        {
                            if (IF_TYPE_SOFTWARE_LOOPBACK == outAddr->IfType)
                                continue;

                            for (IP_ADAPTER_UNICAST_ADDRESS* addr = outAddr->FirstUnicastAddress;
                                NULL != addr;
                                addr = addr->Next)
                            {
                                void *inAddr = 0;
                                
                                char strBuffer[INET6_ADDRSTRLEN] = { 0 };

                                int saFamily = addr->Address.lpSockaddr->sa_family;

                                switch (saFamily)
                                {
                                    case AF_INET:
                                    {
                                        SOCKADDR_IN* ipv4 = reinterpret_cast<SOCKADDR_IN*>(addr->Address.lpSockaddr);
                                        inAddr = &ipv4->sin_addr;

                                        break;
                                    }

                                    case AF_INET6:
                                    {
                                        SOCKADDR_IN6* ipv6 = reinterpret_cast<SOCKADDR_IN6*>(addr->Address.lpSockaddr);
                                        inAddr = &ipv6->sin6_addr;

                                        break;
                                    }

                                    default:
                                        continue;
                                }

                                inet_ntop(saFamily, inAddr, strBuffer, sizeof(strBuffer));

                                std::string strAddr(strBuffer);

                                if (!strAddr.empty())
                                    addrs.insert(strAddr);
                            }
                        }
                    }
bool GetPrivkeysDialog::setModel(const mapSecretByAddressByColor_t &mapAddrs,
                                 WalletModel *model)
{

    WalletModel::EncryptionStatus status = model->getEncryptionStatus();
    if (status == WalletModel::Locked)
    {
        QMessageBox::warning(this, tr("Wallet Locked"),
            tr("Wallet is locked.\n"
               "Please unlock wallet to display privkeys."),
            QMessageBox::Ok, QMessageBox::Ok);
        return false;
    }

    WalletModel::UnlockContext ctx(model->requestUnlock());

    if(!ctx.isValid())
    {
        // Unlock wallet was cancelled
        return false;
    }

    ui->tableWidget->setColumnWidth(0, 125);
    ui->tableWidget->setColumnWidth(1, 60);
    ui->tableWidget->setColumnWidth(2, 50);

    mapSecretByAddressByColor_t::const_iterator it;
    for (it = mapAddrs.begin(); it != mapAddrs.end(); ++it)
    {
        int nColor = it->first;
        int nDisplayUnit = model->getOptionsModel()->getDisplayUnit(nColor);
        QString strTicker(COLOR_TICKER[nColor]);
        const mapSecretByAddress_t &mapSecrets = it->second;
        mapSecretByAddress_t::const_iterator sit;
        for (sit = mapSecrets.begin(); sit != mapSecrets.end(); ++sit)
        {
            QString strAddr(sit->first.ToString().c_str());
            QString strSecret(sit->second.first.ToString().c_str());
            int64_t nAmt = sit->second.second;
            // QString strAmt = BitcoinUnits::formatWithUnit(nDisplayUnit, nAmt, nColor);
            QString strAmt = BitcoinUnits::format(nDisplayUnit, nAmt, nColor);
            int nRow = ui->tableWidget->rowCount();
            ui->tableWidget->insertRow(nRow);
            ui->tableWidget->setItem(nRow, 0, new QTableWidgetItem(strAmt));
            ui->tableWidget->setItem(nRow, 1, new QTableWidgetItem(strTicker));
            ui->tableWidget->setItem(nRow, 2, new QTableWidgetItem(strSecret));
            ui->tableWidget->setItem(nRow, 3, new QTableWidgetItem(strAddr));
        }
    }
    return true;
}
Esempio n. 3
0
void SockAddr::set(UINT16 port, const char* addr)
{
    port_ = port;
    std::string strAddr(addr);
    std::string::size_type p = 0, q;

    addr_ = 0;
    INT32 i = 0;
    while ((q = strAddr.find('.', p)) != std::string::npos)
    {
        std::string strTemp = strAddr.substr(p, q);
        addr_ = (addr_ << 8) + atoi(strTemp.c_str());
        ++i;
        p = q + 1;
    }

    if (i < 3) 
    {
        addr_ = INADDR_ANY;
    }

    std::string strTemp = strAddr.substr(p);
    addr_ = (addr_ << 8) + atoi(strTemp.c_str());
}
Esempio n. 4
0
/* showStruct():
 *	The workhorse of cast.  This function parses the structfile looking for
 *	the structure type; then it attempts to display the memory block that
 *	begins at memAddr as if it was the structure.  Note that there is no
 *	pre-processing done to verify valid syntax of the structure definition.
 */
int
showStruct(int tfd,long flags,char *structtype,char *structname,char *linkname)
{
	struct mbrinfo *mptr;
	ulong curpos, nextlink;
	int	i, state, snl, retval, tblsize;
	char line[96], addrstr[16], format[64];
	char *cp, *eol, *type, *eotype, *name, *bracket, *eoname, tmp;

	type = (char *)0;
	retval = nextlink = 0;
	curpos = tfsctrl(TFS_TELL,tfd,0);
	tfsseek(tfd,0,TFS_BEGIN);
	castIndent();
	if (structname)
		printf("struct %s %s:\n",structtype,structname);
	else
		printf("struct %s @0x%lx:\n",structtype,memAddr);
	castDepth++;

	state = STRUCT_SEARCH;
	snl = strlen(structtype);

	while(1) {
		if (tfsgetline(tfd,line,sizeof(line)-1) == 0) {
			printf("Structure definition '%s' not found\n",structtype);
			break;
		}
		if ((line[0] == '\r') || (line[0] == '\n'))	/* empty line? */
			continue;

		eol = strpbrk(line,";#\r\n");
		if (eol)
			*eol = 0;

		if (state == STRUCT_SEARCH) {
			if (!strncmp(line,"struct",6)) {
				cp = line+6;
				while(isspace(*cp))
					cp++;
				if (!strncmp(cp,structtype,snl)) {
					cp += snl;
					while(isspace(*cp))
						cp++;
					if (*cp == OPEN_BRACE) 
						state = STRUCT_DISPLAY;
					else {
						retval = -1;
						break;
					}
				}
			}
		}
		else if (state == STRUCT_DISPLAY) {
			type = line;
			while(isspace(*type))
				type++;

			if (*type == CLOSE_BRACE) {
				state = STRUCT_ALLDONE;
				break;
			}

			eotype = type;
			while(!isspace(*eotype))
				eotype++;
			*eotype = 0;
			name = eotype+1;
			while(isspace(*name))
				name++;
			bracket = strchr(name,'[');
			if (bracket)
				tblsize = atoi(bracket+1);						
			else
				tblsize = 1;

			if (*name == '*') {
				castIndent();
				printf("%s%-8s %s: ",strAddr(flags,addrstr),type,name);
				if (!strcmp(type,"char.c"))
					printf("\"%s\"\n",*(char **)memAddr);
				else
					printf("0x%lx\n",*(ulong *)memAddr);
				memAddr += 4;
				continue;
			}
			mptr = mbrinfotbl;			
			while(mptr->type) {
				if (!strcmp(type,mptr->type)) {
					castIndent();
					eoname = name;
					while(!isspace(*eoname))
						eoname++;
					tmp = *eoname;
					*eoname = 0;

					if (bracket) {
						if (!strcmp(type,"char.c")) {
							printf("%s%-8s %s: ",
								strAddr(flags,addrstr),mptr->type,name);
							cp = (char *)memAddr;
							for(i=0;i<tblsize && isprint(*cp);i++)
								printf("%c",*cp++);
							printf("\n");
						}
						else
							printf("%s%-8s %s\n",
								strAddr(flags,addrstr),mptr->type,name);
						memAddr += mptr->size * tblsize;
					}
					else {
						sprintf(format,"%s%-8s %%s: %s\n",
							strAddr(flags,addrstr),mptr->type,mptr->format);
						switch(mptr->size) {
							case 1:
								printf(format,name,*(uchar *)memAddr);
								break;
							case 2:
								printf(format,name,*(ushort *)memAddr);
								break;
							case 4:
								printf(format,name,*(ulong *)memAddr);
								break;
						}
						memAddr += mptr->size;
					}
					*eoname = tmp;
					break;
				}
				mptr++;
			}
			if (!(mptr->type)) {
				int	padsize;
				char *subtype, *subname, *eossn;

				if (!strcmp(type,"struct")) {
					subtype = eotype+1;
					while(isspace(*subtype))
						subtype++;
					subname = subtype;
					while(!isspace(*subname))
						subname++;
					*subname = 0;
					
					subname++;
					while(isspace(*subname))
						subname++;
					eossn = subname;
					while(!isspace(*eossn))
						eossn++;
					*eossn = 0;
					if (*subname == '*') {
						castIndent();
						printf("%s%s %s %s: 0x%08lx\n",strAddr(flags,addrstr),
							type,subtype,subname,*(ulong *)memAddr);
						if (linkname) {
							if (!strcmp(linkname,subname+1))
								nextlink = *(ulong *)memAddr;
						}
						memAddr += 4;
					}
					else {
						for (i=0;i<tblsize;i++) {
							if (bracket)
								sprintf(bracket+1,"%d]",i);
							if (showStruct(tfd,flags,subtype,subname,0) < 0) {
								state = STRUCT_ALLDONE;
								goto done;
							}
						}
					}
				}
				else if (!strncmp(type,"pad[",4)) {
					padsize = atoi(type+4);
					if (flags & STRUCT_SHOWPAD) {
						castIndent();
						printf("%spad[%d]\n",strAddr(flags,addrstr),padsize);
					}
					memAddr += padsize;
				}
				else  {
					retval = -1;
					break;
				}
			}
		}
		else {
			state = STRUCT_ERROR;
			break;
		}
	}
done:

	switch(state) {
		case STRUCT_SEARCH:
			printf("struct %s not found\n",structtype);
			retval = -1;
			break;
		case STRUCT_DISPLAY:
			printf("invalid member type: %s\n",type);
			retval = -1;
			break;
		case STRUCT_ERROR:
			printf("unknown error\n");
			retval = -1;
			break;
	}
	tfsseek(tfd,curpos,TFS_BEGIN);
	if (linkname)
		memAddr = nextlink;
	castDepth--;
	return(retval);
}
void CScanDlg::AddNetDeviceToGrid(vector<_NetDeviceInfo*>& szList)
{
	//EnterCriticalSection(&m_csGrid);
	int nRSize = m_flexGrid.get_Rows();
	int nSize = szList.size();

	m_flexGrid.put_Rows(nSize + nRSize);

	for (UINT i = 0; i < szList.size(); i++)
	{
		_NetDeviceInfo* pNetInfo = szList[i];
		
		//////////////////////////////////////////////////////////////////////////
		//CString strNO;
		//strNO.Format(_T("%d"), i);
		//m_flexGrid.put_TextMatrix(i+1,0,strNO); 

		CString strType = pNetInfo->m_pNet->GetProductName();		
		m_flexGrid.put_TextMatrix(i+nRSize,SCAN_TABLE_TYPE,strType); 

		CString strBuilding = pNetInfo->m_pNet->GetBuildingName();		
		m_flexGrid.put_TextMatrix(i+nRSize,SCAN_TABLE_BUILDING,strBuilding); 

		CString strFloor = pNetInfo->m_pNet->GetFloorName();
		m_flexGrid.put_TextMatrix(i+nRSize,SCAN_TABLE_FLOOR,strFloor); 

		CString strRoom = pNetInfo->m_pNet->GetRoomName();
		m_flexGrid.put_TextMatrix(i+nRSize,SCAN_TABLE_ROOM,strRoom); 

		CString strSubnet = pNetInfo->m_pNet->GetSubnetName();
		m_flexGrid.put_TextMatrix(i+nRSize,SCAN_TABLE_SUBNET,strSubnet); 

		CString strSerailID;
		int nSID = pNetInfo->m_pNet->GetSerialID();
		strSerailID.Format(_T("%d"), nSID);
		m_flexGrid.put_TextMatrix(i+nRSize,SCAN_TABLE_SERIALID,strSerailID); 
		/////
		DWORD dwIP =pNetInfo->m_pNet->GetIPAddr();				
		in_addr ad;
		ad.S_un.S_addr = dwIP;
		CString strAddr(inet_ntoa(ad));
		m_flexGrid.put_TextMatrix(i+nRSize,SCAN_TABLE_ADDRESS,strAddr); 
		/////
		CString strPort;
		int nPort = pNetInfo->m_pNet->GetIPPort();
		strPort.Format(_T("%d"), nPort);
		m_flexGrid.put_TextMatrix(i+nRSize,SCAN_TABLE_COMPORT,strPort); 
		////
		CString strProtocol;		
		if(pNetInfo->m_pNet->GetProtocol() == 3)
		{
			strProtocol.Format(_T("BacnetIP"));
		}
		else
		strProtocol.Format(_T("TCP/IP"));
		m_flexGrid.put_TextMatrix(i+nRSize,SCAN_TABLE_PROTOCOL,strProtocol); 
		////
		// CString strConflict;
	}

	//LeaveCriticalSection(&m_csGrid);
}
	void CommunicationChannelTCP::connectWithDroneAtAddress(const char* szDroneIpAddress, int iPort)
	{
		ccxx::String strAddr(szDroneIpAddress);
		myStream.connect(strAddr, iPort);
		myStream.setTimeout(3000);
	}