0001-add-configure-check-for-non-POSIX-compliant-getnameinfo-signature.patch 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. From 07c15a02f6890f56aa0b9341c27fc889956ab114 Mon Sep 17 00:00:00 2001
  2. From: rofl0r <rofl0r@users.noreply.github.com>
  3. Date: Tue, 25 Jan 2022 14:51:27 +0000
  4. Subject: [PATCH] add configure check for non-POSIX compliant getnameinfo
  5. signature
  6. - glibc < 2.14 uses "unsigned" instead of "int" for flags
  7. - openbsd and freebsd use "size_t" instead of socklen_t for servlen
  8. and nodelen, while still using socklen_t for salen.
  9. closes #430
  10. [Retrieved from:
  11. https://github.com/rofl0r/proxychains-ng/commit/07c15a02f6890f56aa0b9341c27fc889956ab114]
  12. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  13. ---
  14. configure | 16 ++++++++++++++++
  15. src/core.h | 2 +-
  16. src/libproxychains.c | 4 ++--
  17. 3 files changed, 19 insertions(+), 3 deletions(-)
  18. diff --git a/configure b/configure
  19. index 4c8bcbc..0102eb2 100755
  20. --- a/configure
  21. +++ b/configure
  22. @@ -175,6 +175,22 @@ ishaiku() {
  23. check_compile 'whether C compiler works' '' 'int main() {return 0;}' || fail 'error: install a C compiler and library'
  24. +if ! check_compile 'whether getnameinfo() servlen argument is POSIX compliant (socklen_t)' "-DGN_NODELEN_T=socklen_t -DGN_SERVLEN_T=socklen_t -DGN_FLAGS_T=int" \
  25. +'#define _GNU_SOURCE\n#include <netdb.h>\nint getnameinfo(const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, int);int main() {\nreturn 0;}' ; then
  26. + # GLIBC < 2.14
  27. + if ! check_compile 'whether getnameinfo() flags argument is unsigned' "-DGN_NODELEN_T=socklen_t -DGN_SERVLEN_T=socklen_t -DGN_FLAGS_T=unsigned" \
  28. + '#define _GNU_SOURCE\n#include <netdb.h>\nint getnameinfo(const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, unsigned);int main() {\nreturn 0;}' ; then
  29. + if ! check_compile 'whether getnameinfo() servlen argument is size_t' "-DGN_NODELEN_T=socklen_t -DGN_SERVLEN_T=size_t -DGN_FLAGS_T=int" \
  30. + '#define _GNU_SOURCE\n#include <netdb.h>\nint getnameinfo(const struct sockaddr *, socklen_t, char *, socklen_t, char *, size_t, int);int main() {\nreturn 0;}' ; then
  31. + # OpenBSD & FreeBSD
  32. + if ! check_compile 'whether getnameinfo() servlen and nodelen argument is size_t' "-DGN_NODELEN_T=size_t -DGN_SERVLEN_T=size_t -DGN_FLAGS_T=int" \
  33. + '#define _GNU_SOURCE\n#include <netdb.h>\nint getnameinfo(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int);int main() {\nreturn 0;}' ; then
  34. + fail "failed to detect getnameinfo signature"
  35. + fi
  36. + fi
  37. + fi
  38. +fi
  39. +
  40. check_compile 'whether we have GNU-style getservbyname_r()' "-DHAVE_GNU_GETSERVBYNAME_R" \
  41. '#define _GNU_SOURCE\n#include <netdb.h>\nint main() {\nstruct servent *se = 0;struct servent se_buf;char buf[1024];\ngetservbyname_r("foo", (void*) 0, &se_buf, buf, sizeof(buf), &se);\nreturn 0;}'
  42. diff --git a/src/core.h b/src/core.h
  43. index 31f3003..3045b86 100644
  44. --- a/src/core.h
  45. +++ b/src/core.h
  46. @@ -109,7 +109,7 @@ typedef int (*getaddrinfo_t)(const char *, const char *, const struct addrinfo *
  47. struct addrinfo **);
  48. typedef int (*getnameinfo_t) (const struct sockaddr *, socklen_t, char *,
  49. - socklen_t, char *, socklen_t, int);
  50. + GN_NODELEN_T, char *, GN_SERVLEN_T, GN_FLAGS_T);
  51. typedef ssize_t (*sendto_t) (int sockfd, const void *buf, size_t len, int flags,
  52. const struct sockaddr *dest_addr, socklen_t addrlen);
  53. diff --git a/src/libproxychains.c b/src/libproxychains.c
  54. index 001ffcd..578ff84 100644
  55. --- a/src/libproxychains.c
  56. +++ b/src/libproxychains.c
  57. @@ -729,8 +729,8 @@ HOOKFUNC(void, freeaddrinfo, struct addrinfo *res) {
  58. }
  59. HOOKFUNC(int, getnameinfo, const struct sockaddr *sa, socklen_t salen,
  60. - char *host, socklen_t hostlen, char *serv,
  61. - socklen_t servlen, int flags)
  62. + char *host, GN_NODELEN_T hostlen, char *serv,
  63. + GN_SERVLEN_T servlen, GN_FLAGS_T flags)
  64. {
  65. INIT();
  66. PFUNC();