summaryrefslogtreecommitdiffstats
path: root/src/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/nslookup.c
blob: 37150f1eb7fe73bd883ecc81761519d0714df532 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 */

#include <assert.h>
#include <string.h>
#ifdef __wasi__
#include <wasi/api.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <wasi_socket_ext.h>
#else
#include <netdb.h>
#endif

void
test_nslookup(int af)
{
    struct addrinfo *res;
    int count = 0;
    struct addrinfo hints;
    char *url = "google-public-dns-a.google.com";

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = af;
    hints.ai_socktype = SOCK_STREAM;
    int ret = getaddrinfo(url, 0, &hints, &res);
    assert(ret == 0);
    struct addrinfo *address = res;
    while (address) {
        assert(address->ai_family == af);
        assert(address->ai_socktype == SOCK_STREAM);
        count++;
        address = address->ai_next;
    }

    assert(count > 0);
    freeaddrinfo(res);
}

int
main()
{
    test_nslookup(AF_INET);  /* for ipv4 */
    test_nslookup(AF_INET6); /* for ipv6 */

    return 0;
}