/*
 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 * conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 * of conditions and the following disclaimer in the documentation and/or other materials
 * provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 * to endorse or promote products derived from this software without specific prior written
 * permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#include "lt_net_netdb.h"
// 引入头文件，可能包含了网络数据库相关的函数声明和宏定义。

static int NameInfoTest(void)
{
    char host[256], serv[256];
    // 定义两个数组，用于存储getnameinfo函数返回的主机名和服务器名。
    struct sockaddr_in addr;
    // 定义一个sockaddr_in结构体，用于存储IPv4地址信息。
    addr.sin_family = AF_INET;
    // 设置地址族为IPv4。
    addr.sin_port = htons(22);
    // 设置端口号为22（例如SSH端口），htons函数用于将主机字节序转换为网络字节序。
    addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    // 设置IP地址为127.0.0.1，inet_addr函数将点分十进制IP地址转换为网络字节序的整数。
    int ret = getnameinfo((struct sockaddr*)&addr, sizeof addr, host, sizeof host, serv, sizeof serv, 0);
    // 调用getnameinfo函数，传入地址信息、主机名和服务器名的缓冲区，尝试获取主机名和服务器名。
    ICUNIT_ASSERT_EQUAL(ret, 0, ret);
    // 断言getnameinfo函数调用成功，返回值为0。

    return ICUNIT_SUCCESS;
    // 返回测试成功。
}

void NetNetDbTest010(void)
{
    TEST_ADD_CASE(__FUNCTION__, NameInfoTest, TEST_POSIX, TEST_TCP, TEST_LEVEL0, TEST_FUNCTION);
}
// 定义测试用例，将NameInfoTest函数注册为一个测试案例。