mirror of
https://repo.or.cz/socat.git
synced 2024-12-22 15:32:35 +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.
|
||||
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:
|
||||
test.sh: Show a warning when phase-1 (insecure phase) of a security
|
||||
test fails
|
||||
|
|
|
@ -99,6 +99,9 @@
|
|||
/* Define if you have the nanosleep function. */
|
||||
#undef HAVE_NANOSLEEP
|
||||
|
||||
/* Define if you have the gethostbyname function. */
|
||||
#undef HAVE_GETHOSTBYNAME
|
||||
|
||||
/* Define if you have the getaddrinfo function. */
|
||||
#undef HAVE_GETADDRINFO
|
||||
|
||||
|
|
|
@ -740,7 +740,7 @@ AC_FUNC_MEMCMP
|
|||
AC_TYPE_SIGNAL
|
||||
AC_FUNC_STRFTIME
|
||||
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()
|
||||
|
||||
|
|
4
sycls.c
4
sycls.c
|
@ -1364,7 +1364,7 @@ int Pause(void) {
|
|||
return retval;
|
||||
}
|
||||
|
||||
#if WITH_IP4 || WITH_IP6
|
||||
#if ( _WITH_IP4 || _WITH_IP6 ) && HAVE_GETHOSTBYNAME
|
||||
struct hostent *Gethostbyname(const char *name) {
|
||||
struct hostent *hent;
|
||||
Debug1("gethostbyname(\"%s\")", name);
|
||||
|
@ -1380,7 +1380,7 @@ struct hostent *Gethostbyname(const char *name) {
|
|||
}
|
||||
return hent;
|
||||
}
|
||||
#endif /* WITH_IP4 || WITH_IP6 */
|
||||
#endif /* ( _WITH_IP4 || _WITH_IP6 ) && HAVE_GETHOSTBYNAME */
|
||||
|
||||
#if (_WITH_IP4 || _WITH_IP6) && HAVE_GETADDRINFO
|
||||
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) {
|
||||
struct hostent *maskaddr;
|
||||
struct in_addr *netaddr_in = &range->netaddr.ip4.sin_addr;
|
||||
struct in_addr *netmask_in = &range->netmask.ip4.sin_addr;
|
||||
char *rangename1; /* a copy of rangename with writing allowed */
|
||||
char *delimpos; /* absolute address of delimiter */
|
||||
unsigned int bits; /* netmask bits */
|
||||
union sockaddr_union sau;
|
||||
socklen_t socklen = sizeof(sau);
|
||||
int rc;
|
||||
|
||||
if ((rangename1 = strdup(rangename)) == NULL) {
|
||||
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)));
|
||||
}
|
||||
} else if (delimpos = strchr(rangename1, ':')) {
|
||||
if ((maskaddr = Gethostbyname(delimpos+1)) == NULL) {
|
||||
/* note: cast is req on AIX: */
|
||||
Error2("gethostbyname(\"%s\"): %s", delimpos+1,
|
||||
h_errno == NETDB_INTERNAL ? strerror(errno) :
|
||||
(char *)hstrerror(h_errno));
|
||||
return STAT_NORETRY;
|
||||
if ((rc = xiogetaddrinfo(delimpos+1, NULL, PF_UNSPEC, 0, 0,
|
||||
&sau, &socklen, 0, 0))
|
||||
!= STAT_OK) {
|
||||
return rc;
|
||||
}
|
||||
netmask_in->s_addr = *(uint32_t *)maskaddr->h_addr_list[0];
|
||||
netmask_in->s_addr = sau.ip4.sin_addr.s_addr;
|
||||
} else {
|
||||
Error1("xioparsenetwork_ip4(\"%s\",,): missing netmask delimiter", rangename);
|
||||
free(rangename1);
|
||||
return STAT_NORETRY;
|
||||
}
|
||||
{
|
||||
struct hostent *nameaddr;
|
||||
*delimpos = 0;
|
||||
if ((nameaddr = Gethostbyname(rangename1)) == NULL) {
|
||||
/* note: cast is req on AIX: */
|
||||
Error2("gethostbyname(\"%s\"): %s", rangename1,
|
||||
h_errno == NETDB_INTERNAL ? strerror(errno) :
|
||||
(char *)hstrerror(h_errno));
|
||||
free(rangename1);
|
||||
return STAT_NORETRY;
|
||||
if ((rc = xiogetaddrinfo(rangename1, NULL, PF_UNSPEC, 0, 0,
|
||||
&sau, &socklen, 0, 0))
|
||||
!= STAT_OK) {
|
||||
return rc;
|
||||
}
|
||||
netaddr_in->s_addr = *(uint32_t *)nameaddr->h_addr_list[0];
|
||||
netaddr_in->s_addr = sau.ip4.sin_addr.s_addr;
|
||||
}
|
||||
free(rangename1);
|
||||
return STAT_OK;
|
||||
|
|
25
xio-proxy.c
25
xio-proxy.c
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "xioopen.h"
|
||||
#include "xio-socket.h"
|
||||
#include "xio-ip.h"
|
||||
#include "xio-ipapp.h"
|
||||
#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,
|
||||
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_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
|
||||
RFC 2396; however once it becomes clear how IPv6 addresses should be
|
||||
represented in CONNECT commands this code might be extended */
|
||||
host = Gethostbyname(targetname);
|
||||
if (host == NULL) {
|
||||
int level = E_WARN;
|
||||
/* note: cast is req on AIX: */
|
||||
Msg2(level, "gethostbyname(\"%s\"): %s", targetname,
|
||||
h_errno == NETDB_INTERNAL ? strerror(errno) :
|
||||
(char *)hstrerror(h_errno)/*0 h_messages[h_errno-1]*/);
|
||||
|
||||
rc = xiogetaddrinfo(targetname, targetport, PF_UNSPEC,
|
||||
SOCK_STREAM, IPPROTO_TCP,
|
||||
&host, &socklen, 0, 0);
|
||||
if (rc != STAT_OK) {
|
||||
proxyvars->targetaddr = strdup(targetname);
|
||||
} else {
|
||||
#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;
|
||||
}
|
||||
snprintf(proxyvars->targetaddr, LEN, "%u.%u.%u.%u",
|
||||
(unsigned char)host->h_addr_list[0][0],
|
||||
(unsigned char)host->h_addr_list[0][1],
|
||||
(unsigned char)host->h_addr_list[0][2],
|
||||
(unsigned char)host->h_addr_list[0][3]);
|
||||
((unsigned char *)&host.ip4.sin_addr.s_addr)[0],
|
||||
((unsigned char *)&host.ip4.sin_addr.s_addr)[1],
|
||||
((unsigned char *)&host.ip4.sin_addr.s_addr)[2],
|
||||
((unsigned char *)&host.ip4.sin_addr.s_addr)[3]);
|
||||
#undef LEN
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue