[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/network/ksniffer
From: Giovanni Venturi <gventuri73 () tiscali ! it>
Date: 2005-10-02 20:38:50
Message-ID: 1128285530.073844.8523.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 466508 by gianni:
other code cleaning
M +51 -49 ksniffer.cpp
M +3 -0 ksniffer.h
M +2 -1 packetmanager.cpp
M +2 -1 sniffer.cpp
M +2 -2 version.h
--- trunk/playground/network/ksniffer/ksniffer.cpp #466507:466508
@@ -174,6 +174,9 @@
m_loadFromFile = false;
m_startedShowing = false;
+ // need to remove temporary file just when I load a non local file and packets are \
available + m_wroteTmpLocalFile = false;
+
m_timer = new QTimer(this);
connect( m_timer, SIGNAL(timeout()), this, SLOT(checkIfSniffing()));
}
@@ -521,6 +524,7 @@
}
changeStatusbar( i18n("Sniffing network by \"%1\" \
interface.").arg(cod->selectedInterface()) );
+ m_wroteTmpLocalFile = true;
startLiveSniffing( cod->selectedInterface() );
}
else
@@ -688,6 +692,17 @@
}
m_sniffer->setCaptureOptions( m_options );
+ if (m_wroteTmpLocalFile && !isLocal)
+ {
+ // need to remove old temporary file
+ QString tmpOldFile = m_options->strTmpDir();
+ tmpOldFile.append( "/" );
+ tmpOldFile.append ( TEMP_PCAP_FILE_NAME );
+ unlink( tmpOldFile );
+ kdDebug() << "++++++++++++++++++ removed ol temporary file: " << tmpOldFile << \
endl; + m_wroteTmpLocalFile = false;
+ }
+
// start sniffing getting packets from a libpcap selected file
startSniffingFromFile();
@@ -711,7 +726,9 @@
{
// copy file from temporary file directory
QString tmp = m_options->strTmpDir();
- tmp.append(TEMP_PCAP_FILE);
+ tmp.append( "/" );
+ tmp.append( TEMP_PCAP_FILE_NAME );
+ kdDebug() << "saving file: " << tmp << endl;
KURL src( tmp );
KURL dest(m_strFilename);
KIO::Job *job = KIO::copy( src, dest );
@@ -731,7 +748,9 @@
KURL dest = KFileDialog::getSaveURL();
QString tmp = m_options->strTmpDir();
- tmp.append( TEMP_PCAP_FILE );
+ tmp.append( "/" );
+ tmp.append( TEMP_PCAP_FILE_NAME );
+ kdDebug() << "saving file: " << tmp << endl;
KURL src( tmp );
if (!dest.isEmpty())
if (dest.isValid())
@@ -829,8 +848,6 @@
m_doingPause = false;
if (!m_loadFromFile)
{
- kdDebug() << "+++++++++++++ slotStop: m_startedShowing: " << m_startedShowing << \
" m_mustShowPacketsNow: " << m_mustShowPacketsNow << endl;
- //FIXME: startup: start sniffing and display after, stop sniffing and no packets \
got: wrong behaviur: it should show the "No packets" box if (m_mustShowPacketsNow || \
m_startedShowing) {
// if you want you can load a new file or start a new capture session
@@ -870,7 +887,6 @@
}
else if (!m_startedShowing && !m_mustShowPacketsNow && \
!m_packets->packetAvailable()) {
- kdDebug() << "stopped for the first sniffing" << endl;
setPlainCaption( i18n("KSniffer - The KDE Network Sniffer") );
KMessageBox::information(this, i18n("You got no packets."));
m_actSave->setEnabled( false );
@@ -896,13 +912,11 @@
}
else
{
- //FIXME: complete here
-
// need to enable accepting packet for Packet Manager again
m_packets->acceptPacket( true );
QString destFile = m_options->strTmpDir();
destFile.append( "/" );
- destFile.append( TEMP_PCAP_FILE );
+ destFile.append( TEMP_PCAP_FILE_NAME );
kdDebug() << "void KSniffer::slotStop(): destFile = " << destFile << endl;
showAfterDisplay( destFile );
}
@@ -921,7 +935,6 @@
m_packets->setFilename( url.path() );
// Packets available, need to save them, continue losting data
-
m_needToSave = true;
// we have to remove the captured data
@@ -1024,9 +1037,6 @@
void KSniffer::slotQuit()
{
- QString tmp = m_options->strTmpDir();
- tmp.append( TEMP_PCAP_FILE );
-
// user wants to close KSniffer
m_action = QUIT_APPL;
@@ -1039,43 +1049,27 @@
if ( m_packets->packetAvailable() && m_needToSave )
{
- //if ( )
- //{
- changeStatusbar( i18n("You have got data, maybe you want to save them.") );
+ changeStatusbar( i18n("You have got data, maybe you want to save them.") );
- int button = KMessageBox::questionYesNoCancel( this,
- i18n( "<p>Quitting KSniffer will cause the current packets to be \
lost.<br>Do you want to save them now?</p>" ),
- i18n( "Unsaved Captured Packets" ), KStdGuiItem::saveAs(), \
KStdGuiItem::discard() ); + int button = KMessageBox::questionYesNoCancel( this,
+ i18n( "<p>Quitting KSniffer will cause the current packets to be \
lost.<br>Do you want to save them now?</p>" ), + i18n( "Unsaved Captured \
Packets" ), KStdGuiItem::saveAs(), KStdGuiItem::discard() );
- // we have some data that maybe we want to save
- if ( button == KMessageBox::Yes )
- {
- slotSave();
- }
- else if ( button == KMessageBox::Cancel )
- {
- // ok the user don't want to quit KSniffer anymore
- m_action = DO_NOTHING;
- m_sniffer->continueSniffing();
- m_packets->acceptPacket( true );
- return;
- }
- else
- {
- // quitting without saving data, so...
- // ...stop really sniffing and...
- m_sniffer->stopSniffing();
-
- // ...remove the pcap temporary file
- kdDebug() << "+++++++++ I'm going to delete " << tmp.ascii() << endl;
- unlink( tmp.ascii() );
- }
- /*}
+ // we have some data that maybe we want to save
+ if ( button == KMessageBox::Yes )
+ slotSave();
+ else if ( button == KMessageBox::Cancel )
+ {
+ // ok the user don't want to quit KSniffer anymore
+ m_action = DO_NOTHING;
+ m_sniffer->continueSniffing();
+ m_packets->acceptPacket( true );
+ return;
+ }
else
- {
- kdDebug() << "+++++++++ I'm going to delete " << tmp.ascii() << endl;
- unlink( tmp.ascii() );
- }*/
+ // quitting without saving data, so...
+ // ...stop really sniffing and...
+ m_sniffer->stopSniffing();
}
// now we can remove the captured data
@@ -1087,6 +1081,17 @@
if ( m_tmpFile )
delete m_tmpFile;
+ if ( m_wroteTmpLocalFile )
+ {
+ QString tmp = m_options->strTmpDir();
+ tmp.append( "/" );
+ tmp.append( TEMP_PCAP_FILE_NAME );
+
+ // ...remove the pcap temporary file
+ kdDebug() << "+++++++++ I'm going to delete " << tmp.ascii() << endl;
+ unlink( tmp.ascii() );
+ }
+
// delay exit from KSniffer if Job's not finished
kapp->deref();
}
@@ -1095,9 +1100,6 @@
// decide what to do when the Job is finished
void KSniffer::copyingJobFinished( KIO::Job *job )
{
- QString tmp = m_options->strTmpDir();
- tmp.append(TEMP_PCAP_FILE);
-
changeStatusbar( i18n("Saved captured-packets.") );
// set the main widget new title
--- trunk/playground/network/ksniffer/ksniffer.h #466507:466508
@@ -179,6 +179,9 @@
// needed by slotStop to understand if it's showing captured packets
bool m_startedShowing;
+ // need to remove temporary file when I load a non local file
+ // and packets are available: to avoid it doesn't remove temporary file not needed
+ bool m_wroteTmpLocalFile;
/**
* Constant action to known if KSniffer has to be closed with special conditions
--- trunk/playground/network/ksniffer/packetmanager.cpp #466507:466508
@@ -139,7 +139,8 @@
void PacketManager::setTmpDir( const QString& tmpDir )
{
m_strTmpFile = tmpDir;
- m_strTmpFile.append( TEMP_PCAP_FILE );
+ m_strTmpFile.append( "/" );
+ m_strTmpFile.append( TEMP_PCAP_FILE_NAME );
}
--- trunk/playground/network/ksniffer/sniffer.cpp #466507:466508
@@ -249,7 +249,8 @@
else
{
QString tmp = m_strTmpDir;
- tmp.append( TEMP_PCAP_FILE );
+ tmp.append( "/" );
+ tmp.append( TEMP_PCAP_FILE_NAME );
m_pdump = pcap_dump_open( m_pcapfp, tmp.ascii() );
kdDebug() << "writing packets into " << tmp.ascii() << endl;
}
--- trunk/playground/network/ksniffer/version.h #466507:466508
@@ -4,6 +4,6 @@
#define APPVER "0.1.51"
#endif
-#ifndef TEMP_PCAP_FILE
-#define TEMP_PCAP_FILE "/ksniffer.pcap"
+#ifndef TEMP_PCAP_FILE_NAME
+#define TEMP_PCAP_FILE_NAME "ksniffer.pcap"
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic