[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:       2008-10-12 14:40:06
Message-ID: 1223822406.207601.7595.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 870437 by gianni:

Added more output in the error dialog in case of libpcap gets an error

 M  +1 -0      Changelog  
 M  +43 -42    ksniff/ksniff.cpp  
 M  +11 -1     ksniffer.cpp  
 M  +6 -0      ksniffer.h  


--- trunk/playground/network/ksniffer/Changelog #870436:870437
@@ -3,6 +3,7 @@
   - Fixed bug: don't get the correct number of packets if you change them more times \
                in the options
   - Fixed a Debian/Ubuntu issue starting ksniff backend: thanks to Kubuntu \
                developers for the patch :)
   - When you decide for a "New Capture" the dialog remember your last choice
+  - Added more output in the error dialog in case of libpcap gets an error
 
 KSniffer 0.3.2 [21 February 2008]
   - More information for ARP protocol
--- trunk/playground/network/ksniffer/ksniff/ksniff.cpp #870436:870437
@@ -77,24 +77,24 @@
 
   m_canSniff = true;
   m_bPauseSniffing = false;
-  cerr << endl << endl << APPNAME << "You choose to use interface: '" << \
                config->interface() << "'" << endl;
-  cerr << APPNAME << "sniffing in: '" << config->sniffFile() << "'" << endl;
-  cerr << APPNAME << "type of capture: " << config->sniffType() << endl;
+  cout << endl << endl << APPNAME << "You choose to use interface: '" << \
config->interface() << "'" << endl; +  cout << APPNAME << "sniffing in: '" << \
config->sniffFile() << "'" << endl; +  cout << APPNAME << "type of capture: " << \
config->sniffType() << endl;  if (config->sniffType() != STOP_CAPTURE_MANUALLY)
-    cerr << APPNAME << "PackSizeTime parameter: " << config->nPackSizeTime() << \
endl; +    cout << APPNAME << "PackSizeTime parameter: " << config->nPackSizeTime() \
<< endl;  switch (config->sniffType())
   {
     case STOP_CAPTURE_MANUALLY:
-      cerr << APPNAME << "the capture will be stopped manually by the user" << endl;
+      cout << APPNAME << "the capture will be stopped manually by the user" << endl;
       break;
     case STOP_AFTER_X_PACKETS:
-      cerr << APPNAME << "the packets capture will stop after: " << \
config->nPackSizeTime() * config->nUnits() << " packets" << endl; +      cout << \
APPNAME << "the packets capture will stop after: " << config->nPackSizeTime() * \
config->nUnits() << " packets" << endl;  break;
     case STOP_AFTER_X_BYTES:
-      cerr << APPNAME << "the packets capture will stop after: " << \
config->nPackSizeTime() * config->nUnits()  << " bytes" << endl; +      cout << \
APPNAME << "the packets capture will stop after: " << config->nPackSizeTime() * \
config->nUnits()  << " bytes" << endl;  break;
     case STOP_AFTER_X_SECONDS:
-      cerr << APPNAME << "the packets capture will stop after: " << \
config->nPackSizeTime() * config->nUnits()  << " seconds" << endl; +      cout << \
APPNAME << "the packets capture will stop after: " << config->nPackSizeTime() * \
config->nUnits()  << " seconds" << endl;  break;
   }
   fflush( stderr );
@@ -119,7 +119,7 @@
   #endif
 
   // delete the file, to avoid problem if cause of some strange reason (crash?) it \
                was not deleted at the KSniffer quit
-  cerr << APPNAME << "deleting " << config->sniffFile() << endl;
+  cout << APPNAME << "deleting " << config->sniffFile() << endl;
   fflush(stderr);
   if ( unlink(config->sniffFile()) == -1 )
     // if we don't reset errno and the file was not delete because all was ok on \
last quit @@ -143,7 +143,7 @@
   {
     m_pdump = pcap_dump_open( m_pcapfp, config->sniffFile() );
     chmod(config->sniffFile(), S_IRUSR|S_IWUSR|S_IRGRP);
-    cerr << APPNAME << "writing packets into " << config->sniffFile() << endl;
+    cout << APPNAME << "writing packets into " << config->sniffFile() << endl;
     fflush(stderr);
     loggingString( "capturing from interface:", config->interface() );
     loggingString( "writing packets into file:", config->sniffFile() );
@@ -193,7 +193,7 @@
        p = NULL;
        if ((selRet < 0) && (errno != EINTR))
        {
-         cerr << "Unexpected error from select: " << strerror(errno) << endl;
+         cerr << APPNAME << "Unexpected error from select: " << strerror(errno) << \
endl;  fflush(stderr);
          break;
        }
@@ -208,8 +208,9 @@
       if ((p == NULL) && (errno != EINTR))
       {
         // errno == 100 : 'Network is down' --> occurs when the interface go down
-        cerr << endl << APPNAME << "an error occurred: " << errno << " : " << \
                strerror(errno) << endl;
-        cerr << APPNAME << "Quitting..." << endl;
+        //cerr << endl << APPNAME << "an error occurred: " << errno << ": " << \
strerror(errno) << endl; +        cerr << APPNAME << "an error occurred. Code " << \
errno << ": " << strerror(errno) << endl; +        cout << APPNAME << "Quitting..." \
<< endl;  fflush(stderr);
         m_returnValue = SNIFF_NETWORK_ERROR;
         m_canSniff = false;
@@ -247,7 +248,7 @@
         case STOP_AFTER_X_SECONDS:
           if (rawtime - startTime > limit)
           {
-            cerr << APPNAME << "Ok capturing time's ended..." << endl;
+            cout << APPNAME << "Ok capturing time's ended..." << endl;
             fflush(stderr);
             m_canSniff = false;
           }
@@ -272,7 +273,7 @@
         setHeaderData(m_pcapfp, frameType, frameLength);
         if (frameLength < 0)
         {
-          cerr << APPNAME << "unknown packet" << endl;
+          cout << APPNAME << "unknown packet" << endl;
           fflush(stderr);
           continue;
         }
@@ -289,20 +290,20 @@
   pcap_dump_close(m_pdump);
 
   loggingInt( "total captured packets:", m_countPackets );
-  cerr << APPNAME << "Thread stopped. Got " << m_countPackets << " packets" << endl;
+  cout << APPNAME << "Thread stopped. Got " << m_countPackets << " packets" << endl;
   fflush(stderr);
-  cerr << endl << APPNAME << "total captured packets: " << m_countPackets << endl;
+  cout << endl << APPNAME << "total captured packets: " << m_countPackets << endl;
   fflush(stderr);
   if (m_countPackets == 0)
   {
     loggingInt( "total captured packets size:", 0 );
-    cerr << APPNAME << "total captured packets size: 0" << endl;
+    cout << APPNAME << "total captured packets size: 0" << endl;
     fflush(stderr);
   }
   else
   {
     loggingInt( "total captured packets size:",  packetsSize);
-    cerr << APPNAME << "total captured packets size: " << packetsSize << endl;
+    cout << APPNAME << "total captured packets size: " << packetsSize << endl;
     fflush(stderr);
   }
 }
@@ -354,14 +355,14 @@
   if (!m_bPauseSniffing)
   {
     m_bPauseSniffing = true;
-    cerr << APPNAME << "Thread paused." << endl;
+    cout << APPNAME << "Thread paused." << endl;
     fflush(stderr);
     logging( "paused sniffing..." );
   }
   else
   {
     m_bPauseSniffing = false;
-    cerr << APPNAME << "Thread resumed." << endl;
+    cout << APPNAME << "Thread resumed." << endl;
     fflush(stderr);
     logging( "resumed sniffing..." );
   }
@@ -380,12 +381,12 @@
 
       if (pcap_findalldevs(&alldevs, errbuf) == 0)
       {
-        cerr << APPNAME << "found capturable devices:" << endl;
+        cout << APPNAME << "found capturable devices:" << endl;
         fflush(stderr);
       }
       else
       {
-        cerr << APPNAME << "errbuf: '" << errbuf << "'" << endl;
+        cout << APPNAME << "errbuf: '" << errbuf << "'" << endl;
         fflush(stderr);
         m_returnValue = SNIFF_NO_SNIFFING_DEVICE_FOUND;
         return m_returnValue;
@@ -394,60 +395,60 @@
       // Print the list
       for(d=alldevs; d; d=d->next)
       {
-        cerr << APPNAME << " " << d->name;
+        cout << APPNAME << " " << d->name;
         if (d->description)
-          cerr << " (" << d->description << ")" << endl;
+          cout << " (" << d->description << ")" << endl;
         else
-          cerr << " (No description available)" << endl;
+          cout << " (No description available)" << endl;
       }
 
 /*      while (alldevs)
       {
-        cerr << APPNAME << "****************************************" << endl;
-        cerr << APPNAME << "interface: " << alldevs->name << endl;
+        cout << APPNAME << "****************************************" << endl;
+        cout << APPNAME << "interface: " << alldevs->name << endl;
         if (alldevs->description != NULL)
-          cerr << APPNAME << "description: " << alldevs->description << endl;
+          cout << APPNAME << "description: " << alldevs->description << endl;
         else
-          cerr << APPNAME << "no description available" << endl;
+          cout << APPNAME << "no description available" << endl;
         if (alldevs->addresses != NULL)
         {
-          cerr << APPNAME << "addresses not NULL" << endl;
+          cout << APPNAME << "addresses not NULL" << endl;
           if (alldevs->addresses->addr != NULL)
             switch (alldevs->addresses->addr->sa_family)
             {
               case AF_INET:
-                cerr << APPNAME << "I'm AF_INET" << endl;
+                cout << APPNAME << "I'm AF_INET" << endl;
                 ai = (struct sockaddr_in *)alldevs->addresses->addr;
-                cerr << inet_ntoa(ai->sin_addr) << ":" << ai->sin_addr.s_addr << \
endl; +                cout << inet_ntoa(ai->sin_addr) << ":" << ai->sin_addr.s_addr \
<< endl;  break;
             }
           else
-            cerr << APPNAME << "addr is NULL" << endl;
+            cout << APPNAME << "addr is NULL" << endl;
           if (alldevs->addresses->netmask != NULL)
             switch (alldevs->addresses->addr->sa_family)
             {
               case AF_INET:
-                cerr << APPNAME << "I'm AF_INET" << endl;
+                cout << APPNAME << "I'm AF_INET" << endl;
                 ai = (struct sockaddr_in *)alldevs->addresses->netmask;
-                cerr << inet_ntoa(ai->sin_addr) << ":" << ai->sin_addr.s_addr << \
endl; +                cout << inet_ntoa(ai->sin_addr) << ":" << ai->sin_addr.s_addr \
<< endl;  break;
             }
           else
-            cerr << APPNAME << "netmask is NULL" << endl;
+            cout << APPNAME << "netmask is NULL" << endl;
           if (alldevs->addresses->broadaddr != NULL)
             switch (alldevs->addresses->addr->sa_family)
             {
               case AF_INET:
-                cerr << APPNAME << "I'm AF_INET" << endl;
+                cout << APPNAME << "I'm AF_INET" << endl;
                 ai = (struct sockaddr_in *)alldevs->addresses->broadaddr;
-                cerr << inet_ntoa(ai->sin_addr) << ":" << ai->sin_addr.s_addr << \
endl; +                cout << inet_ntoa(ai->sin_addr) << ":" << ai->sin_addr.s_addr \
<< endl;  break;
             }
           else
-            cerr << APPNAME << "broadaddr is NULL" << endl;
+            cout << APPNAME << "broadaddr is NULL" << endl;
         }
         alldevs = alldevs->next;
-        cerr << endl;
+        cout << endl;
         fflush(stderr);
       }*/
       pcap_freealldevs(alldevs);
@@ -486,7 +487,7 @@
   else
     cerr << APPNAME << "Usage:" << endl << "'ksniff xml-config-file' OR 'ksniff \
devs'" << endl << endl;  
-  cerr << APPNAME << "Quitting with error code: " << m_returnValue << endl;
+  cout << APPNAME << "Quitting with error code: " << m_returnValue << endl;
   fflush(stderr);
 
   return m_returnValue;
--- trunk/playground/network/ksniffer/ksniffer.cpp #870436:870437
@@ -899,7 +899,8 @@
     {
       if (m_sniffProcess->exitStatus() == SNIFF_NETWORK_ERROR)
       {
-        KMessageBox::error( this, i18n("<p>A network error occurred.<br>Cannot \
continue capturing packets.</p>")); +        KMessageBox::error( this, i18n("<p>A \
network error occurred.<br>Cannot continue capturing packets.</p>") + +               \
QString("<p><b>%1</b></p>").arg(m_sniffProcessErrorText) );  }
     }
   }
@@ -1004,6 +1005,14 @@
 }
 
 
+void KSniffer::processError(KProcess *proc, char *buffer, int buflen)
+{
+  Q_UNUSED(proc);
+  buffer[buflen-1] = '\0';
+  m_sniffProcessErrorText += QString(buffer);
+}
+
+
 void KSniffer::stopSniffing()
 {
   if (m_loadFromFile)
@@ -1511,6 +1520,7 @@
   *m_sniffProcess << "ksniff";
   *m_sniffProcess << m_options->tmpFileConfigPath();
   connect(m_sniffProcess, SIGNAL(processExited(KProcess *)), this, \
SLOT(slotStop())); +  connect(m_sniffProcess, SIGNAL(receivedStderr(KProcess *, char \
*, int)), this, SLOT(processError(KProcess *, char *, int)));  \
m_sniffProcess->start(KProcess::NotifyOnExit, KProcess::All);  
   // we are going to sniff, so we can't wait stopping now
--- trunk/playground/network/ksniffer/ksniffer.h #870436:870437
@@ -120,6 +120,7 @@
   void slotPrint();
   void slotPauseContinue();
   void slotStop();
+  void processError(KProcess *proc, char *buffer, int buflen);
   void slotQuit();
 
   /**
@@ -220,6 +221,11 @@
   KProcess *m_sniffProcess;    // the suid process to sniff packets on file
 
   /**
+   * The string error reported by a network failure in ksniff application
+   */
+  QString m_sniffProcessErrorText;
+
+  /**
    * is the current selected interface assigned by the combobox
    */
   QString m_currentInterfaceText;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic