X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=test%2Fblackbox%2Fcommon%2Ftcpdump.c;h=f33412deae53730b5e188fd4ba0dd0dfd680532e;hb=8538d6c661a083774e5b54163eaf5cdbcadcda6d;hp=422c397ecbfd0278e8fddd082689cb31e698f881;hpb=2fd608c4111ef4d48a649401d918f5981856cc44;p=meshlink diff --git a/test/blackbox/common/tcpdump.c b/test/blackbox/common/tcpdump.c index 422c397e..f33412de 100644 --- a/test/blackbox/common/tcpdump.c +++ b/test/blackbox/common/tcpdump.c @@ -17,25 +17,28 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + #include #include #include #include #include +#include #include #include #include "common_handlers.h" #include "tcpdump.h" pid_t tcpdump_start(char *interface) { - pid_t tcpdump_pid; char *argv[] = { "tcpdump", "-i", interface, NULL }; // child process have a pipe to the parent process when parent process terminates SIGPIPE kills the tcpdump int pipes[2]; assert(pipe(pipes) != -1); PRINT_TEST_CASE_MSG("\x1b[32mLaunching TCP Dump ..\x1b[0m\n"); - if((tcpdump_pid = fork()) == 0) { + pid_t tcpdump_pid = fork(); + + if(tcpdump_pid == 0) { prctl(PR_SET_PDEATHSIG, SIGHUP); close(pipes[1]); // Open log file for TCP Dump @@ -45,13 +48,14 @@ pid_t tcpdump_start(char *interface) { assert(dup2(fd, STDOUT_FILENO) != -1); // Launch TCPDump with port numbers of sleepy, gateway & relay - int ret = execvp("/usr/sbin/tcpdump", argv); + execvp("/usr/sbin/tcpdump", argv); perror("execvp "); - assert(ret != -1); + exit(1); } else { close(pipes[0]); - return tcpdump_pid; } + + return tcpdump_pid; } void tcpdump_stop(pid_t tcpdump_pid) {