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 #ifndef COMMUNICATIONNETSTACK_NET_ADDRESS_H 17 #define COMMUNICATIONNETSTACK_NET_ADDRESS_H 18 19 #include <arpa/inet.h> 20 #include <string> 21 22 namespace OHOS::NetStack { 23 class NetAddress final { 24 public: 25 enum class Family : uint32_t { 26 IPv4 = 1, 27 IPv6 = 2, 28 }; 29 30 NetAddress(); 31 32 ~NetAddress() = default; 33 34 void SetAddress(const std::string &address); 35 36 void SetFamilyByJsValue(uint32_t family); 37 38 void SetFamilyBySaFamily(sa_family_t family); 39 40 void SetPort(uint16_t port); 41 42 [[nodiscard]] const std::string &GetAddress() const; 43 44 [[nodiscard]] uint32_t GetJsValueFamily() const; 45 46 [[nodiscard]] sa_family_t GetSaFamily() const; 47 48 [[nodiscard]] uint16_t GetPort() const; 49 50 private: 51 std::string address_; 52 53 Family family_; 54 55 uint16_t port_; 56 }; 57 } // namespace OHOS::NetStack 58 59 #endif /* COMMUNICATIONNETSTACK_NET_ADDRESS_H */ 60