/********************************************************************** *%FUNCTION: addInterface *%ARGUMENTS: * ifname -- interface name * clientOK -- true if this interface should relay PADI, PADR packets. * acOK -- true if this interface should relay PADO, PADS packets. *%RETURNS: * Nothing *%DESCRIPTION: * Opens an interface; sets up discovery and session sockets. ***********************************************************************/ void addInterface(char const *ifname, int clientOK, int acOK) { PPPoEInterface *i; int j; for (j=0; j<NumInterfaces; j++) { if (!strncmp(Interfaces[j].name, ifname, IFNAMSIZ)) { printf( "Interface %s specified more than once.\n", ifname); exit(EXIT_FAILURE); } } if (NumInterfaces >= MAX_INTERFACES) { printf( "Too many interfaces (%d max)\n", MAX_INTERFACES); exit(EXIT_FAILURE); } i = &Interfaces[NumInterfaces++]; strncpy(i->name, ifname, IFNAMSIZ); i->name[IFNAMSIZ] = 0; i->discoverySock = openInterface(ifname, Eth_PPPOE_Discovery, i->mac, NULL); i->sessionSock = openInterface(ifname, Eth_PPPOE_Session, NULL, NULL); i->clientOK = clientOK; i->acOK = acOK; }
void ClientSettings::selectInterface() { QString fileName = QFileDialog::getOpenFileName(this, tr("Charger une interface"), QString(), "Fichiers d'interface (*"IEXT")"); if(fileName.isEmpty()) return; m_interfacePath->setText(fileName); openInterface(); }
/********************************************************************** *%FUNCTION: discovery *%ARGUMENTS: * conn -- PPPoE connection info structure *%RETURNS: * Nothing *%DESCRIPTION: * Performs the PPPoE discovery phase ***********************************************************************/ void discovery(PPPoEConnection *conn) { int padiAttempts = 0; int padrAttempts = 0; int timeout = conn->discoveryTimeout; conn->discoverySocket = openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth); do { padiAttempts++; if (padiAttempts > MAX_PADI_ATTEMPTS) { printErr("Timeout waiting for PADO packets"); close(conn->discoverySocket); conn->discoverySocket = -1; return; } sendPADI(conn); conn->discoveryState = STATE_SENT_PADI; waitForPADO(conn, timeout); timeout *= 3; if (timeout > 60) timeout = 10; } while (conn->discoveryState == STATE_SENT_PADI); timeout = conn->discoveryTimeout; do { padrAttempts++; if (padrAttempts > MAX_PADI_ATTEMPTS) { printErr("Timeout waiting for PADS packets"); close(conn->discoverySocket); conn->discoverySocket = -1; return; } sendPADR(conn); conn->discoveryState = STATE_SENT_PADR; waitForPADS(conn, timeout); timeout *= 3; if (timeout > 60) timeout = 10; } while (conn->discoveryState == STATE_SENT_PADR); if (!conn->seenMaxPayload) { /* RFC 4638: MUST limit MTU/MRU to 1492 */ if (lcp_allowoptions[0].mru > ETH_PPPOE_MTU) lcp_allowoptions[0].mru = ETH_PPPOE_MTU; if (lcp_wantoptions[0].mru > ETH_PPPOE_MTU) lcp_wantoptions[0].mru = ETH_PPPOE_MTU; } /* We're done. */ conn->discoveryState = STATE_SESSION; return; }
bool cPcapNet::sendFile (const char* file, bool sync, int loops) { struct pcap_pkthdr *header; const u_char *pkt_data; bpf_u_int32 len = 0; bool error = false; // FIXME close interface on error uint32_t count = getFileSize(file); if (!openInterface ()) return false; pcap_send_queue* q = pcap_sendqueue_alloc (count); if (!q) { fprintf (stderr, "can't allocate sendqueue\n"); return false; } cPcapFileIO pcapfile; if (!pcapfile.open (file)) return false; // Retrieve the packets from the file while (pcapfile.read (&header, &pkt_data)) { int r = pcap_sendqueue_queue (q, header, pkt_data); // pcap_sendqueue_queue can only fail, if we have'n allocated enough memory assert (!r); len += (header->len + sizeof (*header)); } error = pcapfile.error (); if (error) fprintf (stderr, "File error while reading %s\n", file); pcapfile.close (); while (!error && loops--) { error = pcap_sendqueue_transmit (ifcHandle, q, sync) != len; if (error) fprintf (stderr, "PCAP could not send transmit buffer\n"); } pcap_sendqueue_destroy (q); pcap_close(ifcHandle); return !error; }
void openAInterface(int fd, struct sockaddr * addr) { int i; for(i=0;i<interface_max_connections && interfaces[i].open;i++); if(i==interface_max_connections) { ERROR("Max Connections Reached!\n"); while(close(fd) && errno==EINTR); } else { SECURE("interface %i: opened from ",i); switch(addr->sa_family) { case AF_INET: { char * host = inet_ntoa( ((struct sockaddr_in *)addr)-> sin_addr); if(host) { SECURE("%s\n",host); } else { SECURE("error getting ipv4 address\n"); } } break; #ifdef HAVE_IPV6 case AF_INET6: { char host[INET6_ADDRSTRLEN+1]; memset(host,0,INET6_ADDRSTRLEN+1); if(inet_ntop(AF_INET6,(void *) &(((struct sockaddr_in6 *)addr)-> sin6_addr),host,INET6_ADDRSTRLEN)) { SECURE("%s\n",host); } else { SECURE("error getting ipv6 address\n"); } } break; #endif case AF_UNIX: SECURE("local connection\n"); break; default: SECURE("unknown\n"); } openInterface(&(interfaces[i]),fd); } }
bool cPcapNet::sendFrame (const uint8_t* payload, int length, int loops) { if (!openInterface ()) return false; int ret = 0; while (loops-- && !ret) { ret = pcap_sendpacket (ifcHandle, (u_char*)payload, length); } pcap_close(ifcHandle); return ret; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); m_idRecord = -1; connect(ui->action_File_Create, SIGNAL(triggered()), this, SLOT(createKhollo())); connect(ui->action_File_Open, SIGNAL(triggered()), this, SLOT(openKhollo())); connect(ui->action_File_Settings, SIGNAL(triggered()), this, SLOT(openSettings())); connect(ui->action_File_Quit, SIGNAL(triggered()), this, SLOT(close())); connect(ui->action_DB_Students, SIGNAL(triggered()), this, SLOT(openStudentsManager())); connect(ui->action_DB_Groups, SIGNAL(triggered()), this, SLOT(openGroupsManager())); connect(ui->action_DB_Subjects, SIGNAL(triggered()), this, SLOT(openSubjectsManager())); connect(ui->action_DB_Kholleurs, SIGNAL(triggered()), this, SLOT(openKholleursManager())); connect(ui->action_Schedule_Students_Groups, SIGNAL(triggered()), this, SLOT(openUsersGroupsManager())); connect(ui->action_Schedule_Timetable, SIGNAL(triggered()), this, SLOT(openCoursesManager())); connect(ui->action_Schedule_Swapping_Groups, SIGNAL(triggered()), this, SLOT(openGroupsSwappingsManager())); connect(ui->action_Schedule_Tribes, SIGNAL(triggered()), this, SLOT(openTribesManager())); connect(ui->action_Schedule_Kholles, SIGNAL(triggered()), this, SLOT(openTimeslotsManager())); connect(ui->action_Schedule_Events, SIGNAL(triggered()), this, SLOT(openEventsManager())); connect(ui->action_Kholles_Interface, SIGNAL(triggered()), this, SLOT(openInterface())); connect(ui->action_Kholles_Generate, SIGNAL(triggered()), this, SLOT(openKholloscope())); connect(ui->action_Kholles_Historic, SIGNAL(triggered()), this, SLOT(openReview())); connect(ui->action_Kholles_LastChanges, SIGNAL(triggered()), this, SLOT(openLastChanges())); connect(ui->action_Help, SIGNAL(triggered()), this, SLOT(openHelp())); connect(ui->action_AboutIt, SIGNAL(triggered()), this, SLOT(openAboutIt())); connect(this, SIGNAL(triggerInterface(QDate,int)), this, SLOT(openInterfaceWithDate(QDate,int))); m_shortcutNotepad = Notepad::shortcut(); this->addAction(m_shortcutNotepad); updateWindow(); #ifndef Q_OS_MAC // Ouvrir directement un fichier sur OS autre que Mac args = QCoreApplication::arguments(); if(args.count() > 1) { QString suffix = QFileInfo(args[1]).suffix().toUpper(); // Check the file suffix if(suffix == "KSCOPE") { openKhollo(args[1]); // Try to open the file } else { QMessageBox::critical(this, "Fichier non pris en charge", "Erreur : Fichier " + QFileInfo(args[1]).suffix().toUpper() + " non pris en charge."); } } #endif }
/********************************************************************** *%FUNCTION: discovery *%ARGUMENTS: * conn -- PPPoE connection info structure *%RETURNS: * Nothing *%DESCRIPTION: * Performs the PPPoE discovery phase ***********************************************************************/ void discovery(PPPoEConnection *conn) { int padiAttempts = 0; int padrAttempts = 0; int timeout = conn->discoveryTimeout; conn->discoverySocket = openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth); do { padiAttempts++; if (padiAttempts > MAX_PADI_ATTEMPTS) { warn("Timeout waiting for PADO packets"); close(conn->discoverySocket); conn->discoverySocket = -1; return; } sendPADI(conn); conn->discoveryState = STATE_SENT_PADI; waitForPADO(conn, timeout); timeout *= 2; } while (conn->discoveryState == STATE_SENT_PADI); timeout = conn->discoveryTimeout; do { padrAttempts++; if (padrAttempts > MAX_PADI_ATTEMPTS) { warn("Timeout waiting for PADS packets"); close(conn->discoverySocket); conn->discoverySocket = -1; return; } sendPADR(conn); conn->discoveryState = STATE_SENT_PADR; waitForPADS(conn, timeout); timeout *= 2; } while (conn->discoveryState == STATE_SENT_PADR); /* We're done. */ conn->discoveryState = STATE_SESSION; return; }
Int32 SerialInterface::recv(UInt8* pBuf, UInt32 size) { size_t ret = -1; if (!m_isPortGood) { sleep(1); openInterface(); } if (m_fd > 0) { fd_set rdfs; struct timeval timeout; FD_ZERO(&rdfs); FD_SET(m_fd, &rdfs); timeout.tv_sec = 1; timeout.tv_usec = 0; int sel = 0; if ((sel = select(m_fd+1, &rdfs, NULL, NULL, &timeout)) > 0) { ret = read(m_fd, pBuf, 1); } if (ret < 0 || sel < 0) { m_isPortGood = false; close(m_fd); ret = -1; printf("Closing port\n"); } else if (sel == 0) { printf("timeout\n"); } } return ret; }
/********************************************************************** *%FUNCTION: discovery *%ARGUMENTS: * conn -- PPPoE connection info structure *%RETURNS: * Nothing *%DESCRIPTION: * Performs the PPPoE discovery phase ***********************************************************************/ void discovery(PPPoEConnection *conn) { int padiAttempts = 0; int timeout = PADI_TIMEOUT; conn->discoverySocket = openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth); do { padiAttempts++; if (padiAttempts > MAX_PADI_ATTEMPTS) { fprintf(stderr, "Timeout waiting for PADO packets\n"); close(conn->discoverySocket); conn->discoverySocket = -1; return; } sendPADI(conn); conn->discoveryState = STATE_SENT_PADI; waitForPADO(conn, timeout); } while (!conn->numPADOs); }
Int32 SerialInterface::send(UInt8* pBuf, UInt32 size) { size_t ret = -1; if (!m_isPortGood) { sleep(1); openInterface(); } if (m_fd > 0) { fd_set rdfs; struct timeval timeout; FD_ZERO(&rdfs); FD_SET(m_fd, &rdfs); timeout.tv_sec = 1; timeout.tv_usec = 0; if (select(m_fd+1, NULL, &rdfs, NULL, &timeout) > 0) { ret = write(m_fd, pBuf, size); if (ret < 0) { m_isPortGood = false; close(m_fd); printf("Closing port\n"); ret = -1; } } } return ret; }
/********************************************************************** *%FUNCTION: discovery *%ARGUMENTS: * conn -- PPPoE connection info structure *%RETURNS: * Nothing *%DESCRIPTION: * Performs the PPPoE discovery phase ***********************************************************************/ void discovery(PPPoEConnection *conn) { int padiAttempts = 0; int padrAttempts = 0; int timeout = PADI_TIMEOUT; /* Skip discovery and don't open discovery socket? */ if (conn->skipDiscovery && conn->noDiscoverySocket) { conn->discoveryState = STATE_SESSION; return; } conn->discoverySocket = openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth); /* Skip discovery? */ if (conn->skipDiscovery) { conn->discoveryState = STATE_SESSION; if (conn->killSession) { sendPADT(conn, "RP-PPPoE: Session killed manually"); exit(0); } return; } do { padiAttempts++; if (padiAttempts > MAX_PADI_ATTEMPTS) { system("rm /etc/ppp/connectfile"); rp_fatal("Timeout waiting for PADO packets0"); } sendPADI(conn); conn->discoveryState = STATE_SENT_PADI; waitForPADO(conn, timeout); #if 0 // RexHua to Reduce connect time /* If we're just probing for access concentrators, don't do exponential backoff. This reduces the time for an unsuccessful probe to 15 seconds. */ if (!conn->printACNames) { timeout *= 2; } #endif if (conn->printACNames && conn->numPADOs) { break; } } while (conn->discoveryState == STATE_SENT_PADI); /* If we're only printing access concentrator names, we're done */ if (conn->printACNames) { printf("--------------------------------------------------\n"); exit(0); } timeout = PADI_TIMEOUT; do { padrAttempts++; if (padrAttempts > MAX_PADI_ATTEMPTS) { rp_fatal("Timeout waiting for PADS packets"); } sendPADR(conn); conn->discoveryState = STATE_SENT_PADR; waitForPADS(conn, timeout); #if 0 // RexHua to Reduce connect time timeout *= 2; #endif } while (conn->discoveryState == STATE_SENT_PADR); /* We're done. */ conn->discoveryState = STATE_SESSION; return; }
/********************************************************************** *%FUNCTION: discovery *%ARGUMENTS: * conn -- PPPoE connection info structure *%RETURNS: * Nothing *%DESCRIPTION: * Performs the PPPoE discovery phase ***********************************************************************/ void discovery(PPPoEConnection *conn) { int padiAttempts = 0; int padrAttempts = 0; int timeout = PADI_TIMEOUT; /* Skip discovery and don't open discovery socket? */ if (conn->skipDiscovery && conn->noDiscoverySocket) { conn->discoveryState = STATE_SESSION; return; } conn->discoverySocket = openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth); /* Skip discovery? */ if (conn->skipDiscovery) { conn->discoveryState = STATE_SESSION; return; } do { padiAttempts++; if (padiAttempts > MAX_PADI_ATTEMPTS) { warn("Timeout waiting for PADO packets"); close(conn->discoverySocket); conn->discoverySocket = -1; return; } sendPADI(conn); conn->discoveryState = STATE_SENT_PADI; waitForPADO(conn, timeout); /* If we're just probing for access concentrators, don't do exponential backoff. This reduces the time for an unsuccessful probe to 15 seconds. */ if (!conn->printACNames) { timeout *= 2; } if (conn->printACNames && conn->numPADOs) { break; } } while (conn->discoveryState == STATE_SENT_PADI); /* If we're only printing access concentrator names, we're done */ if (conn->printACNames) { die(0); } timeout = PADI_TIMEOUT; do { padrAttempts++; if (padrAttempts > MAX_PADI_ATTEMPTS) { warn("Timeout waiting for PADS packets"); close(conn->discoverySocket); conn->discoverySocket = -1; return; } sendPADR(conn); conn->discoveryState = STATE_SENT_PADR; waitForPADS(conn, timeout); timeout *= 2; } while (conn->discoveryState == STATE_SENT_PADR); /* We're done. */ conn->discoveryState = STATE_SESSION; return; }
/********************************************************************** *%FUNCTION: main *%ARGUMENTS: * argc, argv -- count and values of command-line arguments *%RETURNS: * Nothing *%DESCRIPTION: * Main program ***********************************************************************/ int main(int argc, char *argv[]) { int opt; int sock; PPPoEPacket pkt; int size; #ifdef USE_DLPI long buf[MAXDLBUF]; #endif if (getuid() != geteuid() || getgid() != getegid()) { fprintf(stderr, "SECURITY WARNING: pppoe-sniff will NOT run suid or sgid. Fix your installation.\n"); exit(1); } while((opt = getopt(argc, argv, "I:V")) != -1) { switch(opt) { case 'I': SET_STRING(IfName, optarg); break; case 'V': printf("pppoe-sniff: Roaring Penguin PPPoE Version %s\n", VERSION); exit(0); default: usage(argv[0]); } } /* Pick a default interface name */ if (!IfName) { IfName = DEFAULT_IF; } /* Open the interface */ #ifdef USE_DLPI sock = openInterface(IfName, Eth_PPPOE_Discovery, NULL); dlpromisconreq(sock, DL_PROMISC_PHYS); dlokack(sock, (char *)buf); dlpromisconreq(sock, DL_PROMISC_SAP); dlokack(sock, (char *)buf); #else sock = openInterface(IfName, ETH_P_ALL, NULL); #endif /* We assume interface is in promiscuous mode -- use ifconfig to ensure this */ fprintf(stderr, "Sniffing for PADR. Start your connection on another machine...\n"); while (!SeenPADR) { if (receivePacket(sock, &pkt, &size) < 0) continue; if (ntohs(pkt.length) + HDR_SIZE > size) continue; if (pkt.ver != 1 || pkt.type != 1) continue; if (pkt.code != CODE_PADR) continue; /* Looks promising... parse it */ if (parsePacket(&pkt, parsePADRTags, NULL) < 0) { continue; } DiscType = ntohs(pkt.ethHdr.h_proto); fprintf(stderr, "\nExcellent! Sniffed a likely-looking PADR.\n"); break; } while (!SeenSess) { if (receivePacket(sock, &pkt, &size) < 0) continue; if (ntohs(pkt.length) + HDR_SIZE > size) continue; if (pkt.ver != 1 || pkt.type != 1) continue; if (pkt.code != CODE_SESS) continue; /* Cool! */ SessType = ntohs(pkt.ethHdr.h_proto); break; } fprintf(stderr, "Wonderful! Sniffed a likely-looking session packet.\n"); if ((ServiceName == NULL || *ServiceName == 0) && DiscType == ETH_PPPOE_DISCOVERY && SessType == ETH_PPPOE_SESSION) { fprintf(stderr, "\nGreat! It looks like a standard PPPoE service.\nYou should not need anything special in the configuration file.\n"); return 0; } fprintf(stderr, "\nOK, looks like you need something special in the configuration file.\nTry this:\n\n"); if (ServiceName != NULL && *ServiceName != 0) { fprintf(stderr, "SERVICENAME='%s'\n", ServiceName); } if (DiscType != ETH_PPPOE_DISCOVERY || SessType != ETH_PPPOE_SESSION) { fprintf(stderr, " PPPOE_EXTRA='-f %x:%x'\n", DiscType, SessType); } return 0; }
ClientSettings::ClientSettings(ClientInterface* par) { m_parent = par; setParent(par); setWhatsThis(tr("Ici, vous pouvez régler bon nombre d'options du logiciel.")); setWindowFlags(Qt::Dialog|Qt::CustomizeWindowHint|Qt::WindowTitleHint|Qt::WindowCloseButtonHint|Qt::WindowContextHelpButtonHint); m_settings = allocateSettings(this); QVBoxLayout* la = new QVBoxLayout; QVBoxLayout* la2 = new QVBoxLayout; QHBoxLayout* hla= new QHBoxLayout; setLayout(hla); hla->addLayout(la); hla->addLayout(la2); { QGroupBox *gb = new QGroupBox(tr("Général")); la->addWidget(gb); QVBoxLayout* v_la = new QVBoxLayout; gb->setLayout(v_la); { QHBoxLayout* h_la = new QHBoxLayout; v_la->addLayout(h_la); m_nickname = new QLineEdit(m_settings->value(PARAM_NICK).toString(), this); m_nickname->setMaxLength(MAX_NICKNAME_LENGHT); m_nickname->setWhatsThis(tr("Entrez ici le pseudo que vous utiliserez sur le chat. A contrario de la commande /pseudo, ce pseudo sera automatiquement appliqué à chaque connexion.")); h_la->addWidget(new QLabel(tr("Pseudo :"))); h_la->addWidget(m_nickname); } } { QGroupBox *gb = new QGroupBox(tr("Interface")); la->addWidget(gb); QVBoxLayout* v_la = new QVBoxLayout; gb->setLayout(v_la); { QHBoxLayout* h_la = new QHBoxLayout; v_la->addLayout(h_la); m_selectInterface = new QPushButton("...", this); m_selectInterface->setWhatsThis(tr("Parcourir le disque dur...")); connect(m_selectInterface, SIGNAL(pressed()), this, SLOT(selectInterface())); m_interfacePath = new QLineEdit(m_settings->value(PARAM_INTERFACE, DEFAULT_INTERFACE).toString(), this); connect(m_interfacePath, SIGNAL(returnPressed()), this, SLOT(openInterface())); h_la->addWidget(m_interfacePath); h_la->addWidget(m_selectInterface); } { QHBoxLayout* h_la = new QHBoxLayout; v_la->addLayout(h_la); m_saveInterface = new QPushButton(tr("Sauvegarder"), this); m_saveInterface->setWhatsThis(tr("Sauvegarder une interface.")); connect(m_saveInterface, SIGNAL(pressed()), this, SLOT(saveInterface())); h_la->addWidget(m_saveInterface); m_openInterface = new QPushButton(tr("Charger"), this); m_openInterface->setWhatsThis(tr("Charger l'interface marquée plus haut.")); connect(m_openInterface, SIGNAL(pressed()), this, SLOT(openInterface())); h_la->addWidget(m_openInterface); } } { QGroupBox *gb = new QGroupBox(tr("Thème")); la->addWidget(gb); QVBoxLayout* v_la = new QVBoxLayout; gb->setLayout(v_la); QHBoxLayout* h_la = new QHBoxLayout; v_la->addLayout(h_la); m_selectCSS = new QPushButton("...", this); m_selectCSS->setWhatsThis(tr("Parcourir le disque dur...")); connect(m_selectCSS, SIGNAL(pressed()), this, SLOT(selectCSS())); m_CSSPath = new QLineEdit(m_settings->value(PARAM_CSS).toString(), this); connect(m_CSSPath, SIGNAL(returnPressed()), this, SLOT(openCSS())); h_la->addWidget(m_CSSPath); h_la->addWidget(m_selectCSS); m_openCSS = new QPushButton(tr("Charger"), this); m_openCSS->setWhatsThis(tr("Charger la feuille de style indiquée plus haut.")); connect(m_openCSS, SIGNAL(pressed()), this, SLOT(openCSS())); v_la->addWidget(m_openCSS); } { QGroupBox *gb = new QGroupBox(tr("Paramètres de connexion")); gb->setWhatsThis(tr("Ces options ne sont disponibles que lorsque vous n'êtes pas connecté à un serveur.")); la->addWidget(gb); QVBoxLayout* v_la = new QVBoxLayout; gb->setLayout(v_la); v_la->addWidget(new QLabel(tr("Addresse IP et port du serveur :"))); QHBoxLayout* h_la = new QHBoxLayout; v_la->addLayout(h_la); m_serverIP = new QLineEdit(m_settings->value(PARAM_IP, SERVER_IP).toString(), this); m_serverIP->setInputMask("000.000.000.000;"); m_serverPort = new QSpinBox(this); m_serverPort->setMinimum(1024); m_serverPort->setMaximum(65535); m_serverPort->setValue(m_settings->value(PARAM_PORT, SERVER_PORT).toInt()); h_la->addWidget(m_serverIP); h_la->addWidget(new QLabel(":")); h_la->addWidget(m_serverPort); if(par->isConnected()) gb->setEnabled(false); } { QGroupBox *gb = new QGroupBox(tr("Paramètres du son")); la2->addWidget(gb); QVBoxLayout* v_la = new QVBoxLayout; gb->setLayout(v_la); v_la->addWidget(new QLabel(tr("Volume des sons d'ambiance :"))); { QHBoxLayout* h_la = new QHBoxLayout; v_la->addLayout(h_la); m_sound = new QSlider(this); m_sound->setMaximum(1000); m_sound->setOrientation(Qt::Horizontal); m_sound->setValue(static_cast<int>(m_settings->value(PARAM_SOUND, 100.f).toFloat()*10)); connect(m_sound, SIGNAL(valueChanged(int)), this, SLOT(soundSliderChanged(int))); m_soundSpinBox=new QDoubleSpinBox(this); m_soundSpinBox->setMaximum(100); m_soundSpinBox->setMinimum(0); m_soundSpinBox->setMaximum(100); m_soundSpinBox->setDecimals(1); m_soundSpinBox->setValue(m_settings->value(PARAM_SOUND, 100.f).toFloat()); connect(m_soundSpinBox, SIGNAL(valueChanged(double)), this, SLOT(soundSpinBoxChanged(double))); h_la->addWidget(m_sound); h_la->addWidget(m_soundSpinBox); } { QHBoxLayout* h_la = new QHBoxLayout; v_la->addLayout(h_la); h_la->addWidget(new QLabel(tr("Périphériques sonore :"))); m_chb_dvc_out=new QCheckBox(tr("Utiliser le périphérique par défaut"), this); v_la->addWidget(m_chb_dvc_out); m_cb_dvc_out=new QComboBox(this); m_cb_dvc_out->addItems(getOALDevices(true)); m_cb_dvc_out->setCurrentIndex(m_cb_dvc_out->findText(getOALCurrentDevice(true))); h_la->addWidget(m_cb_dvc_out); } { QHBoxLayout* h_la = new QHBoxLayout; v_la->addLayout(h_la); h_la->addWidget(new QLabel(tr("Périphériques de capture :"))); m_chb_dvc_in=new QCheckBox(tr("Utiliser le périphérique par défaut"), this); v_la->addWidget(m_chb_dvc_in); m_cb_dvc_in=new QComboBox(this); m_cb_dvc_in->addItems(getOALDevices(false)); int ind=m_cb_dvc_in->findText(getOALCurrentDevice(false)); if(ind==-1) { QString d=getOALCurrentDevice(false); m_cb_dvc_in->addItem(d); m_cb_dvc_in->setCurrentIndex(m_cb_dvc_in->findText(d)); } else m_cb_dvc_in->setCurrentIndex(ind); h_la->addWidget(m_cb_dvc_in); } } { m_voip = new QGroupBox(tr("Paramètres de la VOIP")); m_voip->setCheckable(true); m_voip->setChecked(m_settings->value(PARAM_VOIP_ENABLED, true).toBool()); la2->addWidget(m_voip); QVBoxLayout* v_la = new QVBoxLayout; m_voip->setLayout(v_la); v_la->addWidget(new QLabel(tr("Volume de la reception :"))); { QHBoxLayout* h_la = new QHBoxLayout; v_la->addLayout(h_la); m_VOIPSound = new QSlider(this); m_VOIPSound->setMaximum(1000); m_VOIPSound->setOrientation(Qt::Horizontal); m_VOIPSound->setValue(static_cast<int>(m_settings->value(PARAM_VOIP_SOUND, 100.f).toFloat()*10)); connect(m_VOIPSound, SIGNAL(valueChanged(int)), this, SLOT(VOIPSoundSliderChanged(int))); m_VOIPSoundSpinBox=new QDoubleSpinBox(this); m_VOIPSoundSpinBox->setMaximum(100); m_VOIPSoundSpinBox->setMinimum(0); m_VOIPSoundSpinBox->setDecimals(1); m_VOIPSoundSpinBox->setValue(m_settings->value(PARAM_VOIP_SOUND, 100.f).toFloat()); connect(m_VOIPSoundSpinBox, SIGNAL(valueChanged(double)), this, SLOT(VOIPSoundSpinBoxChanged(double))); h_la->addWidget(m_VOIPSound); h_la->addWidget(m_VOIPSoundSpinBox); } v_la->addWidget(new QLabel(tr("Qualité de la VOIP (sortant) :"))); { QHBoxLayout* h_la = new QHBoxLayout; v_la->addLayout(h_la); m_VOIPQuality = new QSlider(this); m_VOIPQuality->setMinimum(1); m_VOIPQuality->setMaximum(100); m_VOIPQuality->setOrientation(Qt::Horizontal); m_VOIPQuality->setValue(static_cast<int>(m_settings->value(PARAM_VOIP_QUALITY, 4).toFloat()*10)); connect(m_VOIPQuality, SIGNAL(valueChanged(int)), this, SLOT(VOIPQualitySliderChanged(int))); h_la->addWidget(new QLabel(tr("Plus rapide"))); h_la->addWidget(m_VOIPQuality); h_la->addWidget(new QLabel(tr("Plus clair"))); } } { QGroupBox *gb = new QGroupBox(tr("Bibliothèques de sons")); la2->addWidget(gb); QPushButton* m_libsListRefresh = new QPushButton(tr("Rafraichir"), this); connect(m_libsListRefresh, SIGNAL(pressed()), this, SLOT(refreshLibs())); QPushButton* m_libsListLoad = new QPushButton(tr("Charger"), this); connect(m_libsListLoad, SIGNAL(pressed()), this, SLOT(loadLibs())); QScrollArea* m_libsScroll=new QScrollArea(this); { QVBoxLayout* v = new QVBoxLayout; gb->setLayout(v); v->addWidget(m_libsListRefresh); v->addWidget(m_libsScroll); v->addWidget(m_libsListLoad); } m_libs_la = new QVBoxLayout; { gar=new QWidget(this); m_libsScroll->setWidget(gar); gar->setLayout(m_libs_la); } } { m_ok = new QPushButton(tr("Valider"), this); m_ok->setDefault(true); connect(m_ok, SIGNAL(pressed()), this, SLOT(ok())); m_cancel = new QPushButton(tr("Annuler"), this); connect(m_cancel, SIGNAL(pressed()), this, SLOT(reject())); QHBoxLayout* h_la = new QHBoxLayout; h_la->addWidget(m_ok); h_la->addWidget(m_cancel); la->addLayout(h_la); } refreshLibs(); }
/********************************************************************** * %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; }
/********************************************************************** * %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; }
/********************************************************************** * %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; PPPoEConnection reconn ; memset(&reconn,0,sizeof(reconn)); 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 { memcpy(&reconn,conn,sizeof(reconn)); reconn.discoverySocket = openInterface(reconn.ifName, Eth_PPPOE_Discovery, reconn.myEth); sendPADT(&reconn, NULL); close(reconn.discoverySocket); sleep(3); 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); if (connect(conn->sessionSocket, (struct sockaddr *) &sp, sizeof(struct sockaddr_pppox)) < 0) { error("Failed to connect PPPoE socket: %d %m", errno); close(conn->sessionSocket); goto errout; } return conn->sessionSocket; errout: if (conn->discoverySocket >= 0) { sendPADT(conn, NULL); close(conn->discoverySocket); conn->discoverySocket = -1; } return -1; }
/********************************************************************** *%FUNCTION: discovery *%ARGUMENTS: * conn -- PPPoE connection info structure *%RETURNS: * Nothing *%DESCRIPTION: * Performs the PPPoE discovery phase ***********************************************************************/ void discovery(PPPoEConnection *conn) { int padiAttempts = 0; int padrAttempts = 0; int timeout = PADI_TIMEOUT; /* Skip discovery and don't open discovery socket? */ if (conn->skipDiscovery && conn->noDiscoverySocket) { conn->discoveryState = STATE_SESSION; PPPD_DEBUG(printf("%s %d\n",__FILE__,__LINE__)); return; } conn->discoverySocket = openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth); /* Skip discovery? */ if (conn->skipDiscovery) { conn->discoveryState = STATE_SESSION; if (conn->killSession) { sendPADT(conn, "RP-PPPoE: Session killed manually"); exit(0); } PPPD_DEBUG(printf("%s %d\n",__FILE__,__LINE__)); return; } do { PPPD_DEBUG(printf("%s %d\n",__FILE__,__LINE__)); padiAttempts++; if (padiAttempts > MAX_PADI_ATTEMPTS) { rp_fatal("Timeout waiting for PADO packets"); } sendPADI(conn); conn->discoveryState = STATE_SENT_PADI; waitForPADO(conn, timeout); /* If we're just probing for access concentrators, don't do exponential backoff. This reduces the time for an unsuccessful probe to 15 seconds. */ if (!conn->printACNames) { timeout *= 2; } if (conn->printACNames && conn->numPADOs) { break; } } while (conn->discoveryState == STATE_SENT_PADI); /* If we're only printing access concentrator names, we're done */ if (conn->printACNames) { printf("--------------------------------------------------\n"); exit(0); } PPPD_DEBUG(printf("%s %d\n",__FILE__,__LINE__)); timeout = PADI_TIMEOUT; do { PPPD_DEBUG(printf("%s %d\n",__FILE__,__LINE__)); padrAttempts++; if (padrAttempts > MAX_PADI_ATTEMPTS) { rp_fatal("Timeout waiting for PADS packets"); } sendPADR(conn); conn->discoveryState = STATE_SENT_PADR; waitForPADS(conn, timeout); timeout *= 2; } while (conn->discoveryState == STATE_SENT_PADR); /* We're done. */ free(conn->serviceName);//mcli conn->serviceName=NULL;//mcli conn->discoveryState = STATE_SESSION; PPPD_DEBUG(printf("%s %d\n",__FILE__,__LINE__)); return; }
int rp_openInterface(char const *ifname, UINT16_t type, char *hwaddr) { return openInterface(ifname, type, static_cast<unsigned char*>(static_cast<void*>(hwaddr))); }
void kpppoe_discovery(PPPoEConnection * conn) { int padiAttempts = 0; int padrAttempts = 0; int timeout = PADI_TIMEOUT; d_dbg("[%d]: kpppoe_discovery() >>>\n", getpid()); /* Skip discovery and don't open discovery socket ? */ if (conn->skipDiscovery && conn->noDiscoverySocket) { conn->discoveryState = STATE_SESSION; return; } conn->discoverySocket = openInterface(conn->ifName, Eth_PPPOE_Discovery, conn->myEth); /* Skip discovery ? */ if (conn->skipDiscovery) { conn->discoveryState = STATE_SESSION; if (conn->killSession) { kpppoe_sendPADT(conn, "Session killed manually"); exit(0); } return; } do { padiAttempts++; if (padiAttempts > MAX_PADI_ATTEMPTS) { d_warn("[%d]: Timeout waiting for PADO packets\n", getpid()); return; } sendPADI(conn); conn->discoveryState = STATE_SENT_PADI; waitForPADO(conn, timeout); /* If we're just probing for access concentrators, don't do * exponential backoff. This reduces the time for an unsuccessful * probe to 15 seconds. */ if (!conn->printACNames) timeout *= 2; if (conn->printACNames && conn->numPADOs) break; } while (conn->discoveryState == STATE_SENT_PADI); /* If we're only printing access concentrator names, we're done */ if (conn->printACNames) { printf("-----------------------------------------------------------\n"); exit(0); } timeout = PADI_TIMEOUT; do { padrAttempts++; if (padrAttempts > MAX_PADI_ATTEMPTS) { d_warn("[%d]: Timeout waiting for PADS packets, timeout=[%d]\n", getpid(), timeout); return; } sendPADR(conn); conn->discoveryState = STATE_SENT_PADR; waitForPADS(conn, timeout); timeout *= 2; } while (conn->discoveryState == STATE_SENT_PADR); /* We're done. */ conn->discoveryState = STATE_SESSION; return; }