• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <netdb.h>
17 #include "functionalext.h"
18 
19 #define TEST_GET_SEVERBY_TCP_PORT 25
20 #define TEST_GET_SEVERBY_UDP_PORT 7
21 /**
22  * @tc.name      : getservbyport_0100
23  * @tc.desc      : Get the service information of the specified port
24  * @tc.level     : Level 0
25  */
getservbyport_0100(void)26 void getservbyport_0100(void)
27 {
28     struct servent *se = getservbyport(htons(TEST_GET_SEVERBY_TCP_PORT), NULL);
29     if (se) {
30         EXPECT_EQ("getservbyport_0100", ntohs(se->s_port), TEST_GET_SEVERBY_TCP_PORT);
31         EXPECT_STREQ("getservbyport_0100", se->s_proto, "tcp");
32     }
33 
34     se = getservbyport(htons(TEST_GET_SEVERBY_TCP_PORT), "tcp");
35     if (se) {
36         EXPECT_EQ("getservbyport_0100", ntohs(se->s_port), TEST_GET_SEVERBY_TCP_PORT);
37         EXPECT_STREQ("getservbyport_0100", se->s_proto, "tcp");
38     }
39 
40     se = getservbyport(htons(TEST_GET_SEVERBY_UDP_PORT), "udp");
41     if (se) {
42         EXPECT_EQ("getservbyport_0100", ntohs(se->s_port), TEST_GET_SEVERBY_UDP_PORT);
43         EXPECT_STREQ("getservbyport_0100", se->s_proto, "udp");
44     }
45 }
46 
main(void)47 int main(void)
48 {
49     getservbyport_0100();
50     return t_status;
51 }