1 /* 2 * Copyright (c) 2021-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 "socket_remote_info.h" 17 18 #include "sys/socket.h" 19 #include <string> 20 21 namespace OHOS::NetStack::Socket { SocketRemoteInfo()22SocketRemoteInfo::SocketRemoteInfo() : port_(0), size_(0) {} 23 SetAddress(const std::string & address)24void SocketRemoteInfo::SetAddress(const std::string &address) 25 { 26 address_ = address; 27 } 28 SetFamily(sa_family_t family)29void SocketRemoteInfo::SetFamily(sa_family_t family) 30 { 31 if (family == AF_INET) { 32 family_ = "IPv4"; 33 } else if (family == AF_INET6) { 34 family_ = "IPv6"; 35 } else { 36 family_ = "Others"; 37 } 38 } 39 SetPort(uint16_t port)40void SocketRemoteInfo::SetPort(uint16_t port) 41 { 42 port_ = port; 43 } 44 SetSize(uint32_t size)45void SocketRemoteInfo::SetSize(uint32_t size) 46 { 47 size_ = size; 48 } 49 GetAddress() const50const std::string &SocketRemoteInfo::GetAddress() const 51 { 52 return address_; 53 } 54 GetFamily() const55const std::string &SocketRemoteInfo::GetFamily() const 56 { 57 return family_; 58 } 59 SetFamilyByStr(const std::string family)60void SocketRemoteInfo::SetFamilyByStr(const std::string family) 61 { 62 family_ = family; 63 } GetPort() const64uint16_t SocketRemoteInfo::GetPort() const 65 { 66 return port_; 67 } 68 GetSize() const69uint32_t SocketRemoteInfo::GetSize() const 70 { 71 return size_; 72 } 73 } // namespace OHOS::NetStack::Socket