Пример #1
0
def gethost_common(hostname, hostent, addr=None):
    if not hostent:
        raise HSocketError(hostname)
    family = rffi.getintfield(hostent, 'c_h_addrtype')
    if addr is not None and addr.family != family:
        raise CSocketError(_c.EAFNOSUPPORT)

    h_aliases = hostent.c_h_aliases
    if h_aliases:   # h_aliases can be NULL, according to SF #1511317
        aliases = rffi.charpp2liststr(h_aliases)
    else:
        aliases = []

    address_list = []
    h_addr_list = hostent.c_h_addr_list
    i = 0
    paddr = h_addr_list[0]
    while paddr:
        if family == AF_INET:
            p = rffi.cast(lltype.Ptr(_c.in_addr), paddr)
            addr = INETAddress.from_in_addr(p)
        elif AF_INET6 is not None and family == AF_INET6:
            p = rffi.cast(lltype.Ptr(_c.in6_addr), paddr)
            addr = INET6Address.from_in6_addr(p)
        else:
            raise RSocketError("unknown address family")
        address_list.append(addr)
        i += 1
        paddr = h_addr_list[i]
    return (rffi.charp2str(hostent.c_h_name), aliases, address_list)
Пример #2
0
def gethost_common(hostname, hostent, addr=None):
    if not hostent:
        raise HSocketError(hostname)
    family = rffi.getintfield(hostent, 'c_h_addrtype')
    if addr is not None and addr.family != family:
        raise CSocketError(_c.EAFNOSUPPORT)

    h_aliases = hostent.c_h_aliases
    if h_aliases:   # h_aliases can be NULL, according to SF #1511317
        aliases = rffi.charpp2liststr(h_aliases)
    else:
        aliases = []

    address_list = []
    h_addr_list = hostent.c_h_addr_list
    i = 0
    paddr = h_addr_list[0]
    while paddr:
        if family == AF_INET:
            p = rffi.cast(lltype.Ptr(_c.in_addr), paddr)
            addr = INETAddress.from_in_addr(p)
        elif AF_INET6 is not None and family == AF_INET6:
            p = rffi.cast(lltype.Ptr(_c.in6_addr), paddr)
            addr = INET6Address.from_in6_addr(p)
        else:
            raise RSocketError("unknown address family")
        address_list.append(addr)
        i += 1
        paddr = h_addr_list[i]
    return (rffi.charp2str(hostent.c_h_name), aliases, address_list)
Пример #3
0
def _build_group_info(space, res):
    members = []
    for member in rffi.charpp2liststr(res.c_gr_mem):
        members.append(space.newstr(member))

    return space.new_array_from_pairs([
        (space.newstr("name"), space.newstr(rffi.charp2str(res.c_gr_name))),
        (space.newstr("passwd"), space.newstr(rffi.charp2str(res.c_gr_passwd))),
        (space.newstr("members"), space.new_array_from_list(members)),
        (space.newstr("gid"), space.newint(intmask(res.c_gr_gid))),
    ])
Пример #4
0
def _build_group_info(space, res):
    members = []
    for member in rffi.charpp2liststr(res.c_gr_mem):
        members.append(space.newstr(member))

    return space.new_array_from_pairs([
        (space.newstr("name"), space.newstr(rffi.charp2str(res.c_gr_name))),
        (space.newstr("passwd"),
         space.newstr(rffi.charp2str(res.c_gr_passwd))),
        (space.newstr("members"), space.new_array_from_list(members)),
        (space.newstr("gid"), space.newint(intmask(res.c_gr_gid))),
    ])