logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0026-nc-Portability-fixes-from-libressl-portable.patch (5335B)


  1. From 05fd24cc7b3f1b73a58d41d70ef725925007165c Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Mon, 2 Dec 2019 21:11:04 -0800
  4. Subject: [PATCH] nc: Portability fixes from libressl-portable
  5. ---
  6. usr.bin/nc/netcat.c | 55 +++++++++++++++++++++++++++++++++++++++------
  7. 1 file changed, 48 insertions(+), 7 deletions(-)
  8. diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
  9. index 8c60fd18826..b5129c2204d 100644
  10. --- a/usr.bin/nc/netcat.c
  11. +++ b/usr.bin/nc/netcat.c
  12. @@ -93,9 +93,13 @@ int zflag; /* Port Scan Flag */
  13. int Dflag; /* sodebug */
  14. int Iflag; /* TCP receive buffer size */
  15. int Oflag; /* TCP send buffer size */
  16. +#ifdef TCP_MD5SIG
  17. int Sflag; /* TCP MD5 signature option */
  18. +#endif
  19. int Tflag = -1; /* IP Type of Service */
  20. +#ifdef SO_RTABLE
  21. int rtableid = -1;
  22. +#endif
  23. int usetls; /* use TLS */
  24. const char *Cflag; /* Public cert file */
  25. @@ -268,12 +272,14 @@ main(int argc, char *argv[])
  26. case 'u':
  27. uflag = 1;
  28. break;
  29. +#ifdef SO_RTABLE
  30. case 'V':
  31. rtableid = (int)strtonum(optarg, 0,
  32. RT_TABLEID_MAX, &errstr);
  33. if (errstr)
  34. errx(1, "rtable %s: %s", errstr, optarg);
  35. break;
  36. +#endif
  37. case 'v':
  38. vflag = 1;
  39. break;
  40. @@ -320,9 +326,11 @@ main(int argc, char *argv[])
  41. case 'o':
  42. oflag = optarg;
  43. break;
  44. +#ifdef TCP_MD5SIG
  45. case 'S':
  46. Sflag = 1;
  47. break;
  48. +#endif
  49. case 'T':
  50. errstr = NULL;
  51. errno = 0;
  52. @@ -346,9 +354,11 @@ main(int argc, char *argv[])
  53. argc -= optind;
  54. argv += optind;
  55. +#ifdef SO_RTABLE
  56. if (rtableid >= 0)
  57. if (setrtable(rtableid) == -1)
  58. err(1, "setrtable");
  59. +#endif
  60. /* Cruft to make sure options are clean, and used properly. */
  61. if (argc == 1 && family == AF_UNIX) {
  62. @@ -923,7 +933,10 @@ remote_connect(const char *host, const char *port, struct addrinfo hints,
  63. char *ipaddr)
  64. {
  65. struct addrinfo *res, *res0;
  66. - int s = -1, error, herr, on = 1, save_errno;
  67. + int s = -1, error, herr, save_errno;
  68. +#ifdef SO_BINDANY
  69. + int on = 1;
  70. +#endif
  71. if ((error = getaddrinfo(host, port, &hints, &res0)))
  72. errx(1, "getaddrinfo for host \"%s\" port %s: %s", host,
  73. @@ -938,8 +951,10 @@ remote_connect(const char *host, const char *port, struct addrinfo hints,
  74. if (sflag || pflag) {
  75. struct addrinfo ahints, *ares;
  76. +#ifdef SO_BINDANY
  77. /* try SO_BINDANY, but don't insist */
  78. setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on));
  79. +#endif
  80. memset(&ahints, 0, sizeof(struct addrinfo));
  81. ahints.ai_family = res->ai_family;
  82. ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
  83. @@ -1031,8 +1046,11 @@ int
  84. local_listen(const char *host, const char *port, struct addrinfo hints)
  85. {
  86. struct addrinfo *res, *res0;
  87. - int s = -1, ret, x = 1, save_errno;
  88. + int s = -1, save_errno;
  89. int error;
  90. +#ifdef SO_REUSEPORT
  91. + int ret, x = 1;
  92. +#endif
  93. /* Allow nodename to be null. */
  94. hints.ai_flags |= AI_PASSIVE;
  95. @@ -1052,9 +1070,11 @@ local_listen(const char *host, const char *port, struct addrinfo hints)
  96. res->ai_protocol)) == -1)
  97. continue;
  98. +#ifdef SO_REUSEPORT
  99. ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
  100. if (ret == -1)
  101. err(1, NULL);
  102. +#endif
  103. set_common_sockopts(s, res->ai_family);
  104. @@ -1559,11 +1579,13 @@ set_common_sockopts(int s, int af)
  105. {
  106. int x = 1;
  107. +#ifdef TCP_MD5SIG
  108. if (Sflag) {
  109. if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
  110. &x, sizeof(x)) == -1)
  111. err(1, NULL);
  112. }
  113. +#endif
  114. if (Dflag) {
  115. if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
  116. &x, sizeof(x)) == -1)
  117. @@ -1574,9 +1596,16 @@ set_common_sockopts(int s, int af)
  118. IP_TOS, &Tflag, sizeof(Tflag)) == -1)
  119. err(1, "set IP ToS");
  120. +#ifdef IPV6_TCLASS
  121. else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
  122. IPV6_TCLASS, &Tflag, sizeof(Tflag)) == -1)
  123. err(1, "set IPv6 traffic class");
  124. +#else
  125. + else if (af == AF_INET6) {
  126. + errno = ENOPROTOOPT;
  127. + err(1, "set IPv6 traffic class not supported");
  128. + }
  129. +#endif
  130. }
  131. if (Iflag) {
  132. if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
  133. @@ -1600,13 +1629,17 @@ set_common_sockopts(int s, int af)
  134. }
  135. if (minttl != -1) {
  136. +#ifdef IP_MINTTL
  137. if (af == AF_INET && setsockopt(s, IPPROTO_IP,
  138. IP_MINTTL, &minttl, sizeof(minttl)))
  139. err(1, "set IP min TTL");
  140. +#endif
  141. - else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
  142. +#ifdef IPV6_MINHOPCOUNT
  143. + if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
  144. IPV6_MINHOPCOUNT, &minttl, sizeof(minttl)))
  145. err(1, "set IPv6 min hop count");
  146. +#endif
  147. }
  148. }
  149. @@ -1831,14 +1864,22 @@ help(void)
  150. \t-P proxyuser\tUsername for proxy authentication\n\
  151. \t-p port\t Specify local port for remote connects\n\
  152. \t-R CAfile CA bundle\n\
  153. - \t-r Randomize remote ports\n\
  154. - \t-S Enable the TCP MD5 signature option\n\
  155. + \t-r Randomize remote ports\n"
  156. +#ifdef TCP_MD5SIG
  157. + "\
  158. + \t-S Enable the TCP MD5 signature option\n"
  159. +#endif
  160. + "\
  161. \t-s sourceaddr Local source address\n\
  162. \t-T keyword TOS value or TLS options\n\
  163. \t-t Answer TELNET negotiation\n\
  164. \t-U Use UNIX domain socket\n\
  165. - \t-u UDP mode\n\
  166. - \t-V rtable Specify alternate routing table\n\
  167. + \t-u UDP mode\n"
  168. +#ifdef SO_RTABLE
  169. + "\
  170. + \t-V rtable Specify alternate routing table\n"
  171. +#endif
  172. + "\
  173. \t-v Verbose\n\
  174. \t-W recvlimit Terminate after receiving a number of packets\n\
  175. \t-w timeout Timeout for connects and final net reads\n\
  176. --
  177. 2.49.0