diff options
Diffstat (limited to 'src/common')
-rwxr-xr-x | src/common/captureFile.cpp | 16 | ||||
-rwxr-xr-x | src/common/captureFile.h | 6 |
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: |