/*! * Попытка подключения к удалённой стороне. */ void Task::discovery() { if (m_finished || m_socket) return; const Hosts &remote = m_transaction->remote(); if (!remote.isValid()) return; QString host = remote.address(Internal); quint16 port = remote.port(Internal); discovery(host, port); if (remote.address() != host || remote.port() != port) discovery(remote.address(), remote.port()); }
static void handle_request(int iscsi_fd, const struct iscsi_daemon_request *request, int timeout) { struct connection *conn; log_set_peer_addr(request->idr_conf.isc_target_addr); if (request->idr_conf.isc_target[0] != '\0') { log_set_peer_name(request->idr_conf.isc_target); setproctitle("%s (%s)", request->idr_conf.isc_target_addr, request->idr_conf.isc_target); } else { setproctitle("%s", request->idr_conf.isc_target_addr); } conn = connection_new(request->idr_session_id, &request->idr_conf, iscsi_fd); set_timeout(timeout); capsicate(conn); login(conn); if (conn->conn_conf.isc_discovery != 0) discovery(conn); else handoff(conn); log_debugx("nothing more to do; exiting"); exit (0); }
bool Task::init() { if (!m_file->open(m_transaction->role() ? QIODevice::WriteOnly : QIODevice::ReadOnly)) return false; discovery(); return true; }
int main(int argc, char *argv[]) { int opt; PPPoEConnection *conn; conn = malloc(sizeof(PPPoEConnection)); if (!conn) fatallog("malloc"); memset(conn, 0, sizeof(PPPoEConnection)); while ((opt = getopt(argc, argv, "I:D:VUAS:C:h")) > 0) { switch(opt) { case 'S': conn->serviceName = strDup(optarg); break; case 'C': conn->acName = strDup(optarg); break; case 'U': conn->useHostUniq = 1; break; case 'D': conn->debugFile = fopen(optarg, "w"); if (!conn->debugFile) { fprintf(stderr, "Could not open %s: %s\n", optarg, strerror(errno)); exit(1); } fprintf(conn->debugFile, "pppoe-discovery %s\n", VERSION); break; case 'I': conn->ifName = strDup(optarg); break; case 'A': /* this is the default */ break; case 'V': case 'h': usage(); exit(0); default: usage(); exit(1); } } /* default interface name */ if (!conn->ifName) conn->ifName = strDup("eth0"); conn->discoverySocket = -1; conn->sessionSocket = -1; conn->printACNames = 1; discovery(conn); exit(0); }
/********************************************************************** * %FUNCTION: PPPOEConnectDevice * %ARGUMENTS: * None * %RETURNS: * Non-negative if all goes well; -1 otherwise * %DESCRIPTION: * Connects PPPoE device. ***********************************************************************/ static int PPPOEConnectDevice(void) { struct sockaddr_pppox sp; strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam)); if (existingSession) { unsigned int mac[ETH_ALEN]; int i, ses; if (sscanf(existingSession, "%d:%x:%x:%x:%x:%x:%x", &ses, &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 7) { fatal("Illegal value for rp_pppoe_sess option"); } conn->session = htons(ses); for (i=0; i<ETH_ALEN; i++) { conn->peerEth[i] = (unsigned char) mac[i]; } } else { discovery(conn); if (conn->discoveryState != STATE_SESSION) { error("Unable to complete PPPoE Discovery"); return -1; } } /* Set PPPoE session-number for further consumption */ ppp_session_number = ntohs(conn->session); /* Make the session socket */ conn->sessionSocket = socket(AF_PPPOX, SOCK_STREAM, PX_PROTO_OE); if (conn->sessionSocket < 0) { fatal("Failed to create PPPoE socket: %m"); } sp.sa_family = AF_PPPOX; sp.sa_protocol = PX_PROTO_OE; sp.sa_addr.pppoe.sid = conn->session; memcpy(sp.sa_addr.pppoe.dev, conn->ifName, IFNAMSIZ); memcpy(sp.sa_addr.pppoe.remote, conn->peerEth, ETH_ALEN); /* Set remote_number for ServPoET */ sprintf(remote_number, "%02X:%02X:%02X:%02X:%02X:%02X", (unsigned) conn->peerEth[0], (unsigned) conn->peerEth[1], (unsigned) conn->peerEth[2], (unsigned) conn->peerEth[3], (unsigned) conn->peerEth[4], (unsigned) conn->peerEth[5]); if (connect(conn->sessionSocket, (struct sockaddr *) &sp, sizeof(struct sockaddr_pppox)) < 0) { fatal("Failed to connect PPPoE socket: %d %m", errno); return -1; } return conn->sessionSocket; }
__declspec(dllexport) void ShowDiscoveryDialogEx(IDispatch* pDocument, HWND hParent) { try { ::CoInitialize( 0 ); try { CMWDiscovery discovery(pDocument); if(hParent) { discovery.m_hwnd = hParent; } discovery.SetHelpFile(CGeneral::DefaultHelpFileTitle( AppWorkshare )); discovery.DisplayDiscovery(); } catch(Workshare::Exception& e) { LOG_WS_ERROR_RESULT(e); } catch(_com_error& e) { LOG_WS_ERROR_RESULT(e); } catch(...) { LogUnexpected(); } CoFreeUnusedLibraries(); ::CoUninitialize(); } catch(Workshare::Exception& e) { LOG_WS_ERROR_RESULT(e); } catch(_com_error& e) { LOG_WS_ERROR_RESULT(e); } catch(...) { LogUnexpected(); } }
int main(int argc, char * argv[]) { XPCUdpSocket discovery(9002); discovery.vSetBroadcast(true); discovery.vBindSocket(); char msg[1024]; while(1) { int iRx =discovery.iRecieveMessage(msg,1024); if(iRx) std::cerr<<std::string(msg)<<std::endl; } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->eventTable->setSelectionBehavior( QAbstractItemView::SelectRows ); setWindowTitle("iAlert"); QString uuid = Registry::getValue("uuid").toString(); if (uuid.isEmpty() ) { uuid = QUuid::createUuid().toString(); Registry::setValue("uuid",uuid); } connect(&upnp,SIGNAL(discovery(QUpnpDiscovery)),this,SLOT(upnpDiscovery(QUpnpDiscovery))); connect(&upnp,SIGNAL(discoveryTimeout()),this,SLOT(upnpDiscoveryTimeout())); ui->videoWidget->play( ":/icons/icon.svg" ); refreshCameraList(); }
main() { char stealfood(char x[]); char discovery(char x[]); char trace(char x[]); char run(char x[]); char awake(char x[]); char yad(char x[]); char a[]={"р╩ж╩юойСм╣Ёт╤╚нВё╛"}; char b[]={"ц╗╥╒ожакюойСё╛"}; char c[]={"ц╗в╥юойСё╛"}; char d[]={"юойС╥иеэё╛"}; char e[]={"╬╙пяакп║╧╥ё╛"}; char f[]={"п║╧╥╥м║ё"}; stealfood(a); discovery(b); trace(c); run(d); awake(e); yad(f); getchar(); }
void hd_scan_pppoe(hd_data_t *hd_data2) { hd_t *hd; int cnt, interfaces; PPPoEConnection *conn; hd_data = hd_data2; if(!hd_probe_feature(hd_data, pr_pppoe)) return; hd_data->module = mod_pppoe; PROGRESS(1, 0, "looking for pppoe"); for(interfaces = 0, hd = hd_data->hd; hd; hd = hd->next) { if( hd->base_class.id == bc_network_interface && hd->sub_class.id == sc_nif_ethernet && hd->unix_dev_name ) { interfaces++; } } if(!interfaces) return; conn = new_mem(interfaces * sizeof *conn); for(cnt = 0, hd = hd_data->hd; hd && cnt < interfaces; hd = hd->next) { if( hd->base_class.id == bc_network_interface && hd->sub_class.id == sc_nif_ethernet && hd->unix_dev_name ) { conn[cnt].hd = hd; conn[cnt].fd = -1; conn[cnt].ifname = hd->unix_dev_name; cnt++; } } PROGRESS(2, 0, "discovery"); discovery(interfaces, conn); for(cnt = 0; cnt < interfaces; cnt++) { conn[cnt].hd->is.pppoe = 0; if(conn[cnt].received_pado) { conn[cnt].hd->is.pppoe = 1; ADD2LOG( "pppoe %s: my mac %02x:%02x:%02x:%02x:%02x:%02x, " "peer mac %02x:%02x:%02x:%02x:%02x:%02x\n", conn[cnt].ifname, conn[cnt].my_mac[0], conn[cnt].my_mac[1], conn[cnt].my_mac[2], conn[cnt].my_mac[3], conn[cnt].my_mac[4], conn[cnt].my_mac[5], conn[cnt].peer_mac[0], conn[cnt].peer_mac[1], conn[cnt].peer_mac[2], conn[cnt].peer_mac[3], conn[cnt].peer_mac[4], conn[cnt].peer_mac[5] ); } } }
DumbRelayConsumer::DumbRelayConsumer(const std::string &identifier) { this->identifier(identifier); discovery(); }
void MainWindow::setupCustomPlot2(QCustomPlot *customPlot) { /* int count = simulation->getGlobalRepository()->getRepositoryList().count(); QVector<double> discovery(count), latency(count); int i = 0; Particle * particle; //for (int z=simulation->getExternalFile()->getExternalFileList().count()-1; z>=0; z-- ) for (int z=simulation->getGlobalRepository()->getRepositoryList().count()-1; z>=0; z-- ) { particle = simulation->getGlobalRepository()->getRepositoryList().at(z); discovery[i] = particle->getPerformanceDiscovery(); latency[i] = particle->getPerformanceLatency(); i++; } */ customPlot->legend->setVisible(true); QFont legendFont = font(); // start out with MainWindow's font.. legendFont.setPointSize(9); // and make a bit smaller for legend customPlot->legend->setFont(legendFont); customPlot->legend->setBrush(QBrush(QColor(255,255,255,230))); // by default, the legend is in the inset layout of the main axis rect. So this is how we access it to change legend placement: customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignBottom|Qt::AlignRight); customPlot->clearGraphs(); Particle * particle; int count = genericAlgorithmSolutions.count(); QVector<double> discovery(count), latency(count); for (int i = 0; i < count; i++) { particle = genericAlgorithmSolutions.at(i); discovery[i] = particle->getPerformanceDiscovery(); latency[i] = particle->getPerformanceLatency(); } int countModified = modificatedAlgorithmSolutions.count(); QVector<double> discoveryModified(countModified), latencyModified(countModified); //if (ui->checkBoxComparation->isChecked()) //if (comparation) //{ for (int i = 0; i < countModified; i++) { particle = modificatedAlgorithmSolutions.at(i); discoveryModified[i] = particle->getPerformanceDiscovery(); latencyModified[i] = particle->getPerformanceLatency(); } //} // create graph and assign data to it: customPlot->addGraph(); customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph customPlot->graph(0)->setData(discovery, latency); customPlot->graph(0)->setLineStyle(QCPGraph::lsLine); customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, Qt::red, 4)); customPlot->graph(0)->setName("PSO generico"); customPlot->addGraph(); customPlot->graph(1)->setPen(QPen(Qt::green)); // line color green for second graph customPlot->graph(1)->setData(discoveryModified, latencyModified); customPlot->graph(1)->setLineStyle(QCPGraph::lsLine); customPlot->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, Qt::black, 4)); customPlot->graph(1)->setName("PSO modificado"); // give the axes some labels: customPlot->xAxis->setLabel("Descubierta"); customPlot->yAxis->setLabel("Latencia"); // set axes ranges, so we see all data: customPlot->xAxis->setRange(0, 75); customPlot->yAxis->setRange(0, 300); customPlot->yAxis->grid()->setSubGridVisible(true); ui->customPlot->replot(); // show legend: //customPlot->legend->setVisible(true); }
void MainWindow::setupCustomPlot(QCustomPlot *customPlot) { /* int count = simulation->getGlobalRepository()->getRepositoryList().count(); QVector<double> discovery(count), latency(count); int i = 0; Particle * particle; //for (int z=simulation->getExternalFile()->getExternalFileList().count()-1; z>=0; z-- ) for (int z=simulation->getGlobalRepository()->getRepositoryList().count()-1; z>=0; z-- ) { particle = simulation->getGlobalRepository()->getRepositoryList().at(z); discovery[i] = particle->getPerformanceDiscovery(); latency[i] = particle->getPerformanceLatency(); i++; } */ //customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // period as decimal separator and comma as thousand separator customPlot->legend->setVisible(true); QFont legendFont = font(); // start out with MainWindow's font.. legendFont.setPointSize(9); // and make a bit smaller for legend customPlot->legend->setFont(legendFont); customPlot->legend->setBrush(QBrush(QColor(255,255,255,230))); // by default, the legend is in the inset layout of the main axis rect. So this is how we access it to change legend placement: customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignBottom|Qt::AlignRight); customPlot->clearGraphs(); Particle * particle; int count = genericAlgorithmSolutions.count(); QVector<double> discovery(count), latency(count); for (int i = 0; i < count; i++) { particle = genericAlgorithmSolutions.at(i); discovery[i] = particle->getPerformanceDiscovery(); latency[i] = particle->getPerformanceLatency(); } int countModified = modificatedAlgorithmSolutions.count(); QVector<double> discoveryModified(countModified), latencyModified(countModified); if (ui->checkBoxGrid->isChecked()) { for (int i = 0; i < countModified; i++) { particle = modificatedAlgorithmSolutions.at(i); discoveryModified[i] = particle->getPerformanceDiscovery(); latencyModified[i] = particle->getPerformanceLatency(); } } // create graph and assign data to it: customPlot->addGraph(); if (ui->checkBoxGrid->isChecked()) { customPlot->graph(0)->setName("PSO modificado"); customPlot->graph(0)->setData(discoveryModified, latencyModified); customPlot->graph(0)->setPen(QPen(Qt::green)); // line color blue for first graph customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, Qt::black, 4)); } else { customPlot->graph(0)->setName("PSO generico"); customPlot->graph(0)->setData(discovery, latency); customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, Qt::red, 4)); } customPlot->graph(0)->setLineStyle(QCPGraph::lsLine); if (ui->checkBoxComparation->isChecked()) //if (modified) { customPlot->addGraph(); customPlot->graph(1)->setPen(QPen(Qt::green)); // line color green for second graph customPlot->graph(1)->setData(discoveryModified, latencyModified); customPlot->graph(1)->setLineStyle(QCPGraph::lsLine); customPlot->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, Qt::yellow, 4)); } // give the axes some labels: customPlot->xAxis->setLabel("Descubierta"); customPlot->yAxis->setLabel("Latencia"); // set axes ranges, so we see all data: customPlot->xAxis->setRange(0, 75); customPlot->yAxis->setRange(0, 300); customPlot->yAxis->grid()->setSubGridVisible(true); ui->customPlot->replot(); // show legend: //customPlot->legend->setVisible(true); /* // add two new graphs and set their look: customPlot->addGraph(); customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue customPlot->addGraph(); customPlot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph // generate some points of data (y0 for first, y1 for second graph): QVector<double> x(250), y0(250), y1(250); for (int i=0; i<250; ++i) { x[i] = i; y0[i] = exp(-i/150.0)*cos(i/10.0); // exponentially decaying cosine y1[i] = exp(-i/150.0); // exponential envelope } // configure right and top axis to show ticks but no labels: // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this) customPlot->xAxis2->setVisible(true); customPlot->xAxis2->setTickLabels(false); customPlot->yAxis2->setVisible(true); customPlot->yAxis2->setTickLabels(false); // make left and bottom axes always transfer their ranges to right and top axes: connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange))); connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange))); // pass data points to graphs: customPlot->graph(0)->setData(x, y0); customPlot->graph(1)->setData(x, y1); // let the ranges scale themselves so graph 0 fits perfectly in the visible area: customPlot->graph(0)->rescaleAxes(); // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0): customPlot->graph(1)->rescaleAxes(true); // Note: we could have also just called customPlot->rescaleAxes(); instead // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking: customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); */ }
/********************************************************************** * %FUNCTION: PPPOEConnectDevice * %ARGUMENTS: * None * %RETURNS: * Non-negative if all goes well; -1 otherwise * %DESCRIPTION: * Connects PPPoE device. ***********************************************************************/ static int PPPOEConnectDevice(void) { struct sockaddr_pppox sp; struct ifreq ifr; int s; /* Restore configuration */ lcp_allowoptions[0].mru = conn->mtu; lcp_wantoptions[0].mru = conn->mru; /* Update maximum MRU */ s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { error("Can't get MTU for %s: %m", conn->ifName); return -1; } strncpy(ifr.ifr_name, conn->ifName, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCGIFMTU, &ifr) < 0) { error("Can't get MTU for %s: %m", conn->ifName); close(s); return -1; } close(s); if (lcp_allowoptions[0].mru > ifr.ifr_mtu - TOTAL_OVERHEAD) { lcp_allowoptions[0].mru = ifr.ifr_mtu - TOTAL_OVERHEAD; } if (lcp_wantoptions[0].mru > ifr.ifr_mtu - TOTAL_OVERHEAD) { lcp_wantoptions[0].mru = ifr.ifr_mtu - TOTAL_OVERHEAD; } /* Open session socket before discovery phase, to avoid losing session */ /* packets sent by peer just after PADS packet (noted on some Cisco */ /* server equipment). */ /* Opening this socket just before waitForPADS in the discovery() */ /* function would be more appropriate, but it would mess-up the code */ conn->sessionSocket = socket(AF_PPPOX, SOCK_STREAM, PX_PROTO_OE); if (conn->sessionSocket < 0) { error("Failed to create PPPoE socket: %m"); return -1; } if (acName) { SET_STRING(conn->acName, acName); } if (pppd_pppoe_service) { SET_STRING(conn->serviceName, pppd_pppoe_service); } strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam)); if (existingSession) { unsigned int mac[ETH_ALEN]; int i, ses; if (sscanf(existingSession, "%d:%x:%x:%x:%x:%x:%x", &ses, &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 7) { fatal("Illegal value for rp_pppoe_sess option"); } conn->session = htons(ses); for (i=0; i<ETH_ALEN; i++) { conn->peerEth[i] = (unsigned char) mac[i]; } } else { conn->discoverySocket = openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth, NULL); discovery(conn); if (conn->discoveryState != STATE_SESSION) { error("Unable to complete PPPoE Discovery"); goto ERROR; } } /* Set PPPoE session-number for further consumption */ ppp_session_number = ntohs(conn->session); sp.sa_family = AF_PPPOX; sp.sa_protocol = PX_PROTO_OE; sp.sa_addr.pppoe.sid = conn->session; memcpy(sp.sa_addr.pppoe.dev, conn->ifName, IFNAMSIZ); memcpy(sp.sa_addr.pppoe.remote, conn->peerEth, ETH_ALEN); /* Set remote_number for ServPoET */ sprintf(remote_number, "%02X:%02X:%02X:%02X:%02X:%02X", (unsigned) conn->peerEth[0], (unsigned) conn->peerEth[1], (unsigned) conn->peerEth[2], (unsigned) conn->peerEth[3], (unsigned) conn->peerEth[4], (unsigned) conn->peerEth[5]); warn("Connected to %02X:%02X:%02X:%02X:%02X:%02X via interface %s", (unsigned) conn->peerEth[0], (unsigned) conn->peerEth[1], (unsigned) conn->peerEth[2], (unsigned) conn->peerEth[3], (unsigned) conn->peerEth[4], (unsigned) conn->peerEth[5], conn->ifName); script_setenv("MACREMOTE", remote_number, 0); if (connect(conn->sessionSocket, (struct sockaddr *) &sp, sizeof(struct sockaddr_pppox)) < 0) { error("Failed to connect PPPoE socket: %d %m", errno); goto ERROR; } return conn->sessionSocket; ERROR: close(conn->sessionSocket); conn->sessionSocket = -1; /* Send PADT to reset the session unresponsive at buggy nas */ sendPADT(conn, NULL); if (!existingSession) { close(conn->discoverySocket); conn->discoverySocket = -1; } return -1; }
int main() { signal (SIGINT, sig_handler); wtpconf_preinit(); if (!read_config("./wtp_uci.conf")) { return 1; } // cw_dbg_opt_level = conf_dbg_level; if (!wtpconf_init()){ return 1; }; cw_dbg_opt_display = DBG_DISP_ASC_DMP | DBG_DISP_COLORS; dtls_init(); the_conn = conn_create_noq(-1, NULL); struct conn *conn = the_conn; conn->radios = mbag_i_create(); conn->radios_upd=mbag_i_create(); mbag_i_set_mbag(conn->radios,0,mbag_create()); mbag_i_set_mbag(conn->radios_upd,0,mbag_create()); #define CWMOD "cisco" #define CWBIND "cisco" //#define CWMOD "capwap" //#define CWBIND "capwap80211" struct mod_wtp *mod = modload_wtp(CWMOD); if (!mod) { printf("Can't load mod capwap\n"); exit(0); } mod->init(); mod->register_actions(&capwap_actions,MOD_MODE_CAPWAP); mod = modload_wtp(CWBIND); if (!mod) { printf("Can't load mod capwap80211\n"); exit(0); } int rc = mod->register_actions(&capwap_actions,MOD_MODE_BINDINGS); conn->detected = 1; conn->dtls_verify_peer=0; conn->dtls_mtu = 12000; conn->actions = &capwap_actions; conn->outgoing = mbag_create(); conn->incomming = mbag_create(); conn->local = mbag_create(); conn->config = mbag_create(); the_conn->strict_capwap = 0; cfg_from_json(conn); setup_conf(conn); mbag_t r; // r = mbag_i_get_mbag(conn->radios,0,NULL); r = conn->radios; MAVLITER_DEFINE(it,r); mavliter_foreach(&it){ struct mbag_item *i=mavliter_get(&it); printf("RID = %d\n",i->iid); printf("DATA: %p\n",i->data); mbag_t radio= (mbag_t)i->data; struct mbag_item *mri = mbag_get(radio,CW_RADIOITEM80211_WTP_RADIO_INFORMATION); if (!mri){ printf("Setting to 8 %p %p\n",mri,r); mbag_set_dword(radio,CW_RADIOITEM80211_WTP_RADIO_INFORMATION,1); } else{ printf("MRI %p\n",mri); } } mod_init_config(mod,conn->config); cfg_to_json(); mbag_t mb = mbag_get_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA, NULL); printf("mbag %p\n", mb); cw_acpriolist_t acprios = cw_acpriolist_create(); cw_acpriolist_set(acprios, "Master AC", strlen("Master AC"), 1); cw_acpriolist_set(acprios, "AC8new", strlen("AC8new"), 12); mbag_set_byte(conn->local, CW_ITEM_WTP_MAC_TYPE, CW_WTP_MAC_TYPE_SPLIT); mbag_set_byte(conn->local, CW_ITEM_WTP_FRAME_TUNNEL_MODE, CW_WTP_FRAME_TUNNEL_MODE_E); conn->wbid=1; // cw_set_msg_end_callback(conn->actions,CW_STATE_RUN,CW_MSG_CONFIGURATION_UPDATE_REQUEST,handle_update_req); if (!discovery()) return -1; if (!join()) return -1; if (!configure()) return -1; cw_dbg(DBG_X,"Saveing config 0"); cfg_to_json(); changestate(); run(); //image_update(); return 0; }
status_t pppoe_input(void *cookie, net_device *_device, net_buffer *packet) { if (!packet) return B_ERROR; NetBufferHeaderReader<pppoe_header> bufferheader(packet); if (bufferheader.Status() != B_OK) return B_ERROR; pppoe_header &header = bufferheader.Data(); // remove the following lines when pppoe server is enabled if (header.code == PADI) { TRACE("PADI packet received, ignoreing!\n"); gBufferModule->free(packet); return B_OK; } if (header.code == PADO || header.code == PADR || header.code == PADS || header.code == PADT) { uint8 peerEtherAddr[ETHER_ADDRESS_LENGTH]; struct sockaddr_dl& source = *(struct sockaddr_dl*)packet->source; memcpy(peerEtherAddr, source.sdl_data, ETHER_ADDRESS_LENGTH); const char *str = header.code == PADI ? "PADI" : header.code == PADO ? "PADO" : header.code == PADR ? "PADR" : header.code == PADS ? "PADS" : "PADT" ; dprintf("%s from:%02x:%02x:%02x:%02x:%02x:%02x code:%02x\n", str, peerEtherAddr[0], peerEtherAddr[1], peerEtherAddr[2], peerEtherAddr[3], peerEtherAddr[4], peerEtherAddr[5], header.code); } PPPoEDevice *device; pppoe_query *query; sockaddr_dl& linkAddress = *(sockaddr_dl*)packet->source; int32 specificType = B_NET_FRAME_TYPE(linkAddress.sdl_type, ntohs(linkAddress.sdl_e_type)); // MutexLocker locker(sLock); if (specificType == B_NET_FRAME_TYPE_PPPOE_DISCOVERY && ntohs(header.length) <= PPPoE_QUERY_REPORT_SIZE) { for (int32 index = 0; index < sDevices->CountItems(); index++) { query = sQueries->ItemAt(index); if (query) {// && query->ethernetIfnet == sourceIfnet) { if (header.code == PADO) { DiscoveryPacket discovery(packet, ETHER_HDR_LEN); if (discovery.InitCheck() != B_OK) { ERROR("PPPoE: received corrupted discovery packet!\n"); // gBufferModule->free(packet); return B_ERROR; } pppoe_tag *hostTag = discovery.TagWithType(HOST_UNIQ); if (hostTag && hostTag->length == 4 && *((uint32*)hostTag->data) == query->hostUniq) { SendQueryPacket(query, discovery); // gBufferModule->free(packet); return B_ERROR; } } } } } TRACE("in pppoed processing sDevices->CountItems(): %ld\n", sDevices->CountItems()); for (int32 index = 0; index < sDevices->CountItems(); index++) { device = sDevices->ItemAt(index); TRACE("device->SessionID() %d, header.sessionID: %d\n", device->SessionID(), header.sessionID); if (device) { // && device->EthernetIfnet() == sourceIfnet) { if (specificType == B_NET_FRAME_TYPE_PPPOE && header.sessionID == device->SessionID()) { TRACE("PPPoE: session packet\n"); device->Receive(packet); return B_OK; } if (specificType == B_NET_FRAME_TYPE_PPPOE_DISCOVERY && header.code != PADI && header.code != PADR && !device->IsDown()) { TRACE("PPPoE: discovery packet\n"); DiscoveryPacket discovery(packet, ETHER_HDR_LEN); if (discovery.InitCheck() != B_OK) { ERROR("PPPoE: received corrupted discovery packet!\n"); gBufferModule->free(packet); return B_OK; } pppoe_tag *tag = discovery.TagWithType(HOST_UNIQ); if (header.code == PADT || (tag && tag->length == 4 && *((uint32*)tag->data) == device->HostUniq())) { device->Receive(packet); return B_OK; } } } } ERROR("PPPoE: No device found for packet from: %s\n", "ethernet"); // gBufferModule->free(packet); return B_ERROR; }
int main(int argc, char *argv[]) { int opt; PPPoEConnection *conn; conn = malloc(sizeof(PPPoEConnection)); if (!conn) fatalSys("malloc"); memset(conn, 0, sizeof(PPPoEConnection)); while ((opt = getopt(argc, argv, "I:D:VUW:AS:C:h")) > 0) { switch(opt) { case 'S': conn->serviceName = xstrdup(optarg); break; case 'C': conn->acName = xstrdup(optarg); break; case 'U': if(conn->hostUniq.length) { fprintf(stderr, "-U and -W are mutually exclusive\n"); exit(EXIT_FAILURE); } char pidbuf[5]; snprintf(pidbuf, sizeof(pidbuf), "%04x", getpid()); parseHostUniq(pidbuf, &conn->hostUniq); break; case 'W': if(conn->hostUniq.length) { fprintf(stderr, "-U and -W are mutually exclusive\n"); exit(EXIT_FAILURE); } if (!parseHostUniq(optarg, &conn->hostUniq)) { fprintf(stderr, "Invalid host-uniq argument: %s\n", optarg); exit(EXIT_FAILURE); } break; case 'D': conn->debugFile = fopen(optarg, "w"); if (!conn->debugFile) { fprintf(stderr, "Could not open %s: %s\n", optarg, strerror(errno)); exit(1); } fprintf(conn->debugFile, "pppoe-discovery %s\n", RP_VERSION); break; case 'I': conn->ifName = xstrdup(optarg); break; case 'A': /* this is the default */ break; case 'V': case 'h': usage(); exit(0); default: usage(); exit(1); } } /* default interface name */ if (!conn->ifName) conn->ifName = strdup("eth0"); conn->discoverySocket = -1; conn->sessionSocket = -1; conn->printACNames = 1; discovery(conn); exit(0); }
/********************************************************************** * %FUNCTION: PPPOEConnectDevice * %ARGUMENTS: * None * %RETURNS: * Non-negative if all goes well; -1 otherwise * %DESCRIPTION: * Connects PPPoE device. ***********************************************************************/ static int PPPOEConnectDevice(void) { struct sockaddr_pppox sp; /* Open session socket before discovery phase, to avoid losing session */ /* packets sent by peer just after PADS packet (noted on some Cisco */ /* server equipment). */ /* Opening this socket just before waitForPADS in the discovery() */ /* function would be more appropriate, but it would mess-up the code */ conn->sessionSocket = socket(AF_PPPOX, SOCK_STREAM, PX_PROTO_OE); if (conn->sessionSocket < 0) { error("Failed to create PPPoE socket: %m"); return -1; } strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam)); if (existingSession) { unsigned int mac[ETH_ALEN]; int i, ses; if (sscanf(existingSession, "%d:%x:%x:%x:%x:%x:%x", &ses, &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 7) { fatal("Illegal value for rp_pppoe_sess option"); } conn->session = htons(ses); for (i=0; i<ETH_ALEN; i++) { conn->peerEth[i] = (unsigned char) mac[i]; } } else { conn->discoverySocket = openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth); discovery(conn); if (conn->discoveryState != STATE_SESSION) { error("Unable to complete PPPoE Discovery"); return -1; } } /* Set PPPoE session-number for further consumption */ ppp_session_number = ntohs(conn->session); sp.sa_family = AF_PPPOX; sp.sa_protocol = PX_PROTO_OE; sp.sa_addr.pppoe.sid = conn->session; memcpy(sp.sa_addr.pppoe.dev, conn->ifName, IFNAMSIZ); memcpy(sp.sa_addr.pppoe.remote, conn->peerEth, ETH_ALEN); /* Set remote_number for ServPoET */ sprintf(remote_number, "%02X:%02X:%02X:%02X:%02X:%02X", (unsigned) conn->peerEth[0], (unsigned) conn->peerEth[1], (unsigned) conn->peerEth[2], (unsigned) conn->peerEth[3], (unsigned) conn->peerEth[4], (unsigned) conn->peerEth[5]); warn("Connected to %02X:%02X:%02X:%02X:%02X:%02X via interface %s", (unsigned) conn->peerEth[0], (unsigned) conn->peerEth[1], (unsigned) conn->peerEth[2], (unsigned) conn->peerEth[3], (unsigned) conn->peerEth[4], (unsigned) conn->peerEth[5], conn->ifName); script_setenv("MACREMOTE", remote_number, 0); if (connect(conn->sessionSocket, (struct sockaddr *) &sp, sizeof(struct sockaddr_pppox)) < 0) { error("Failed to connect PPPoE socket: %d %m", errno); return -1; } return conn->sessionSocket; }
int main(int argc, char **argv) { int i = 0; char ip[8][64] = {"192.168.16.213", "192.168.16.213", "192.168.16.213", "192.168.16.213", "192.168.16.213", "192.168.16.213"}; int ipNum = 2; #if 1 #ifndef X86 int resolution = PIC_HD1080; #endif catchSignal(); // memroySet(); if(argc > 1) { for(i = 1; i < argc; i++) { memset(ip[i - 1], 0, sizeof(ip[i - 1])); strcpy(ip[i - 1], argv[i]); } ipNum = argc - 1; } if(ipNum < 2) { ipNum = 2; } databaseLibInit(); //writeLog(LOG_MAJOR_SYSTEM, 0, 0, "system", "127.0.0.1", "system start"); system("rm -rf /config/*.log"); P2pSnUpdate(); //P2P┐пок P2pInitStart(); startWtdThread(); configLibInit(); gpioLibInit(); streamLibInit(); //logLibInit(); startGuiSerVer(); //gpioSetIcPower(1); //PHONE_ThrStart(); //databaseLibInit(); // gpioSetBeep(0);// // gpioSetDiskPower(0); setpriority(PRIO_PROCESS, getpid(), -20); /* */ // myEvLibInit(); myThreadLibInit(); diskLibInit(); threadPoolInit(6 * configGetDisplayNum(), 6 * configGetDisplayNum());/**/ decodeLibInit(0, configGetDisplayNum()); networkLibInit(); appLibInit(); startBoaThread(); //diskLibInit(); playbackLibInit(); recordLibInit(); p2pTHRStart(0); ///StartDdnsThread(); ///TE_platformCreate(); #ifndef X86 hi_audio_init(PT_G711U); #endif alarmLibInit(); sleep(1); rtspServerStart(); usleep(100*1000); discovery(); appLibStart(); sleep(2); startMotion(); startProcessManage(); ////startSmtpThread(); #ifndef HI3531 SnapThreadStart(); #endif setPthreadPriority(PTHREAD_SCHEDULED_PRIORITY_LOW_EST); #endif //appNtpSettime(); while(1) { sleep(60); } stopWtdthread(); decodeLibdestroy(configGetDisplayNum()); networkLibDestroy(); appLibDestroy(); myEvLibDestroy(); diskLibDestroy(); hi_audio_destroy(); alarmLibDestroy(); gpioLibDestroy(); streamLibUninit(); return 0; }
/********************************************************************** * %FUNCTION: PPPOEConnectDevice * %ARGUMENTS: * None * %RETURNS: * Non-negative if all goes well; -1 otherwise * %DESCRIPTION: * Connects PPPoE device. ***********************************************************************/ static int PPPOEConnectDevice(void) { struct sockaddr_pppox sp; static int qosidx=6410; strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam)); if (existingSession) { unsigned int mac[ETH_ALEN]; int i, ses; if (sscanf(existingSession, "%d:%x:%x:%x:%x:%x:%x", &ses, &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 7) { fatal("Illegal value for rp_pppoe_sess option"); } conn->session = htons(ses); for (i=0; i<ETH_ALEN; i++) { conn->peerEth[i] = (unsigned char) mac[i]; } } else { discovery(conn); if (conn->discoveryState != STATE_SESSION) { error("Unable to complete PPPoE Discovery"); return -1; } } /* Set PPPoE session-number for further consumption */ ppp_session_number = ntohs(conn->session); /* Make the session socket */ conn->sessionSocket = socket(AF_PPPOX, SOCK_STREAM, PX_PROTO_OE); if (conn->sessionSocket < 0) { error("Failed to create PPPoE socket: %m"); goto errout; } sp.sa_family = AF_PPPOX; sp.sa_protocol = PX_PROTO_OE; sp.sa_addr.pppoe.sid = conn->session; memcpy(sp.sa_addr.pppoe.dev, conn->ifName, IFNAMSIZ); memcpy(sp.sa_addr.pppoe.remote, conn->peerEth, ETH_ALEN); /* Set remote_number for ServPoET */ sprintf(remote_number, "%02X:%02X:%02X:%02X:%02X:%02X", (unsigned) conn->peerEth[0], (unsigned) conn->peerEth[1], (unsigned) conn->peerEth[2], (unsigned) conn->peerEth[3], (unsigned) conn->peerEth[4], (unsigned) conn->peerEth[5]); warn("Connected to %02X:%02X:%02X:%02X:%02X:%02X via interface %s", (unsigned) conn->peerEth[0], (unsigned) conn->peerEth[1], (unsigned) conn->peerEth[2], (unsigned) conn->peerEth[3], (unsigned) conn->peerEth[4], (unsigned) conn->peerEth[5], conn->ifName); script_setenv("MACREMOTE", remote_number, 0); if (connect(conn->sessionSocket, (struct sockaddr *) &sp, sizeof(struct sockaddr_pppox)) < 0) { fatal("Failed to connect PPPoE socket: %d %m", errno); close(conn->sessionSocket); goto errout; } #ifdef HAVE_AQOS if (bandwidthup!=0 && bandwidthdown!=0) { char uplevel[64]; char downlevel[64]; char mac[64]; sprintf(mac, MACSTR, MAC2STR(conn->myEth)); sprintf(uplevel,"%d",bandwidthup/1000); sprintf(downlevel,"%d",bandwidthdown/1000); fprintf(stderr,"use bandwidth down value to %d\n",bandwidthdown); fprintf(stderr,"use bandwidth up value to %d\n",bandwidthdown); int ret = addrule(mac,uplevel,downlevel); if (!ret) { qosidx+=10; if (qosidx>8190) qosidx=0; add_usermac(mac, qosidx, uplevel,downlevel,"0" ); }else if (ret>1) { system("startstop_f wshaper"); } } #endif return conn->sessionSocket; errout: if (conn->discoverySocket >= 0) { sendPADT(conn, NULL); close(conn->discoverySocket); conn->discoverySocket = -1; } return -1; }