aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libssh/priv.h2
-rw-r--r--src/connect.c66
-rw-r--r--src/init.c3
3 files changed, 8 insertions, 63 deletions
diff --git a/include/libssh/priv.h b/include/libssh/priv.h
index 66f24e2d..4dbc4450 100644
--- a/include/libssh/priv.h
+++ b/include/libssh/priv.h
@@ -172,8 +172,6 @@ void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callback
void ssh_packet_set_default_callbacks(ssh_session session);
void ssh_packet_process(ssh_session session, uint8_t type);
/* connect.c */
-int ssh_regex_init(void);
-void ssh_regex_finalize(void);
socket_t ssh_connect_host(ssh_session session, const char *host,const char
*bind_addr, int port, long timeout, long usec);
socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
diff --git a/src/connect.c b/src/connect.c
index 6f4fa81f..20997864 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -21,12 +21,17 @@
* MA 02111-1307, USA.
*/
+#include "config.h"
+
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "libssh/libssh.h"
+#include "libssh/misc.h"
+
#ifdef _WIN32
/*
* Only use Windows API functions available on Windows 2000 SP4 or later.
@@ -78,14 +83,6 @@
#error "Your system must have getaddrinfo()"
#endif
-#ifdef HAVE_REGCOMP
-/* don't declare gnu extended regexp's */
-#ifndef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE
-#endif
-#include <regex.h>
-#endif /* HAVE_REGCOMP */
-
#ifdef _WIN32
void ssh_sock_set_nonblocking(socket_t sock) {
u_long nonblocking = 1;
@@ -118,53 +115,6 @@ void ssh_sock_set_blocking(socket_t sock) {
#endif /* _WIN32 */
-#ifdef HAVE_REGCOMP
-#define IPEXPR "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
-
-static regex_t *ip_regex = NULL;
-
-/** @internal
- * @brief initializes and compile the regexp to be used for IP matching
- * @returns -1 on error (and error message is set)
- * @returns 0 on success
- */
-int ssh_regex_init(){
- if(ip_regex==NULL){
- int err;
- regex_t *regex=malloc(sizeof (regex_t));
- ZERO_STRUCTP(regex);
- err = regcomp(regex, IPEXPR, REG_EXTENDED | REG_NOSUB);
- if(err != 0){
- char buffer[128];
- regerror(err,regex,buffer,sizeof(buffer));
- fprintf(stderr,"Error while compiling regular expression : %s\n",buffer);
- SAFE_FREE(regex);
- return -1;
- }
- ip_regex=regex;
- }
- return 0;
-}
-
-/** @internal
- * @brief clean up the IP regexp
- */
-void ssh_regex_finalize(){
- if(ip_regex){
- regfree(ip_regex);
- SAFE_FREE(ip_regex);
- }
-}
-
-#else /* HAVE_REGCOMP */
-int ssh_regex_init(){
- return 0;
-}
-void ssh_regex_finalize(){
-}
-#endif
-
-
static int ssh_connect_socket_close(socket_t s){
#ifdef _WIN32
return closesocket(s);
@@ -194,13 +144,13 @@ static int getai(ssh_session session, const char *host, int port, struct addrinf
hints.ai_flags=AI_NUMERICSERV;
#endif
}
-#ifdef HAVE_REGCOMP
- if(regexec(ip_regex,host,0,NULL,0) == 0){
+
+ if (ssh_is_ipaddr(host)) {
/* this is an IP address */
ssh_log(session,SSH_LOG_PACKET,"host %s matches an IP address",host);
hints.ai_flags |= AI_NUMERICHOST;
}
-#endif
+
return getaddrinfo(host, service, &hints, ai);
}
diff --git a/src/init.c b/src/init.c
index 385cb7a4..7b29d2b6 100644
--- a/src/init.c
+++ b/src/init.c
@@ -57,8 +57,6 @@ int ssh_init(void) {
return -1;
if(ssh_socket_init())
return -1;
- if(ssh_regex_init())
- return -1;
return 0;
}
@@ -74,7 +72,6 @@ int ssh_init(void) {
*/
int ssh_finalize(void) {
ssh_threads_finalize();
- ssh_regex_finalize();
ssh_crypto_finalize();
ssh_socket_cleanup();
#ifdef HAVE_LIBGCRYPT