<commit_before>// This example uses fds() to find out which file descriptors c-ares
// wants us to listen on, and uses select() to satisfy those requirements.
extern crate c_ares;

use winapi::winsock2::{
    fd_set,
    FD_SETSIZE,
    SOCKET_ERROR,
    timeval,
    WSADATA,
};
use ws2_32::{
    select,
    WSACleanup,
    WSAStartup,
};
use std::error::Error;
use std::mem;
use std::net::{
    Ipv4Addr,
    Ipv6Addr,
    SocketAddr,
    SocketAddrV4,
    SocketAddrV6,
};
use std::ptr;

fn print_soa_result(result: Result<c_ares::SOAResult, c_ares::AresError>) {
    match result {
        Err(e) => {
            println!("SOA lookup failed with error '{}'", e.description());
        }
        Ok(soa_result) => {
            println!("Successful SOA lookup...");
            println!("Name server: {}", soa_result.name_server());
            println!("Hostmaster: {}", soa_result.hostmaster());
            println!("Serial: {}", soa_result.serial());
            println!("Retry: {}", soa_result.retry());
            println!("Expire: {}", soa_result.expire());
            println!("Min TTL: {}", soa_result.min_ttl());
        }
    }
}

fn print_name_info_result(
    result: Result<c_ares::NameInfoResult, c_ares::AresError>) {
    match result {
        Err(e) => {
            println!(
                "Name info lookup failed with error '{}'",
                e.description());
        }
        Ok(name_info_result) => {
            println!("Successful name info lookup...");
            println!("Node: {}", name_info_result.node().unwrap_or("<None>"));
            println!(
                "Service: {}",
                name_info_result.service().unwrap_or("<None>"));
        }
    }
}

pub fn main() {
    // Windows peculiarities.
    unsafe {
        let mut wsadata: WSADATA = mem::uninitialized();
        WSAStartup(0x101, &mut wsadata);
    }

    // Create the c_ares::Channel.
    let mut options = c_ares::Options::new();
    options
        .set_domains(&["example.com"])
        .set_flags(c_ares::flags::STAYOPEN)
        .set_timeout(500)
        .set_tries(3);
    let mut ares_channel = c_ares::Channel::new(options)
        .expect("Failed to create channel");
    ares_channel.set_servers(&["8.8.8.8"])
        .expect("Failed to set servers");

    // Set up some queries.
    ares_channel.query_soa("google.com", move |result| {
        println!("");
        print_soa_result(result);
    });

    let ipv4 = Ipv4Addr::new(216, 58, 210, 14);
    let sock = SocketAddr::V4(SocketAddrV4::new(ipv4, 80));
    ares_channel.get_name_info(
        &sock,
        c_ares::ni_flags::LOOKUPHOST | c_ares::ni_flags::LOOKUPSERVICE,
        move |result| {
            println!("");
            print_name_info_result(result);
        }
    );

    let ipv6 = Ipv6Addr::new(0x2a00, 0x1450, 0x4009, 0x80a, 0, 0, 0, 0x200e);
    let sock = SocketAddr::V6(SocketAddrV6::new(ipv6, 80, 0, 0));
    ares_channel.get_name_info(
        &sock,
        c_ares::ni_flags::LOOKUPHOST | c_ares::ni_flags::LOOKUPSERVICE,
        move |result| {
            println!("");
            print_name_info_result(result);
        }
    );

    // While c-ares wants us to listen for events, do so..<commit_msg>Slight prettification<commit_after>// This example uses fds() to find out which file descriptors c-ares
// wants us to listen on, and uses select() to satisfy those requirements.
extern crate c_ares;

use winapi::winsock2::{
    fd_set,
    FD_SETSIZE,
    SOCKET_ERROR,
    timeval,
    WSADATA,
};
use ws2_32::{
    select,
    WSACleanup,
    WSAStartup,
};
use std::error::Error;
use std::mem;
use std::net::{
    Ipv4Addr,
    Ipv6Addr,
    SocketAddr,
    SocketAddrV4,
    SocketAddrV6,
};
use std::ptr;

fn print_soa_result(result: Result<c_ares::SOAResult, c_ares::AresError>) {
    match result {
        Err(e) => {
            println!("SOA lookup failed with error '{}'", e.description());
        }
        Ok(soa_result) => {
            println!("Successful SOA lookup...");
            println!("Name server: {}", soa_result.name_server());
            println!("Hostmaster: {}", soa_result.hostmaster());
            println!("Serial: {}", soa_result.serial());
            println!("Retry: {}", soa_result.retry());
            println!("Expire: {}", soa_result.expire());
            println!("Min TTL: {}", soa_result.min_ttl());
        }
    }
}

fn print_name_info_result(
    result: Result<c_ares::NameInfoResult, c_ares::AresError>) {
    match result {
        Err(e) => {
            println!(
                "Name info lookup failed with error '{}'",
                e.description());
        }
        Ok(name_info_result) => {
            println!("Successful name info lookup...");
            println!("Node: {}", name_info_result.node().unwrap_or("<None>"));
            println!(
                "Service: {}",
                name_info_result.service().unwrap_or("<None>"));
        }
    }
}

pub fn main() {
    // Windows peculiarities.
    unsafe {
        let mut wsadata: WSADATA = mem::uninitialized();
        WSAStartup(0x101, &mut wsadata);
    }

    // Create the c_ares::Channel.
    let mut options = c_ares::Options::new();
    options
        .set_domains(&["example.com"])
        .set_flags(c_ares::flags::STAYOPEN)
        .set_timeout(500)
        .set_tries(3);
    let mut ares_channel = c_ares::Channel::new(options)
        .expect("Failed to create channel");
    ares_channel.set_servers(&["8.8.8.8"])
        .expect("Failed to set servers");

    // Set up some queries.
    ares_channel.query_soa("google.com", move |result| {
        println!("");
        print_soa_result(result);
    });

    let ipv4 = "192.168.3.11".parse::<Ipv4Addr>().unwrap();
    let sock = SocketAddr::V4(SocketAddrV4::new(ipv4, 80));
    ares_channel.get_name_info(
        &sock,
        c_ares::ni_flags::LOOKUPHOST | c_ares::ni_flags::LOOKUPSERVICE,
        move |result| {
            println!("");
            print_name_info_result(result);
        }
    );

    let ipv6 = "fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b".parse::<Ipv6Addr>().unwrap();
    let sock = SocketAddr::V6(SocketAddrV6::new(ipv6, 80, 0, 0));
    ares_channel.get_name_info(
        &sock,
        c_ares::ni_flags::LOOKUPHOST | c_ares::ni_flags::LOOKUPSERVICE,
        move |result| {
            println!("");
            print_name_info_result(result);
        }
    );

    // While c-ares wants us to listen for events, do so..
{'fraction_non_alphanumeric': 0.15505791505791505, 'fraction_numerical': 0.020694980694980696, 'mean_word_length': 2.4319024907260203, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '4310511', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2184, 'n_words': 408}