mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 21:23:03 +01:00
Fixed CORE-833.
This commit is contained in:
parent
49ebf1b20b
commit
a9348e5766
@ -289,7 +289,7 @@ static int fork(SOCKET, USHORT);
|
||||
#endif
|
||||
|
||||
static in_addr get_bind_address();
|
||||
static in_addr get_host_address(const TEXT *);
|
||||
static in_addr get_host_address(const Firebird::string&);
|
||||
|
||||
static void copy_p_cnct_repeat_array( p_cnct::p_cnct_repeat* pDest,
|
||||
const p_cnct::p_cnct_repeat* pSource,
|
||||
@ -666,35 +666,32 @@ rem_port* INET_connect(const TEXT* name,
|
||||
ISC_tcp_setup(ISC_wait, gds__completion_ast);
|
||||
#endif
|
||||
|
||||
const TEXT* protocol = NULL;
|
||||
TEXT temp[BUFFER_TINY];
|
||||
Firebird::string host;
|
||||
Firebird::string protocol;
|
||||
|
||||
if (name) {
|
||||
strncpy(temp, name, sizeof(temp));
|
||||
temp[sizeof(temp) - 1] = 0;
|
||||
for (TEXT* p = temp; *p;) {
|
||||
if (*p++ == '/') {
|
||||
p[-1] = 0;
|
||||
name = temp;
|
||||
protocol = p;
|
||||
break;
|
||||
}
|
||||
host = name;
|
||||
const size_t pos = host.find("/");
|
||||
if (pos != Firebird::string::npos) {
|
||||
protocol = host.substr(pos + 1);
|
||||
host = host.substr(0, pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (name && *name) {
|
||||
if (host.length()) {
|
||||
if (port->port_connection) {
|
||||
ALLR_free(port->port_connection);
|
||||
}
|
||||
port->port_connection = REMOTE_make_string(name);
|
||||
port->port_connection = REMOTE_make_string(host.c_str());
|
||||
}
|
||||
else {
|
||||
name = port->port_host->str_data;
|
||||
host = port->port_host->str_data;
|
||||
}
|
||||
|
||||
if (!protocol) {
|
||||
if (!protocol.length()) {
|
||||
const unsigned short port2 = Config::getRemoteServicePort();
|
||||
if (port2) {
|
||||
TEXT temp[BUFFER_TINY];
|
||||
// EKU: since temp is 128 byte long, the port number will always
|
||||
// fit into the buffer, hence snprintf replaced with sprintf
|
||||
sprintf(temp, "%hu", port2);
|
||||
@ -712,13 +709,13 @@ rem_port* INET_connect(const TEXT* name,
|
||||
|
||||
#ifdef VMS
|
||||
/* V M S */
|
||||
if (getservport(protocol, "tcp", &address.sin_port) == -1) {
|
||||
if (getservport(protocol.c_str(), "tcp", &address.sin_port) == -1) {
|
||||
inet_error(port, "getservbyname", isc_net_connect_err, 0);
|
||||
disconnect(port);
|
||||
return NULL;
|
||||
}
|
||||
if (packet) {
|
||||
if (getaddr(name, &address) == -1) {
|
||||
if (getaddr(host.c_str(), &address) == -1) {
|
||||
inet_error(port, "gethostbyname", isc_net_connect_err, 0);
|
||||
disconnect(port);
|
||||
return NULL;
|
||||
@ -739,13 +736,13 @@ rem_port* INET_connect(const TEXT* name,
|
||||
|
||||
if (packet) {
|
||||
// client connection
|
||||
host_addr = get_host_address(name);
|
||||
host_addr = get_host_address(host);
|
||||
|
||||
if (host_addr.s_addr == INADDR_NONE)
|
||||
{
|
||||
SNPRINTF(msg, FB_NELEM(msg),
|
||||
"INET/INET_connect: gethostbyname (%s) failed, error code = %d",
|
||||
name, H_ERRNO);
|
||||
host.c_str(), H_ERRNO);
|
||||
gds__log(msg, 0);
|
||||
inet_gen_error(port,
|
||||
isc_network_error,
|
||||
@ -769,7 +766,7 @@ rem_port* INET_connect(const TEXT* name,
|
||||
|
||||
THREAD_EXIT();
|
||||
|
||||
const struct servent* service = getservbyname(protocol, "tcp");
|
||||
const struct servent* service = getservbyname(protocol.c_str(), "tcp");
|
||||
#ifdef WIN_NT
|
||||
/* On Windows NT/9x, getservbyname can only accomodate
|
||||
* 1 call at a time. In this case it returns the error
|
||||
@ -780,7 +777,7 @@ rem_port* INET_connect(const TEXT* name,
|
||||
if (!service) {
|
||||
if (H_ERRNO == INET_RETRY_ERRNO) {
|
||||
for (int retry = 0; retry < INET_RETRY_CALL; retry++) {
|
||||
if ( (service = getservbyname(protocol, "tcp")) )
|
||||
if ( (service = getservbyname(protocol.c_str(), "tcp")) )
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -797,7 +794,7 @@ rem_port* INET_connect(const TEXT* name,
|
||||
for zero-installation clients.
|
||||
*/
|
||||
if (!service) {
|
||||
if (strcmp(protocol, FB_SERVICE_NAME) == 0) {
|
||||
if (protocol == FB_SERVICE_NAME) {
|
||||
/* apply hardwired translation */
|
||||
address.sin_port = htons(FB_SERVICE_PORT);
|
||||
}
|
||||
@ -808,7 +805,7 @@ rem_port* INET_connect(const TEXT* name,
|
||||
* let's see whether this is a port number
|
||||
* instead of a service name
|
||||
*/
|
||||
address.sin_port = htons(atoi(protocol));
|
||||
address.sin_port = htons(atoi(protocol.c_str()));
|
||||
}
|
||||
|
||||
if (address.sin_port == 0)
|
||||
@ -819,6 +816,7 @@ rem_port* INET_connect(const TEXT* name,
|
||||
"INET/INET_connect: getservbyname failed, error code = %d",
|
||||
H_ERRNO);
|
||||
gds__log(msg, 0);
|
||||
const rem_str* const string = REMOTE_make_string(protocol.c_str());
|
||||
inet_gen_error(port,
|
||||
isc_network_error,
|
||||
isc_arg_string,
|
||||
@ -828,7 +826,8 @@ rem_port* INET_connect(const TEXT* name,
|
||||
isc_arg_gds,
|
||||
isc_service_unknown,
|
||||
isc_arg_string,
|
||||
protocol, isc_arg_string, "tcp", 0);
|
||||
string->str_data,
|
||||
isc_arg_string, "tcp", 0);
|
||||
return NULL;
|
||||
} /* else / not hardwired gds_db translation */
|
||||
}
|
||||
@ -2026,7 +2025,7 @@ static in_addr get_bind_address()
|
||||
return config_address;
|
||||
}
|
||||
|
||||
static in_addr get_host_address(const TEXT* name)
|
||||
static in_addr get_host_address(const Firebird::string& name)
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
@ -2042,11 +2041,11 @@ static in_addr get_host_address(const TEXT* name)
|
||||
|
||||
THREAD_EXIT();
|
||||
|
||||
address.s_addr = inet_addr(name);
|
||||
address.s_addr = inet_addr(name.c_str());
|
||||
|
||||
if (address.s_addr == INADDR_NONE) {
|
||||
|
||||
const hostent* host = gethostbyname(name);
|
||||
const hostent* host = gethostbyname(name.c_str());
|
||||
|
||||
/* On Windows NT/9x, gethostbyname can only accomodate
|
||||
* 1 call at a time. In this case it returns the error
|
||||
@ -2059,7 +2058,7 @@ static in_addr get_host_address(const TEXT* name)
|
||||
if (!host) {
|
||||
if (H_ERRNO == INET_RETRY_ERRNO) {
|
||||
for (int retry = 0; retry < INET_RETRY_CALL; retry++) {
|
||||
if ( (host = gethostbyname(name)) )
|
||||
if ( (host = gethostbyname(name.c_str())) )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user