libuv-dns

libuv dns example


更新記錄

item note
20160517 第一版

目錄


libuv dns

範例說明

範例內容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main() {
loop = uv_default_loop();

struct addrinfo hints;
hints.ai_family = PF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = 0;

uv_getaddrinfo_t resolver;
fprintf(stderr, "www.google.com is... ");
int r = uv_getaddrinfo(loop, &resolver, on_resolved, "www.google.com", "6667", &hints);

if (r) {
fprintf(stderr, "getaddrinfo call error %s\n", uv_err_name(r));
return 1;
}
return uv_run(loop, UV_RUN_DEFAULT);
}

範例測試

1
2
3
4
5
[ubuntu](master-48df99a)0h19m root@e8b0cd737680:[t09_dns]$ ./t09-main-ubuntu 
irc.freenode.net is... 130.239.18.119
:leguin.freenode.net NOTICE * :*** Looking up your hostname...
:leguin.freenode.net NOTICE * :*** Checking Ident
:leguin.freenode.net NOTICE * :*** Found your hostname
1
www.google.com is... 210.242.128.113

參考來源