예제 #1
0
파일: dns.c 프로젝트: 1060460048/tbox
/* //////////////////////////////////////////////////////////////////////////////////////
 * interfaces
 */
tb_bool_t tb_dns_init()
{
    // done
    tb_size_t count = 0;
    if (tb_file_info("/etc/resolv.conf", tb_null)) 
    {
        /* try get list from "/etc/resolv.conf"
         *
         * # Generated by NetworkManager
         * nameserver 10.1.20.10
         * nameserver 8.8.8.8
         *
         */
        tb_stream_ref_t stream = tb_stream_init_from_url("/etc/resolv.conf");
        if (stream)
        {
            // open
            if (tb_stream_open(stream)) 
            {
                // read
                tb_long_t size = 0;
                tb_char_t line[8192];
                while ((size = tb_stream_bread_line(stream, line, 8192)) >= 0)
                {
                    if (size && !tb_strnicmp(line, "nameserver", 10))
                    {
                        // seek to server
                        tb_char_t const* p = line + 10;
                        while (*p && !tb_isdigit(*p)) p++;
                        tb_check_continue(*p);

                        // add server
                        tb_dns_server_add(p);

                        // count++
                        count++;
                    }
                }
            }
    
            // exit
            tb_stream_exit(stream);
        }
    }

    // no server? add the default server
    if (!count) 
    {
        tb_dns_server_add("8.8.8.8");
        tb_dns_server_add("8.8.8.4");
    }

    // ok
    return tb_true;
}
예제 #2
0
파일: dns.c 프로젝트: siwuxian/xmake
/* //////////////////////////////////////////////////////////////////////////////////////
 * interfaces
 */
tb_bool_t tb_dns_init_env()
{
    // done
    tb_size_t   count = 0;
    tb_handle_t library = tb_dynamic_init("libresolv.dylib");
    if (library) 
    {
        // the res_ninit func
        tb_dns_res_ninit_func_t pres_ninit = (tb_dns_res_ninit_func_t)tb_dynamic_func(library, "res_9_ninit");
        if (pres_ninit)
        {
            // init state
            struct __res_state state;
            if (!pres_ninit(&state))
            {
                // walk it
                tb_size_t i = 0;
                for (i = 0; i < state.nscount; i++, count++)
                {
                    // the address
                    tb_char_t const* addr = inet_ntoa(state.nsaddr_list[i].sin_addr);
                    tb_assert_and_check_continue(addr);

                    // trace
                    tb_trace_d("addr: %s", addr);

                    // add address
                    tb_dns_server_add(addr);
                }
            }
        }
    }

    // ok
    return tb_true;
}
예제 #3
0
파일: dns.c 프로젝트: AlexShiLucky/tbox
/* //////////////////////////////////////////////////////////////////////////////////////
 * main
 */ 
tb_int_t tb_demo_network_dns_main(tb_int_t argc, tb_char_t** argv)
{
    // test the invalid host
#if TB_DNS_TEST_INVALID_HOST
    // add not dns host
    tb_dns_server_add("127.0.0.1");

    // add not ipv4 host
    tb_dns_server_add("localhost");

#endif

    // test the more host
#if TB_DNS_TEST_MORE_HOST
    tb_dns_server_add("2001:470:20::2");
    tb_dns_server_add("fec0:0:0:ffff::1%1");
    tb_dns_server_add("205.252.144.228");
    tb_dns_server_add("208.151.69.65");
    tb_dns_server_add("202.181.202.140");
    tb_dns_server_add("202.181.224.2");
    tb_dns_server_add("202.175.3.8");
    tb_dns_server_add("202.175.3.3");
    tb_dns_server_add("168.95.192.1");
    tb_dns_server_add("168.95.1.1");
    tb_dns_server_add("208.67.222.222");
    tb_dns_server_add("205.171.2.65");
    tb_dns_server_add("193.0.14.129");
    tb_dns_server_add("202.12.27.33");
    tb_dns_server_add("202.216.228.18");
    tb_dns_server_add("209.166.160.132");
    tb_dns_server_add("208.96.10.221");
    tb_dns_server_add("61.144.56.101");
    tb_dns_server_add("202.101.98.55");
    tb_dns_server_add("202.96.128.166");
    tb_dns_server_add("202.96.209.134");
    tb_dns_server_add("221.12.65.228");
#endif

    // sort
    tb_dns_server_sort();

    // dump
#ifdef __tb_debug__
    tb_dns_server_dump();
#endif

#if TB_DNS_TEST_HOST_SOME
    tb_hong_t time = tb_mclock();
    tb_dns_test_done("www.tboox.org");
    tb_dns_test_done("www.tboox.net");
    tb_dns_test_done("www.baidu.com");
    tb_dns_test_done("www.google.com");
    tb_dns_test_done("www.google.com.hk");
    tb_dns_test_done("www.csdn.net");
    tb_dns_test_done("www.qq.com");
    tb_dns_test_done("www.youku.com");
    tb_dns_test_done("www.ibm.com");
    tb_dns_test_done("www.sina.com.cn");
    tb_dns_test_done("www.hao123.com");
    tb_dns_test_done("www.sohu.com");
    tb_dns_test_done("www.weibo.com");
    tb_dns_test_done("www.126.com");
    tb_dns_test_done("www.163.com");
    tb_dns_test_done("www.taobao.com");
    tb_dns_test_done("www.microsoft.com");
    tb_dns_test_done("www.qiyi.com");
    tb_dns_test_done("www.xunlei.com");
    tb_dns_test_done("www.360buy.com");
    tb_dns_test_done("www.tudou.com");
    tb_dns_test_done("www.pps.tv");
    tb_dns_test_done("www.yahoo.com");
    tb_dns_test_done("www.zol.com.cn");
    tb_dns_test_done("www.download.com");
    tb_dns_test_done("www.webkit.org");
    tb_dns_test_done("www.douban.com");
    tb_dns_test_done("www.github.com");
    tb_dns_test_done("www.videolan.org");
    tb_dns_test_done("www.net.cn");
    tb_dns_test_done("www.yahoo.com");
    tb_dns_test_done("www.sina.com.cn");
    tb_dns_test_done("www.hao123.com");
    tb_dns_test_done("www.sohu.com");
    tb_dns_test_done("www.weibo.com");
    tb_dns_test_done("www.126.com");
    tb_dns_test_done("www.163.com");
    tb_dns_test_done("www.taobao.com");
    tb_dns_test_done("www.microsoft.com");
    tb_dns_test_done("www.qiyi.com");
    tb_dns_test_done("www.xunlei.com");
    tb_dns_test_done("www.360buy.com");
    tb_dns_test_done("www.tudou.com");
    tb_dns_test_done("www.pps.tv");
    tb_dns_test_done("www.yahoo.com");
    tb_dns_test_done("www.zol.com.cn");
    tb_dns_test_done("www.download.com");
    tb_dns_test_done("www.webkit.org");
    tb_dns_test_done("www.huaxiazi.com");
    tb_dns_test_done("www.facebook.com");
    tb_dns_test_done("www.youtube.com");
    tb_dns_test_done("www.bing.com");
    tb_dns_test_done("www.baidu.com");
    tb_dns_test_done("www.tianya.com");
    tb_dns_test_done("www.adobe.com");
    tb_dns_test_done("web2.qq.com");
    tb_dns_test_done("www.bluehost.com");
    tb_dns_test_done("www.pediy.com");
    tb_dns_test_done("www.wordpress.com");
    tb_dns_test_done("www.gitorious.org");
    tb_dns_test_done("t.qq.com");
    tb_dns_test_done("www.wordpress.com");
    tb_dns_test_done("www.mop.com");
    tb_dns_test_done("www.56.com");
    tb_dns_test_done("www.joy.com.cn");
    tb_dns_test_done("www.xxxxx.com");
    tb_dns_test_done("www.wordpress.com");
    tb_dns_test_done("developer.android.com");
    tb_dns_test_done("developer.apple.com");
    tb_dns_test_done("www.arm.com");
    tb_dns_test_done("www.nginx.com");
    tb_dns_test_done("www.ted.com");
    tb_dns_test_done("www.tboox.org");
    tb_dns_test_done("www.tboox.net");
    tb_dns_test_done("www.baidu.com");
    tb_dns_test_done("www.google.com");
    tb_dns_test_done("www.google.com.hk");
    tb_dns_test_done("www.csdn.net");
    tb_dns_test_done("www.qq.com");
    tb_dns_test_done("www.youku.com");
    tb_dns_test_done("www.ibm.com");
    tb_dns_test_done("www.sina.com.cn");
    tb_dns_test_done("www.hao123.com");
    tb_dns_test_done("www.sohu.com");
    tb_dns_test_done("www.weibo.com");
    tb_dns_test_done("www.126.com");
    tb_dns_test_done("www.163.com");
    tb_dns_test_done("www.taobao.com");
    tb_dns_test_done("www.microsoft.com");
    tb_dns_test_done("www.qiyi.com");
    tb_dns_test_done("www.xunlei.com");
    tb_dns_test_done("www.360buy.com");
    tb_dns_test_done("www.tudou.com");
    tb_dns_test_done("www.pps.tv");
    tb_dns_test_done("www.yahoo.com");
    tb_dns_test_done("www.zol.com.cn");
    tb_dns_test_done("www.download.com");
    tb_dns_test_done("www.webkit.org");
    tb_dns_test_done("www.douban.com");
    tb_dns_test_done("www.github.com");
    tb_dns_test_done("www.videolan.org");
    tb_dns_test_done("www.net.cn");
    tb_dns_test_done("www.yahoo.com");
    tb_dns_test_done("www.sina.com.cn");
    tb_dns_test_done("www.hao123.com");
    tb_dns_test_done("www.sohu.com");
    tb_dns_test_done("www.weibo.com");
    tb_dns_test_done("www.126.com");
    tb_dns_test_done("www.163.com");
    tb_dns_test_done("www.taobao.com");
    tb_dns_test_done("www.microsoft.com");
    tb_dns_test_done("www.qiyi.com");
    tb_dns_test_done("www.xunlei.com");
    tb_dns_test_done("www.360buy.com");
    tb_dns_test_done("www.tudou.com");
    tb_dns_test_done("www.pps.tv");
    tb_dns_test_done("www.yahoo.com");
    tb_dns_test_done("www.zol.com.cn");
    tb_dns_test_done("www.download.com");
    tb_dns_test_done("www.webkit.org");
    tb_dns_test_done("www.huaxiazi.com");
    tb_dns_test_done("www.facebook.com");
    tb_dns_test_done("www.youtube.com");
    tb_dns_test_done("www.bing.com");
    tb_dns_test_done("www.baidu.com");
    tb_dns_test_done("www.tianya.com");
    tb_dns_test_done("www.adobe.com");
    tb_dns_test_done("web2.qq.com");
    tb_dns_test_done("www.bluehost.com");
    tb_dns_test_done("www.pediy.com");
    tb_dns_test_done("www.wordpress.com");
    tb_dns_test_done("www.gitorious.org");
    tb_dns_test_done("t.qq.com");
    tb_dns_test_done("www.wordpress.com");
    tb_dns_test_done("www.mop.com");
    tb_dns_test_done("www.56.com");
    tb_dns_test_done("www.joy.com.cn");
    tb_dns_test_done("www.xxxxx.com");
    tb_dns_test_done("www.wordpress.com");
    tb_dns_test_done("developer.android.com");
    tb_dns_test_done("developer.apple.com");
    tb_dns_test_done("www.arm.com");
    tb_dns_test_done("www.nginx.com");
    tb_dns_test_done("www.ted.com");
    tb_dns_test_done("www.mcu-memory.com");
    tb_dns_test_done("mail.126.com");
    tb_dns_test_done("mail.163.com");
    tb_dns_test_done("mail.google.com");
    tb_dns_test_done("mail.qq.com");
    tb_dns_test_done("mail.sina.com");
    tb_dns_test_done("mail.sohu.com");
    tb_dns_test_done("mail.qq.com");
    tb_dns_test_done("www.renren.com");
    tb_dns_test_done("www.cepark.com");
    tb_dns_test_done("www.ifttt.com");
    tb_dns_test_done("www.china-pub.com");
    tb_dns_test_done("www.amazon.com");
    tb_dns_test_done("www.amazon.cn");
    tb_dns_test_done("www.2688.com");
    tb_dns_test_done("www.mtime.com");
    tb_dns_test_done("hi.baidu.com");
    tb_dns_test_done("repo.or.cz");
    tb_dns_test_done("www.ifeng.com");
    tb_dns_test_done("www.sourceforge.com");
    tb_dns_test_done("www.wikipedia.org");
    tb_dns_test_done("baike.baidu.com");
    tb_dns_test_done("www.ted.com");
    tb_dns_test_done("www.ted.com");
    tb_dns_test_done("www.ted.com");
    time = tb_mclock() - time;
    tb_trace_i("[demo]: done %lld ms", time);
#else
    tb_dns_test_done(argv[1]);
#endif

    return 0;
}