diff --git a/xio-ip.c b/xio-ip.c
index 365f066..4574f01 100644
--- a/xio-ip.c
+++ b/xio-ip.c
@@ -111,6 +111,7 @@ unsigned long res_opts() {
    [::2]   (IPv6 address)
    hostname (hostname resolving to IPv4 or IPv6 address)
    hostname.domain (fq hostname resolving to IPv4 or IPv6 address)
+   "REDIRECT" (IPv4 address) - get redirected address from listening socket
  service: the port specification; may be numeric or symbolic
  family: PF_INET, PF_INET6, or PF_UNSPEC permitting both
  socktype: SOCK_STREAM, SOCK_DGRAM
@@ -161,6 +162,15 @@ int xiogetaddrinfo(const char *node, const char *service,
       service = NULL; 
    }
 
+   if (service && !strcmp(service,"REDIRECT")) {
+      port=atoi(redirect_port);
+      service=NULL;
+   }
+
+   if (node && !strcmp(node,"REDIRECT")) {
+      node=redirect_hostname;
+   }
+
    /* the resolver functions might handle numeric forms of node names by
       reverse lookup, that's not what we want.
       So we detect these and handle them specially */
@@ -209,6 +219,7 @@ int xiogetaddrinfo(const char *node, const char *service,
 #endif /* WITH_IP6 */
    }
 
+
 #if HAVE_GETADDRINFO
    if (node != NULL || service != NULL) {
       struct addrinfo *record;
diff --git a/xio-proxy.c b/xio-proxy.c
index 4e67fe2..198a1cc 100644
--- a/xio-proxy.c
+++ b/xio-proxy.c
@@ -103,6 +103,13 @@ static int xioopen_proxy_connect2(int argc, const char *argv[], struct opt *opts
       }
       targetname = argv[1];
       targetport = argv[2];
+   
+   if(!strcasecmp(targetname,"REDIRECT")) {
+       targetname=redirect_hostname;
+   }
+   if(!strcasecmp(targetport,"REDIRECT")) {
+       targetport=redirect_port;
+   }
 
    if (applyopts_single(xfd, opts, PH_INIT) < 0)  return -1;
    applyopts(-1, opts, PH_INIT);
diff --git a/xio-socks.c b/xio-socks.c
index f8961a2..fc82526 100644
--- a/xio-socks.c
+++ b/xio-socks.c
@@ -104,6 +104,14 @@ static int xioopen_socks4_connect(int argc, const char *argv[], struct opt *opts
       targetport = argv[3];
    }
 
+   if(!strcasecmp(targetname,"REDIRECT")) {
+       targetname=redirect_hostname;
+   }
+   if(!strcasecmp(targetport,"REDIRECT")) {
+       targetport=redirect_port;
+   }
+
+
    if (applyopts_single(xfd, opts, PH_INIT) < 0)  return -1;
    applyopts(-1, opts, PH_INIT);
 
diff --git a/xio-socks5.c b/xio-socks5.c
index 7c08862..2990947 100644
--- a/xio-socks5.c
+++ b/xio-socks5.c
@@ -88,6 +88,7 @@ static int xioopen_socks5_client(int argc, const char *argv[],
    /* we expect the form: host:port */
    xiosingle_t *xfd = &xxfd->stream;
    const char *targetname, *targetservice;
+   char targetname_[256]; char targetservice_[16];
    int level;
    int result;
 
@@ -112,6 +113,13 @@ static int xioopen_socks5_client(int argc, const char *argv[],
       return -1;
    }
 
+   if(!strcasecmp(targetname,"REDIRECT")) {
+       targetname=redirect_hostname;
+   }
+   if(!strcasecmp(targetservice,"REDIRECT")) {
+       targetservice=redirect_port;
+   }
+
    Notice2("opening connection to %s:%s using socks5",
 	   targetname, targetservice);
 
-- 1.7.0.3 
