#NEWLINE# def inet_ntop( address_family , packed_ip ) : #NEWLINE# #INDENT# addr = sockaddr ( ) #NEWLINE# addr . sa_family = address_family #NEWLINE# addr_size = ctypes . c_int ( ctypes . sizeof ( addr ) ) #NEWLINE# ip_string = ctypes . create_string_buffer ( 128 ) #NEWLINE# ip_string_size = ctypes . c_int ( ctypes . sizeof ( ip_string ) ) #NEWLINE# if ( address_family == socket . AF_INET ) : #NEWLINE# #INDENT# if ( len ( packed_ip ) != ctypes . sizeof ( addr . ipv4_addr ) ) : #NEWLINE# #INDENT# raise socket . error ( 'packed IP wrong length for inet_ntoa' ) #NEWLINE# #UNINDENT# ctypes . memmove ( addr . ipv4_addr , packed_ip , 4 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( address_family == socket . AF_INET6 ) : #NEWLINE# #INDENT# if ( len ( packed_ip ) != ctypes . sizeof ( addr . ipv6_addr ) ) : #NEWLINE# #INDENT# raise socket . error ( 'packed IP wrong length for inet_ntoa' ) #NEWLINE# #UNINDENT# ctypes . memmove ( addr . ipv6_addr , packed_ip , 16 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise socket . error ( 'unknown address family' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( WSAAddressToStringA ( ctypes . byref ( addr ) , addr_size , None , ip_string , ctypes . byref ( ip_string_size ) ) != 0 ) : #NEWLINE# #INDENT# raise socket . error ( ctypes . FormatError ( ) ) #NEWLINE# #UNINDENT# return ip_string [ : ( ip_string_size . value - 1 ) ]