1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <arpa/inet.h>
17 #include <netinet/in.h>
18 #include <netdb.h>
19 #include <sys/socket.h>
20 #include "functionalext.h"
21
22 /**
23 * @tc.name : gethostbyaddr_r_0100
24 * @tc.desc : Each parameter is valid, and multiple threads simultaneously obtain host information.
25 * @tc.level : Level 0
26 */
gethostbyaddr_r_0100(void)27 void gethostbyaddr_r_0100(void)
28 {
29 struct hostent h, *res = NULL;
30 char buf[8192] = {0};
31 int err = 0;
32 in_addr_t a = inet_addr("127.0.0.1");
33 int ret = gethostbyaddr_r((void *)&a, 4, AF_INET, &h, buf, sizeof(buf), &res, &err);
34 EXPECT_EQ("gethostbyaddr_r_0100", ret, 0);
35 EXPECT_TRUE("gethostbyaddr_r_0100", strcmp(h.h_name, "localhost") == 0);
36 }
37
38 /**
39 * @tc.name : gethostbyaddr_r_0200
40 * @tc.desc : Invalid parameter, failed to get host information.
41 * @tc.level : Level 2
42 */
gethostbyaddr_r_0200(void)43 void gethostbyaddr_r_0200(void)
44 {
45 struct hostent h, *res = NULL;
46 char buf[8192] = {0};
47 int err = 0;
48 in_addr_t a = inet_addr("127.0.0.1");
49 int ret = gethostbyaddr_r((void *)&a, 0, AF_INET, &h, buf, sizeof(buf), &res, &err);
50 EXPECT_NE("gethostbyaddr_r_0200", ret, 0);
51 }
52
main(int argc, char *argv[])53 int main(int argc, char *argv[])
54 {
55 gethostbyaddr_r_0100();
56 gethostbyaddr_r_0200();
57 return t_status;
58 }