summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-05-03 14:57:34 +0300
committerimarom <imarom@cisco.com>2016-05-09 16:48:14 +0300
commit8691f4019dc2123c1aa7413cf3666138756c2f66 (patch)
tree4b09f137d266471b51a4e5270e8d113806c97c93 /src/common
parent64847bb6d182c73f7489a821ea5724687dab1bc1 (diff)
first remote PCAP push - draft
Diffstat (limited to 'src/common')
-rwxr-xr-xsrc/common/captureFile.cpp16
-rwxr-xr-xsrc/common/captureFile.h6
2 files changed, 10 insertions, 12 deletions
diff --git a/src/common/captureFile.cpp b/src/common/captureFile.cpp
index e73c37ad..4c50bcb2 100755
--- a/src/common/captureFile.cpp
+++ b/src/common/captureFile.cpp
@@ -244,28 +244,23 @@ bool CErfCmp::compare(std::string f1, std::string f2 ){
return (res);
}
-
-
/**
* try to create type by type
* @param name
*
* @return CCapReaderBase*
*/
-CCapReaderBase * CCapReaderFactory::CreateReader(char * name, int loops)
+CCapReaderBase * CCapReaderFactory::CreateReader(char * name, int loops, std::ostream &err)
{
- if (name == NULL) {
- printf("Got null file name\n");
- return NULL;
- }
+ assert(name);
/* make sure we have a file */
FILE * f = CAP_FOPEN_64(name, "rb");
if (f == NULL) {
if (errno == ENOENT) {
- printf("\nERROR: Cap file not found %s\n\n",name);
+ err << "CAP file '" << name << "' not found";
} else {
- printf("\nERROR: Failed to open cap file '%s' with errno %d\n\n", name, errno);
+ err << "failed to open CAP file '" << name << "' with errno " << errno;
}
return NULL;
}
@@ -281,8 +276,7 @@ CCapReaderBase * CCapReaderFactory::CreateReader(char * name, int loops)
delete next;
}
- printf("\nERROR: file %s format not supported",name);
- printf("\nERROR: formats supported are LIBPCAP and ERF. other formats are deprecated\n\n");
+ err << "unsupported CAP format (not PCAP or ERF): " << name << "\n";
return NULL;
}
diff --git a/src/common/captureFile.h b/src/common/captureFile.h
index 3be83432..32b98272 100755
--- a/src/common/captureFile.h
+++ b/src/common/captureFile.h
@@ -24,6 +24,8 @@ limitations under the License.
#include <math.h>
#include <stdlib.h>
#include <string>
+#include <iostream>
+
#ifdef WIN32
#pragma warning(disable:4786)
#endif
@@ -201,11 +203,13 @@ public:
* @param name - cature file name
* @param loops - number of loops for the same capture. use 0
* for one time transmition
+ * @param err - IO stream to print error
+ *
* @return CCapReaderBase* - pointer to new instance (allocated
* by the function). the user should release the
* instance once it has no use any more.
*/
- static CCapReaderBase * CreateReader(char * name, int loops = 0);
+ static CCapReaderBase * CreateReader(char * name, int loops = 0, std::ostream &err = std::cout);
private: