def get_socket_address(host, port, ipv4_only=False):
 try:
  info = socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_DGRAM)
 except socket.gaierror as e:
  try:
   if (not ipv4_only):
    info = socket.getaddrinfo(host, port, socket.AF_INET6, socket.SOCK_DGRAM)
   elif (host == 'localhost'):
    log.warning('Warning localhost seems undefined in your host file, using 127.0.0.1 instead')
    info = socket.getaddrinfo('127.0.0.1', port, socket.AF_INET, socket.SOCK_DGRAM)
   else:
    log.error('Error processing host %s and port %s: %s', host, port, e)
    return None
  except socket.gaierror as e:
   log.error('Error processing host %s and port %s: %s', host, port, e)
   return None
 sockaddr = info[0][(-1)]
 if ((info[0][0] == socket.AF_INET) and (not ipv4_only)):
  mapped_host = mapto_v6(sockaddr[0])
  sockaddr = (mapped_host, sockaddr[1], 0, 0)
 return sockaddr

def get_socket_address ( host , port , ipv4_only = False ) : try : info = socket . getaddrinfo ( host , port , socket . AF_INET , socket . SOCK_DGRAM ) except socket . gaierror as e : try : if ( not ipv4_only ) : info = socket . getaddrinfo ( host , port , socket . AF_INET6 , socket . SOCK_DGRAM ) elif ( host == 'localhost' ) : log . warning ( 'Warning localhost seems undefined in your host file, using 127.0.0.1 instead' ) info = socket . getaddrinfo ( '127.0.0.1' , port , socket . AF_INET , socket . SOCK_DGRAM ) else : log . error ( 'Error processing host %s and port %s: %s' , host , port , e ) return None except socket . gaierror as e : log . error ( 'Error processing host %s and port %s: %s' , host , port , e ) return None sockaddr = info [ 0 ] [ ( - 1 ) ] if ( ( info [ 0 ] [ 0 ] == socket . AF_INET ) and ( not ipv4_only ) ) : mapped_host = mapto_v6 ( sockaddr [ 0 ] ) sockaddr = ( mapped_host , sockaddr [ 1 ] , 0 , 0 ) return sockaddr
gather informations to open the server socket .