mirror of
https://repo.or.cz/socat.git
synced 2024-12-22 23:42:34 +00:00
Removed dependency on gethostbyname()
This commit is contained in:
parent
2bd582713d
commit
a3c688210f
6 changed files with 35 additions and 33 deletions
4
CHANGES
4
CHANGES
|
@ -12,6 +12,10 @@ corrections:
|
||||||
cross compiling.
|
cross compiling.
|
||||||
Thanks to Max Freisinger from Gentoo for seinding a patch.
|
Thanks to Max Freisinger from Gentoo for seinding a patch.
|
||||||
|
|
||||||
|
Socat still depended on obsolete gethostbyname() function, thus
|
||||||
|
compiling with MUSL libc failed.
|
||||||
|
Problem reported by Kennedy33.
|
||||||
|
|
||||||
testing:
|
testing:
|
||||||
test.sh: Show a warning when phase-1 (insecure phase) of a security
|
test.sh: Show a warning when phase-1 (insecure phase) of a security
|
||||||
test fails
|
test fails
|
||||||
|
|
|
@ -99,6 +99,9 @@
|
||||||
/* Define if you have the nanosleep function. */
|
/* Define if you have the nanosleep function. */
|
||||||
#undef HAVE_NANOSLEEP
|
#undef HAVE_NANOSLEEP
|
||||||
|
|
||||||
|
/* Define if you have the gethostbyname function. */
|
||||||
|
#undef HAVE_GETHOSTBYNAME
|
||||||
|
|
||||||
/* Define if you have the getaddrinfo function. */
|
/* Define if you have the getaddrinfo function. */
|
||||||
#undef HAVE_GETADDRINFO
|
#undef HAVE_GETADDRINFO
|
||||||
|
|
||||||
|
|
|
@ -740,7 +740,7 @@ AC_FUNC_MEMCMP
|
||||||
AC_TYPE_SIGNAL
|
AC_TYPE_SIGNAL
|
||||||
AC_FUNC_STRFTIME
|
AC_FUNC_STRFTIME
|
||||||
AC_CHECK_FUNCS(putenv select poll socket strtod strtol)
|
AC_CHECK_FUNCS(putenv select poll socket strtod strtol)
|
||||||
AC_CHECK_FUNCS(strtoul uname getpgid getsid getaddrinfo)
|
AC_CHECK_FUNCS(strtoul uname getpgid getsid gethostbyname getaddrinfo)
|
||||||
AC_CHECK_FUNCS(setgroups inet_aton)
|
AC_CHECK_FUNCS(setgroups inet_aton)
|
||||||
AC_CHECK_FUNCS()
|
AC_CHECK_FUNCS()
|
||||||
|
|
||||||
|
|
4
sycls.c
4
sycls.c
|
@ -1364,7 +1364,7 @@ int Pause(void) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WITH_IP4 || WITH_IP6
|
#if ( _WITH_IP4 || _WITH_IP6 ) && HAVE_GETHOSTBYNAME
|
||||||
struct hostent *Gethostbyname(const char *name) {
|
struct hostent *Gethostbyname(const char *name) {
|
||||||
struct hostent *hent;
|
struct hostent *hent;
|
||||||
Debug1("gethostbyname(\"%s\")", name);
|
Debug1("gethostbyname(\"%s\")", name);
|
||||||
|
@ -1380,7 +1380,7 @@ struct hostent *Gethostbyname(const char *name) {
|
||||||
}
|
}
|
||||||
return hent;
|
return hent;
|
||||||
}
|
}
|
||||||
#endif /* WITH_IP4 || WITH_IP6 */
|
#endif /* ( _WITH_IP4 || _WITH_IP6 ) && HAVE_GETHOSTBYNAME */
|
||||||
|
|
||||||
#if (_WITH_IP4 || _WITH_IP6) && HAVE_GETADDRINFO
|
#if (_WITH_IP4 || _WITH_IP6) && HAVE_GETADDRINFO
|
||||||
int Getaddrinfo(const char *node, const char *service,
|
int Getaddrinfo(const char *node, const char *service,
|
||||||
|
|
30
xio-ip4.c
30
xio-ip4.c
|
@ -15,12 +15,14 @@
|
||||||
|
|
||||||
|
|
||||||
int xioparsenetwork_ip4(const char *rangename, struct xiorange *range) {
|
int xioparsenetwork_ip4(const char *rangename, struct xiorange *range) {
|
||||||
struct hostent *maskaddr;
|
|
||||||
struct in_addr *netaddr_in = &range->netaddr.ip4.sin_addr;
|
struct in_addr *netaddr_in = &range->netaddr.ip4.sin_addr;
|
||||||
struct in_addr *netmask_in = &range->netmask.ip4.sin_addr;
|
struct in_addr *netmask_in = &range->netmask.ip4.sin_addr;
|
||||||
char *rangename1; /* a copy of rangename with writing allowed */
|
char *rangename1; /* a copy of rangename with writing allowed */
|
||||||
char *delimpos; /* absolute address of delimiter */
|
char *delimpos; /* absolute address of delimiter */
|
||||||
unsigned int bits; /* netmask bits */
|
unsigned int bits; /* netmask bits */
|
||||||
|
union sockaddr_union sau;
|
||||||
|
socklen_t socklen = sizeof(sau);
|
||||||
|
int rc;
|
||||||
|
|
||||||
if ((rangename1 = strdup(rangename)) == NULL) {
|
if ((rangename1 = strdup(rangename)) == NULL) {
|
||||||
Error1("strdup(\"%s\"): out of memory", rangename);
|
Error1("strdup(\"%s\"): out of memory", rangename);
|
||||||
|
@ -43,31 +45,25 @@ int xioparsenetwork_ip4(const char *rangename, struct xiorange *range) {
|
||||||
netmask_in->s_addr = htonl((0xffffffff << (32-bits)));
|
netmask_in->s_addr = htonl((0xffffffff << (32-bits)));
|
||||||
}
|
}
|
||||||
} else if (delimpos = strchr(rangename1, ':')) {
|
} else if (delimpos = strchr(rangename1, ':')) {
|
||||||
if ((maskaddr = Gethostbyname(delimpos+1)) == NULL) {
|
if ((rc = xiogetaddrinfo(delimpos+1, NULL, PF_UNSPEC, 0, 0,
|
||||||
/* note: cast is req on AIX: */
|
&sau, &socklen, 0, 0))
|
||||||
Error2("gethostbyname(\"%s\"): %s", delimpos+1,
|
!= STAT_OK) {
|
||||||
h_errno == NETDB_INTERNAL ? strerror(errno) :
|
return rc;
|
||||||
(char *)hstrerror(h_errno));
|
|
||||||
return STAT_NORETRY;
|
|
||||||
}
|
}
|
||||||
netmask_in->s_addr = *(uint32_t *)maskaddr->h_addr_list[0];
|
netmask_in->s_addr = sau.ip4.sin_addr.s_addr;
|
||||||
} else {
|
} else {
|
||||||
Error1("xioparsenetwork_ip4(\"%s\",,): missing netmask delimiter", rangename);
|
Error1("xioparsenetwork_ip4(\"%s\",,): missing netmask delimiter", rangename);
|
||||||
free(rangename1);
|
free(rangename1);
|
||||||
return STAT_NORETRY;
|
return STAT_NORETRY;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
struct hostent *nameaddr;
|
|
||||||
*delimpos = 0;
|
*delimpos = 0;
|
||||||
if ((nameaddr = Gethostbyname(rangename1)) == NULL) {
|
if ((rc = xiogetaddrinfo(rangename1, NULL, PF_UNSPEC, 0, 0,
|
||||||
/* note: cast is req on AIX: */
|
&sau, &socklen, 0, 0))
|
||||||
Error2("gethostbyname(\"%s\"): %s", rangename1,
|
!= STAT_OK) {
|
||||||
h_errno == NETDB_INTERNAL ? strerror(errno) :
|
return rc;
|
||||||
(char *)hstrerror(h_errno));
|
|
||||||
free(rangename1);
|
|
||||||
return STAT_NORETRY;
|
|
||||||
}
|
}
|
||||||
netaddr_in->s_addr = *(uint32_t *)nameaddr->h_addr_list[0];
|
netaddr_in->s_addr = sau.ip4.sin_addr.s_addr;
|
||||||
}
|
}
|
||||||
free(rangename1);
|
free(rangename1);
|
||||||
return STAT_OK;
|
return STAT_OK;
|
||||||
|
|
25
xio-proxy.c
25
xio-proxy.c
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "xioopen.h"
|
#include "xioopen.h"
|
||||||
#include "xio-socket.h"
|
#include "xio-socket.h"
|
||||||
|
#include "xio-ip.h"
|
||||||
#include "xio-ipapp.h"
|
#include "xio-ipapp.h"
|
||||||
#include "xio-ascii.h" /* for base64 encoding of authentication */
|
#include "xio-ascii.h" /* for base64 encoding of authentication */
|
||||||
|
|
||||||
|
@ -231,7 +232,9 @@ static int xioopen_proxy_connect(int argc, const char *argv[], struct opt *opts,
|
||||||
|
|
||||||
int _xioopen_proxy_prepare(struct proxyvars *proxyvars, struct opt *opts,
|
int _xioopen_proxy_prepare(struct proxyvars *proxyvars, struct opt *opts,
|
||||||
const char *targetname, const char *targetport) {
|
const char *targetname, const char *targetport) {
|
||||||
struct hostent *host;
|
union sockaddr_union host;
|
||||||
|
socklen_t socklen = sizeof(host);
|
||||||
|
int rc;
|
||||||
|
|
||||||
retropt_bool(opts, OPT_IGNORECR, &proxyvars->ignorecr);
|
retropt_bool(opts, OPT_IGNORECR, &proxyvars->ignorecr);
|
||||||
retropt_bool(opts, OPT_PROXY_RESOLVE, &proxyvars->doresolve);
|
retropt_bool(opts, OPT_PROXY_RESOLVE, &proxyvars->doresolve);
|
||||||
|
@ -241,14 +244,10 @@ int _xioopen_proxy_prepare(struct proxyvars *proxyvars, struct opt *opts,
|
||||||
/* currently we only resolve to IPv4 addresses. This is in accordance to
|
/* currently we only resolve to IPv4 addresses. This is in accordance to
|
||||||
RFC 2396; however once it becomes clear how IPv6 addresses should be
|
RFC 2396; however once it becomes clear how IPv6 addresses should be
|
||||||
represented in CONNECT commands this code might be extended */
|
represented in CONNECT commands this code might be extended */
|
||||||
host = Gethostbyname(targetname);
|
rc = xiogetaddrinfo(targetname, targetport, PF_UNSPEC,
|
||||||
if (host == NULL) {
|
SOCK_STREAM, IPPROTO_TCP,
|
||||||
int level = E_WARN;
|
&host, &socklen, 0, 0);
|
||||||
/* note: cast is req on AIX: */
|
if (rc != STAT_OK) {
|
||||||
Msg2(level, "gethostbyname(\"%s\"): %s", targetname,
|
|
||||||
h_errno == NETDB_INTERNAL ? strerror(errno) :
|
|
||||||
(char *)hstrerror(h_errno)/*0 h_messages[h_errno-1]*/);
|
|
||||||
|
|
||||||
proxyvars->targetaddr = strdup(targetname);
|
proxyvars->targetaddr = strdup(targetname);
|
||||||
} else {
|
} else {
|
||||||
#define LEN 16 /* www.xxx.yyy.zzz\0 */
|
#define LEN 16 /* www.xxx.yyy.zzz\0 */
|
||||||
|
@ -256,10 +255,10 @@ int _xioopen_proxy_prepare(struct proxyvars *proxyvars, struct opt *opts,
|
||||||
return STAT_RETRYLATER;
|
return STAT_RETRYLATER;
|
||||||
}
|
}
|
||||||
snprintf(proxyvars->targetaddr, LEN, "%u.%u.%u.%u",
|
snprintf(proxyvars->targetaddr, LEN, "%u.%u.%u.%u",
|
||||||
(unsigned char)host->h_addr_list[0][0],
|
((unsigned char *)&host.ip4.sin_addr.s_addr)[0],
|
||||||
(unsigned char)host->h_addr_list[0][1],
|
((unsigned char *)&host.ip4.sin_addr.s_addr)[1],
|
||||||
(unsigned char)host->h_addr_list[0][2],
|
((unsigned char *)&host.ip4.sin_addr.s_addr)[2],
|
||||||
(unsigned char)host->h_addr_list[0][3]);
|
((unsigned char *)&host.ip4.sin_addr.s_addr)[3]);
|
||||||
#undef LEN
|
#undef LEN
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue