diff -urN ntplib-0.1.8/ntplib.py ntplib-0.1.8-solrex/ntplib.py --- ntplib-0.1.8/ntplib.py 2010-02-20 16:55:43.000000000 +0800 +++ ntplib-0.1.8-solrex/ntplib.py 2010-03-07 13:34:13.333250000 +0800 @@ -164,25 +164,24 @@ def request(self, host, version=2, port='ntp'): """make a NTP request to a server - return a NTPStats object""" + # lookup server address + addrinfo = socket.getaddrinfo(host, port)[0] + # create the socket - let the application handle (unlikely) exceptions - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s = socket.socket(addrinfo[0], socket.SOCK_DGRAM) s.settimeout(5) - try: - # lookup server address - sockaddr = socket.getaddrinfo(host, port)[0][4] - # create the request packet - mode 3 is client query = NTPPacket(mode=3, version=version, tx_timestamp=system_to_ntp_time(time.time())) query_packet = query.to_data() - + # send the request - s.sendto(query_packet, sockaddr) - + s.sendto(query_packet, addrinfo[4]) + # wait for the response - check the source address - src_addr = (None, None) - while src_addr != sockaddr: + (response_packet, src_addr) = s.recvfrom(256) + while src_addr[0] != addrinfo[4][0]: (response_packet, src_addr) = s.recvfrom(256) # build the destination timestamp