tcpdump01.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. # Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
  3. # Copyright (c) International Business Machines Corp., 2000
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License as
  7. # published by the Free Software Foundation; either version 2 of
  8. # the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it would be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write the Free Software Foundation,
  17. # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. #
  19. # PURPOSE: To test the basic functionality of `tcpdump`.
  20. #
  21. # HISTORY:
  22. # 04/17/01 Robbie Williamson (robbiew@us.ibm.com)
  23. # -Written
  24. TST_TOTAL=1
  25. TCID="tcpdump01"
  26. TST_CLEANUP=do_cleanup
  27. do_setup()
  28. {
  29. ping_cmd=ping$TST_IPV6
  30. tst_require_cmds tcpdump kill $ping_cmd
  31. outfile="tcpdump_out"
  32. numloops=20
  33. tst_tmpdir
  34. }
  35. do_test()
  36. {
  37. addr=$(tst_ipaddr rhost)
  38. tst_resm TINFO "start $ping_cmd in background"
  39. $ping_cmd -I $(tst_iface) -f $addr > /dev/null 2>&1 &
  40. ping_pid=$!
  41. tst_resm TINFO "running tcpdump..."
  42. tcpdump -n -i $(tst_iface) -c $numloops > $outfile 2>/dev/null
  43. [ $? -ne 0 ] && tst_brkm TBROK "problems trying to launch tcpdump"
  44. grep "$addr\>" $outfile > /dev/null 2>&1
  45. if [ $? -ne 0 ]; then
  46. tst_resm TFAIL "'$addr' was not listed in network traffic"
  47. return
  48. fi
  49. tst_resm TPASS "Test finished successfully"
  50. }
  51. do_cleanup()
  52. {
  53. kill $ping_pid > /dev/null 2>&1
  54. wait $ping_pid > /dev/null 2>&1
  55. tst_rmdir
  56. }
  57. TST_USE_LEGACY_API=1
  58. . tst_net.sh
  59. do_setup
  60. do_test
  61. tst_exit