def get_addr(hostname, socktype, protocol, port, address_to_fill): hostent = _c.gethostbyname(hostname) if not hostent: raise GAIError(EAI_FAIL) hname, aliases, address_list = gethost_common("", hostent) result = [] for address in address_list: if address.family == _c.AF_INET: a = address.lock(_c.sockaddr_in) rffi.setintfield(a, 'c_sin_port', port & 0xffff) address.unlock() a = address.lock() addr = make_address(a, address.addrlen, address_to_fill) address.unlock() result.append(( address.family, socktype, protocol, "", # XXX canonname? addr)) return result
def get_addr(hostname, socktype, protocol, port, address_to_fill): hostent = _c.gethostbyname(hostname) if not hostent: raise GAIError(EAI_FAIL) hname, aliases, address_list = gethost_common("", hostent) result = [] for address in address_list: if address.family == _c.AF_INET: a = address.lock(_c.sockaddr_in) rffi.setintfield(a, 'c_sin_port', r_uint(port) & 0xffff) address.unlock() a = address.lock() addr = make_address(a, address.addrlen, address_to_fill) address.unlock() result.append((address.family, socktype, protocol, "", # XXX canonname? addr)) return result
def gethostbyname_ex(name): # XXX use gethostbyname_r() if available, and/or use locks if not addr = gethostbyname(name) hostent = _c.gethostbyname(name) return gethost_common(name, hostent, addr)