def sockaddr(host, port, network='ipv4'):
 address_family = {'ipv4': socket.AF_INET, 'ipv6': socket.AF_INET6}[network]
 for (family, _, _, _, ip) in socket.getaddrinfo(host, None, address_family):
  ip = ip[0]
  if (family == address_family):
   break
 else:
  log.error(('Could not find %s address for %r' % (network, host)))
 info = socket.getaddrinfo(host, None, address_family)
 host = socket.inet_pton(address_family, ip)
 sockaddr = p16(address_family)
 sockaddr += pack(port, word_size=16, endianness='big')
 length = 0
 if (network == 'ipv4'):
  sockaddr += host
  length = 16
 else:
  sockaddr += p32(4294967295)
  sockaddr += host
  length = (len(sockaddr) + 4)
 return (sockaddr, length, address_family)

def sockaddr ( host , port , network = 'ipv4' ) : address_family = { 'ipv4' : socket . AF_INET , 'ipv6' : socket . AF_INET6 } [ network ] for ( family , _ , _ , _ , ip ) in socket . getaddrinfo ( host , None , address_family ) : ip = ip [ 0 ] if ( family == address_family ) : break else : log . error ( ( 'Could not find %s address for %r' % ( network , host ) ) ) info = socket . getaddrinfo ( host , None , address_family ) host = socket . inet_pton ( address_family , ip ) sockaddr = p16 ( address_family ) sockaddr += pack ( port , word_size = 16 , endianness = 'big' ) length = 0 if ( network == 'ipv4' ) : sockaddr += host length = 16 else : sockaddr += p32 ( 4294967295 ) sockaddr += host length = ( len ( sockaddr ) + 4 ) return ( sockaddr , length , address_family )
sockaddr -> creates a sockaddr_in or sockaddr_in6 memory buffer for use in shellcode .