udp-scan-timeout.patch 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. Index: netcat-openbsd-1.89/netcat.c
  2. ===================================================================
  3. --- netcat-openbsd-1.89.orig/netcat.c 2008-01-22 16:17:30.000000000 -0500
  4. +++ netcat-openbsd-1.89/netcat.c 2008-01-22 16:17:34.000000000 -0500
  5. @@ -69,6 +69,8 @@
  6. #define CONNECTION_FAILED 1
  7. #define CONNECTION_TIMEOUT 2
  8. +#define UDP_SCAN_TIMEOUT 3 /* Seconds */
  9. +
  10. /* Command Line Options */
  11. int dflag; /* detached, no stdin */
  12. int iflag; /* Interval Flag */
  13. @@ -376,7 +378,7 @@
  14. continue;
  15. ret = 0;
  16. - if (vflag) {
  17. + if (vflag && !uflag) {
  18. /* For UDP, make sure we are connected. */
  19. if (uflag) {
  20. if (udptest(s) == -1) {
  21. @@ -841,15 +843,20 @@
  22. int
  23. udptest(int s)
  24. {
  25. - int i, ret;
  26. + int i, t;
  27. - for (i = 0; i <= 3; i++) {
  28. - if (write(s, "X", 1) == 1)
  29. - ret = 1;
  30. - else
  31. - ret = -1;
  32. + if ((write(s, "X", 1) != 1) ||
  33. + ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED)))
  34. + return -1;
  35. +
  36. + /* Give the remote host some time to reply. */
  37. + for (i = 0, t = (timeout == -1) ? UDP_SCAN_TIMEOUT : (timeout / 1000);
  38. + i < t; i++) {
  39. + sleep(1);
  40. + if ((write(s, "X", 1) != 1) && (errno == ECONNREFUSED))
  41. + return -1;
  42. }
  43. - return (ret);
  44. + return 1;
  45. }
  46. void