<commit_before>// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

import CoreFoundation

#if os(Android)
    // Android Glibc differs a little with respect to the Linux Glibc.

    // IFF_LOOPBACK is part of the enumeration net_device_flags, which needs to
    // convert to UInt32.
    private extension UInt32 {
        init(_ value: net_device_flags) {
            self.init(value.rawValue)
        }
    }

    // getnameinfo uses size_t for its 4th and 6th arguments.
    private func getnameinfo(_ addr: UnsafePointer<sockaddr>?, _ addrlen: socklen_t, _ host: UnsafeMutablePointer<Int8>?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer<Int8>?, _ servlen: socklen_t, _ flags: Int32) -> Int32 {
        return Glibc.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags)
    }
#endif

open class Host: NSObject {
    enum ResolveType {
        case name
        case address
        case current
    }
    internal var _info: String?<commit_msg>Call getifaddrs and freeifaddrs dynamically on Android<commit_after>// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

import CoreFoundation

#if os(Android)
    // Android Glibc differs a little with respect to the Linux Glibc.

    // IFF_LOOPBACK is part of the enumeration net_device_flags, which needs to
    // convert to UInt32.
    private extension UInt32 {
        init(_ value: net_device_flags) {
            self.init(value.rawValue)
        }
    }

    // getnameinfo uses size_t for its 4th and 6th arguments.
    private func getnameinfo(_ addr: UnsafePointer<sockaddr>?, _ addrlen: socklen_t, _ host: UnsafeMutablePointer<Int8>?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer<Int8>?, _ servlen: socklen_t, _ flags: Int32) -> Int32 {
        return Glibc.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags)
    }

    // getifaddrs and freeifaddrs are not available in Android 6.0 or earlier, so call these functions dynamically.
    // This only happens during the initial lookup of the addresses and then the results are cached and _resolved is marked true.
    // If this API changes so these functions are called more frequently, it might be beneficial to cache the function pointers.

    private typealias GetIfAddrsFunc = @convention(c) (UnsafeMutablePointer<UnsafeMutablePointer<ifaddrs>?>) -> Int32
    private func getifaddrs(_ ifap: UnsafeMutablePointer<UnsafeMutablePointer<ifaddrs>?>) -> Int32 {
        var result: Int32 = -1
        if let handle = dlopen("libc.so", RTLD_NOLOAD) {
            if let entry = dlsym(handle, "getifaddrs") {
                result = unsafeBitCast(entry, to: GetIfAddrsFunc.self)(ifap)
            }
            dlclose(handle)
        }
        return result
    }

    private typealias FreeIfAddrsFunc = @convention(c) (UnsafeMutablePointer<ifaddrs>?) -> Void
    private func freeifaddrs(_ ifa: UnsafeMutablePointer<ifaddrs>?) {
        if let handle = dlopen("libc.so", RTLD_NOLOAD) {
            if let entry = dlsym(handle, "freeifaddrs") {
                unsafeBitCast(entry, to: FreeIfAddrsFunc.self)(ifa)
            }
            dlclose(handle)
        }
    }
#endif

open class Host: NSObject {
    enum ResolveType {
        case name
        case address
        case current
    }
    internal var _info: String?
{'fraction_non_alphanumeric': 0.08575096277278563, 'fraction_numerical': 0.013607188703465983, 'mean_word_length': 2.9553299492385787, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4305855', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1131, 'n_words': 386}