diff --git a/contrib/libfaketime/COPYING b/contrib/libfaketime/COPYING
new file mode 100644
index 0000000000000000000000000000000000000000..d159169d1050894d3ea3b98e1c965c4058208fe1
--- /dev/null
+++ b/contrib/libfaketime/COPYING
@@ -0,0 +1,339 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                            NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/contrib/libfaketime/libfaketime.so.1 b/contrib/libfaketime/libfaketime.so.1
new file mode 100644
index 0000000000000000000000000000000000000000..420893a82e05f70c4648b59d1fb02036e7dd4616
Binary files /dev/null and b/contrib/libfaketime/libfaketime.so.1 differ
diff --git a/contrib/libfaketime/libfaketimeMT.so.1 b/contrib/libfaketime/libfaketimeMT.so.1
new file mode 100644
index 0000000000000000000000000000000000000000..e0c6ca8d27f9f182e7ecf265f218c6bda6c59cb5
Binary files /dev/null and b/contrib/libfaketime/libfaketimeMT.so.1 differ
diff --git a/platform.mk b/platform.mk
index 724cd4222dd3475f8355c1d86de2cebc8be31501..f8e0805126813a38c09796b0838831e55fb5b2b4 100644
--- a/platform.mk
+++ b/platform.mk
@@ -134,8 +134,7 @@ endef
 
 # Find libfaketime
 define find_libfaketime
-        SPACED_PATH := $(subst :, ,$(PATH))
-        libfaketime_LIBS := $(shell find $(HOME)/.local /usr/local $(S_PATH) -name $(libfaketime_name) -print -quit 2> /dev/null)
+        libfaketime_LIBS := $(shell find ./contrib -name $(libfaketime_name) -print -quit 2> /dev/null)
 	$(call have_lib,libfaketime)
 endef
 
diff --git a/tests/pydnstest/testserver.py b/tests/pydnstest/testserver.py
index de4879a2db918befb8e6cceba5026a4dd3bc689f..93c6764b5bd0c699fb964e56f4fa2ca386b0c853 100644
--- a/tests/pydnstest/testserver.py
+++ b/tests/pydnstest/testserver.py
@@ -15,12 +15,13 @@ if 'TEST_DEBUG' in os.environ:
 
 g_lock = threading.Lock()
 def syn_print(tag, *args):
-        g_lock.acquire()
-        if tag is None:
-            tag = inspect.stack()[1][3]
-        for s in args:
-            print "[{:<12}][{}] {}".format(tag,threading.current_thread().name,s)
-        g_lock.release()
+    """ Print message with some debug information included. """
+    g_lock.acquire()
+    if tag is None:
+        tag = inspect.stack()[1][3]
+    for s in args:
+        print "[{:<12}][{}] {}".format(tag,threading.current_thread().name,s)
+    g_lock.release()
 
 def recvfrom_msg(stream):
     """ Receive DNS/UDP message. """
@@ -49,18 +50,14 @@ def get_local_addr_str(family, iface):
         raise Exception("[get_local_addr_str] family not supported '%i'" % family)
     return addr_local_pattern.format(iface)
 
-
-class SInfo:
-    def __init__(self,type,addr,port,client_addr):
-        self.type = type
-        self.addr = addr
-        self.port = port
-        self.client_addr = client_addr
-        self.thread = None
-        self.active = False
-        self.name = ''
+class SrvSock (socket.socket):
+    """ Socket with some additional info  """
+    def __init__(self, client_address, family=socket.AF_INET, type=socket.SOCK_DGRAM, proto=socket.IPPROTO_UDP):
+        self.client_address = client_address
+        socket.socket.__init__(self, family, type, proto)
 
 class AddrMapInfo:
+    """ Saves mapping info between adresses from rpl and cwrap adresses """
     def __init__(self, family, local, external):
         self.family   = family
         self.local    = local
@@ -73,6 +70,7 @@ class TestServer:
         """ Initialize server instance. """
         if TEST_DEBUG > 0:
             syn_print(None, "initialization")
+        self.thread = None
         self.srv_socks = []
         self.client_socks = []
 	self.active = False
@@ -98,27 +96,27 @@ class TestServer:
             self.stop()
 
     def start(self):
-        """ Asynchronous start, returns immediately. """
+        """ Synchronous start """
         if TEST_DEBUG > 0:
             syn_print(None, "start")
         if self.active is True:
             raise Exception('TestServer already started')
         self.active = True
-        self.start_srv(self.kroot_local, self.kroot_family, self.kroot_local)
+        self.start_srv(self.kroot_local, self.kroot_family)
 
     def stop(self):
         """ Stop socket server operation. """
         if TEST_DEBUG > 0:
             syn_print(None,"stop")
         self.active = False
+        self.thread.join()
         for srv_sock in self.srv_socks:
             if TEST_DEBUG > 0:
-                syn_print(None, "closing socket {name}".format(name=srv_sock.name))
-            srv_sock.active = False
-            srv_sock.thread.join()
+                syn_print(None, "closing socket {name}".format(name=srv_sock.getsockname()))
+            srv_sock.close()
         for client_sock in self.client_socks:
             if TEST_DEBUG > 0:
-                syn_print(None, "closing client socket")
+                syn_print(None, "closing client socket {name}".format(name=client_sock.getsockname()))
             client_sock.close()
         self.client_socks = []
         self.srv_socks = []
@@ -175,6 +173,16 @@ class TestServer:
                 self.cur_iface = self.cur_iface + 1
         return local_address, family
 
+    def get_external(self, local_address, family):
+        """ Fetches external address mapped to local_address """
+        external_address = None
+        for am in self.addr_map:
+            if am.local == local_address and am.family == family:
+                external_address = am.external
+
+        return external_address
+
+
     def map_entries(self, entrylist):
         """ Translate addresses for A and AAAA records"""
         for entry in entrylist :
@@ -202,7 +210,6 @@ class TestServer:
             syn_print(None,"translating config")
         m = re.search("(?P<kroot>\S+)\s+#\s+K.ROOT-SERVERS.NET.", self.config)
         if m is not None:
-#            raise Exception("[map_adresses] Can't parse K.ROOT-SERVERS.NET. address, check the config")
             kroot_addr = m.group("kroot")
             self.kroot_local, self.kroot_family = self.get_local(kroot_addr, True)
             if self.kroot_local is None:
@@ -232,14 +239,15 @@ class TestServer:
         """ Returns opened sockets list """
         addrlist = [];
         for s in self.srv_socks:
-            addrlist.append(s.name);
+            addrlist.append(s.getsockname());
         return addrlist;
 
-    def handle_query(self, client, client_address):
+    def handle_query(self, client):
         """ Handle incoming queries. """
+        client_address = client.client_address
         query, addr = recvfrom_msg(client)
         if TEST_DEBUG > 0:
-            syn_print(None, "incoming query from {addr}; client={client}".format(addr=addr, client=client_address))
+            syn_print(None, "incoming query from {}; client address {}, mapped to external {}".format(addr, client_address, self.get_external(client_address, client.family)))
         if TEST_DEBUG > 1:
             syn_print(None,"========= INCOMING QUERY START =========")
             syn_print(None,query)
@@ -273,11 +281,11 @@ class TestServer:
                         if rd.rdtype == dns.rdatatype.A:
                             if TEST_DEBUG > 1:
                                  syn_print(None,"rd address =", rd.address)
-                            self.start_srv(rd.address, socket.AF_INET, rd.address)
+                            self.start_srv(rd.address, socket.AF_INET)
                         elif rd.rdtype == dns.rdatatype.AAAA:
                             if TEST_DEBUG > 1:
                                 syn_print(None,"rd address =", rd.address)
-                            self.start_srv(rd.address, socket.AF_INET6, rd.address)
+                            self.start_srv(rd.address, socket.AF_INET6)
                 sendto_msg(client, response.to_wire(), addr)
             else:
                 sendto_msg(client, response, addr)
@@ -291,47 +299,35 @@ class TestServer:
             sendto_msg(client, response.to_wire(), addr)
             return False
 
-    def query_io(self,srv_sock):
+    def query_io(self):
         """ Main server process """
-        if TEST_DEBUG > 0:
-            syn_print(None,"query_io starts")
         if self.active is False:
             raise Exception("[query_io] Test server not active")
-        res = socket.getaddrinfo(srv_sock.addr,srv_sock.port,srv_sock.type,0,socket.IPPROTO_UDP)
-        serv_sock = socket.socket(srv_sock.type, socket.SOCK_DGRAM,socket.IPPROTO_UDP)
-        entry0 = res[0]
-        sockaddr = entry0[4]
-        serv_sock.bind(sockaddr)
-        serv_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-        address = serv_sock.getsockname()
-        srv_sock.name = address
-        clients = [serv_sock]
-        srv_sock.active = True
         if TEST_DEBUG > 0:
-            syn_print(None,"UDP query handler type {type} started at {addr}".format(type=srv_sock.type,addr=address))
-        while srv_sock.active is True:
-           to_read, _, to_error = select.select(clients, [], clients, 0.1)
+            syn_print(None,"UDP query io handler started")
+
+        while self.active is True:
+           to_read, _, to_error = select.select(self.srv_socks, [], self.srv_socks, 0.1)
            for sock in to_read:
-              self.handle_query(sock,srv_sock.client_addr)
+              self.handle_query(sock)
            for sock in to_error:
               if TEST_DEBUG > 0:
-                  syn_print(None,"Socket error")
-              raise Exception("[query_io] Socket IO error, exit")
-        serv_sock.close()
+                  syn_print(None,"Error for socket {}".format(sock.getsockname()))
+              raise Exception("[query_io] Socket IO error {}, exit".format(sock.getsockname()))
         if TEST_DEBUG > 0:
-            syn_print(None,"UDP query handler exit")
+            syn_print(None,"UDP query io handler exit")
 
 
-    def start_srv(self, client_addr, type = socket.AF_INET, address = None, port = 53):
+    def start_srv(self, address = None, family = socket.AF_INET, port = 53):
         """ Starts listening thread if necessary """
         if TEST_DEBUG > 0:
-            syn_print(None,"starting server thread; socket type {type} {address} client {client_addr}".format(type=type,address=address,client_addr=client_addr))
-        if type == None:
-            type = socket.AF_INET
-        if type == socket.AF_INET:
+            syn_print(None,"starting socket; type {} {} {}".format(family,address,port))
+        if family == None:
+            family = socket.AF_INET
+        if family == socket.AF_INET:
             if address == '' or address is None:
                 address = "127.0.0.{}".format(self.default_iface)
-        elif type == socket.AF_INET6:
+        elif family == socket.AF_INET6:
             if socket.has_ipv6 is not True:
                 raise Exception("[start_srv] IPV6 is not supported")
             if address == '' or address is None:
@@ -339,33 +335,37 @@ class TestServer:
         else:
             syn_print(None, "unsupported socket type {sock_type}".format(sock_type=type))
             raise Exception("[start_srv] unsupported socket type {sock_type}".format(sock_type=type))
-        if client_addr is not None:
-            client_addr = client_addr.split('@')[0]
-        else:
-            client_addr = address
 	if port == 0 or port is None:
             port = 53
+
+        if (self.thread is None):
+            self.thread = threading.Thread(target=self.query_io)
+            self.thread.start()
+
         for srv_sock in self.srv_socks:
-            if srv_sock.type == type and srv_sock.client_addr == client_addr :
+            if srv_sock.family == family and srv_sock.client_address == address :
                 if TEST_DEBUG > 0:
-                    syn_print(None, "server thread '%s' at '%s' already started" % (srv_sock.thread.name, srv_sock.addr) )
-                return srv_sock.name
-        srv_sock = SInfo(type,address,port,client_addr)
-        srv_sock.thread = threading.Thread(target=self.query_io, args=(srv_sock,))
-        srv_sock.thread.start()
-        while srv_sock.active is False:
-            continue
-        self.srv_socks.append(srv_sock)
+                    syn_print(None, "server socket {} already started".format(srv_sock.getsockname()) )
+                return srv_sock.getsockname()
+    
+        addr_info = socket.getaddrinfo(address,port,family,0,socket.IPPROTO_UDP)
+        sock = SrvSock(address, family, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
+        addr_info_entry0 = addr_info[0]
+        sockaddr = addr_info_entry0[4]
+        sock.bind(sockaddr)
+        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+        self.srv_socks.append(sock)
+        sockname = sock.getsockname()
         if TEST_DEBUG > 0:
-            syn_print(None, "server thread '%s' at '%s:%i' started" % (srv_sock.thread.name, srv_sock.addr, srv_sock.port))
-        return srv_sock.name
+            syn_print(None, "server socket {} started".format(sockname))
+        return sockname
 
     def client(self, dst_addr = None):
         """ Return connected client. """
         if dst_addr is not None:
             dst_addr = dst_addr.split('@')[0]
+        sockname = self.start_srv(dst_addr, socket.AF_INET)
         sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-        sockname = self.start_srv(dst_addr,socket.AF_INET)
         sock.connect(sockname)
         self.client_socks.append(sock)
         return sock, sockname
@@ -395,16 +395,26 @@ def test_sendrecv(default_iface,peer_iface):
 
 if __name__ == '__main__':
 
+    syn_print(None,"qqqqqqqqqqqqqq")
     # Self-test code
+    DEFAULT_IFACE = 0
+    CHILD_IFACE = 0
+    if "SOCKET_WRAPPER_DEFAULT_IFACE" in os.environ:
+       DEFAULT_IFACE = int(os.environ["SOCKET_WRAPPER_DEFAULT_IFACE"])
+    if DEFAULT_IFACE < 2 or DEFAULT_IFACE > 254 :
+        if TEST_DEBUG > 0:
+            syn_print(None,"SOCKET_WRAPPER_DEFAULT_IFACE is invalid ({}), set to default (10)".format(DEFAULT_IFACE))
+        DEFAULT_IFACE = 10
+        os.environ["SOCKET_WRAPPER_DEFAULT_IFACE"]="{}".format(DEFAULT_IFACE)
+
     test = test.Test()
-    test.add('testserver/sendrecv', test_sendrecv)
+    test.add('testserver/sendrecv', test_sendrecv, DEFAULT_IFACE, DEFAULT_IFACE)
     if test.run() != 0:
         sys.exit(1)
 
     # Mirror server
-    server = TestServer(None)
+    server = TestServer(None,None,DEFAULT_IFACE,DEFAULT_IFACE)
     server.start()
-    server.start_srv(None, socket.AF_INET)
     syn_print("main","[==========] Mirror server running at", server.address())
     try:
         while True: