1570af302Sopenharmony_ci/** 2570af302Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3570af302Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4570af302Sopenharmony_ci * you may not use this file except in compliance with the License. 5570af302Sopenharmony_ci * You may obtain a copy of the License at 6570af302Sopenharmony_ci * 7570af302Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8570af302Sopenharmony_ci * 9570af302Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10570af302Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11570af302Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12570af302Sopenharmony_ci * See the License for the specific language governing permissions and 13570af302Sopenharmony_ci * limitations under the License. 14570af302Sopenharmony_ci */ 15570af302Sopenharmony_ci 16570af302Sopenharmony_ci#include <netdb.h> 17570af302Sopenharmony_ci#include "functionalext.h" 18570af302Sopenharmony_ci#define FTP_PORT 21 19570af302Sopenharmony_ci#define HTTP_PORT 80 20570af302Sopenharmony_ci#define TCPMUX_PORT 1 21570af302Sopenharmony_ci#define FIDO_PORT 60179 22570af302Sopenharmony_ci#define NOT_EXIST_PORT 62000 23570af302Sopenharmony_ci 24570af302Sopenharmony_ci/** 25570af302Sopenharmony_ci * @tc.name : getservbyname_0100 26570af302Sopenharmony_ci * @tc.desc : Get service entry 27570af302Sopenharmony_ci * @tc.level : Level 0 28570af302Sopenharmony_ci */ 29570af302Sopenharmony_civoid getservbyname_0100(void) 30570af302Sopenharmony_ci{ 31570af302Sopenharmony_ci struct servent *se = getservbyname("smtp", "tcp"); 32570af302Sopenharmony_ci if (se) { 33570af302Sopenharmony_ci EXPECT_STREQ("getservbyname_0100", se->s_proto, "tcp"); 34570af302Sopenharmony_ci } 35570af302Sopenharmony_ci 36570af302Sopenharmony_ci se = getservbyname("echo", "udp"); 37570af302Sopenharmony_ci if (se) { 38570af302Sopenharmony_ci EXPECT_STREQ("getservbyname_0100", se->s_proto, "udp"); 39570af302Sopenharmony_ci } 40570af302Sopenharmony_ci} 41570af302Sopenharmony_ci 42570af302Sopenharmony_ci/** 43570af302Sopenharmony_ci * @tc.name : getservbyname_0200 44570af302Sopenharmony_ci * @tc.desc : Get the service information of the specified port 45570af302Sopenharmony_ci * @tc.level : Level 0 46570af302Sopenharmony_ci */ 47570af302Sopenharmony_civoid getservbyname_0200(void) 48570af302Sopenharmony_ci{ 49570af302Sopenharmony_ci struct servent *se = getservbyname("name", "proto"); 50570af302Sopenharmony_ci EXPECT_PTREQ("getservbyname_0200", se, NULL); 51570af302Sopenharmony_ci} 52570af302Sopenharmony_ci 53570af302Sopenharmony_ci/** 54570af302Sopenharmony_ci * @tc.name : getservbyname_0300 55570af302Sopenharmony_ci * @tc.desc : Get the service information of the specified port 56570af302Sopenharmony_ci * @tc.level : Level 0 57570af302Sopenharmony_ci*/ 58570af302Sopenharmony_civoid getservbyname_0300(void) 59570af302Sopenharmony_ci{ 60570af302Sopenharmony_ci struct servent *se = getservbyname("ftp", "tcp"); 61570af302Sopenharmony_ci EXPECT_PTRNE("getservbyname_0300", se, NULL); 62570af302Sopenharmony_ci EXPECT_EQ("getservbyname_0300", ntohs(se->s_port), FTP_PORT); 63570af302Sopenharmony_ci} 64570af302Sopenharmony_ci 65570af302Sopenharmony_ci/** 66570af302Sopenharmony_ci * @tc.name : getservbyname_0400 67570af302Sopenharmony_ci * @tc.desc : Get the service information of the specified port 68570af302Sopenharmony_ci * @tc.level : Level 0 69570af302Sopenharmony_ci*/ 70570af302Sopenharmony_civoid getservbyname_0400(void) 71570af302Sopenharmony_ci{ 72570af302Sopenharmony_ci struct servent *se = getservbyname("http", "tcp"); 73570af302Sopenharmony_ci EXPECT_PTRNE("getservbyname_0400", se, NULL); 74570af302Sopenharmony_ci EXPECT_EQ("getservbyname_0400", ntohs(se->s_port), HTTP_PORT); 75570af302Sopenharmony_ci} 76570af302Sopenharmony_ci 77570af302Sopenharmony_ci/** 78570af302Sopenharmony_ci * @tc.name : getservbyname_0500 79570af302Sopenharmony_ci * @tc.desc : Get the service information of the specified port 80570af302Sopenharmony_ci * @tc.level : Level 0 81570af302Sopenharmony_ci*/ 82570af302Sopenharmony_civoid getservbyname_0500(void) 83570af302Sopenharmony_ci{ 84570af302Sopenharmony_ci struct servent *se = getservbyname("tcpmux", "tcp"); 85570af302Sopenharmony_ci EXPECT_PTRNE("getservbyname_0500", se, NULL); 86570af302Sopenharmony_ci EXPECT_EQ("getservbyname_0500", ntohs(se->s_port), TCPMUX_PORT); 87570af302Sopenharmony_ci} 88570af302Sopenharmony_ci 89570af302Sopenharmony_ci/** 90570af302Sopenharmony_ci * @tc.name : getservbyname_0600 91570af302Sopenharmony_ci * @tc.desc : Get the service information of the specified port 92570af302Sopenharmony_ci * @tc.level : Level 0 93570af302Sopenharmony_ci*/ 94570af302Sopenharmony_civoid getservbyname_0600(void) 95570af302Sopenharmony_ci{ 96570af302Sopenharmony_ci struct servent *se = getservbyname("fido", "tcp"); 97570af302Sopenharmony_ci EXPECT_PTRNE("getservbyname_0600", se, NULL); 98570af302Sopenharmony_ci EXPECT_EQ("getservbyname_0600", ntohs(se->s_port), FIDO_PORT); 99570af302Sopenharmony_ci} 100570af302Sopenharmony_ci 101570af302Sopenharmony_ci/** 102570af302Sopenharmony_ci * @tc.name : getservbyname_0700 103570af302Sopenharmony_ci * @tc.desc : Get the service information of the specified port 104570af302Sopenharmony_ci * @tc.level : Level 0 105570af302Sopenharmony_ci*/ 106570af302Sopenharmony_civoid getservbyname_0700(void) 107570af302Sopenharmony_ci{ 108570af302Sopenharmony_ci struct servent *se = getservbyname("not_exist_service_name", "tcp"); 109570af302Sopenharmony_ci EXPECT_PTREQ("getservbyname_0700", se, NULL); 110570af302Sopenharmony_ci} 111570af302Sopenharmony_ci 112570af302Sopenharmony_ci 113570af302Sopenharmony_ciint main(void) 114570af302Sopenharmony_ci{ 115570af302Sopenharmony_ci getservbyname_0100(); 116570af302Sopenharmony_ci getservbyname_0200(); 117570af302Sopenharmony_ci getservbyname_0300(); 118570af302Sopenharmony_ci getservbyname_0400(); 119570af302Sopenharmony_ci getservbyname_0500(); 120570af302Sopenharmony_ci getservbyname_0600(); 121570af302Sopenharmony_ci getservbyname_0700(); 122570af302Sopenharmony_ci return t_status; 123570af302Sopenharmony_ci} 124