1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 #include "util.h" 19 20 #include <android-base/parseint.h> 21 #include <server_configurable_flags/get_flags.h> 22 23 using android::base::ParseInt; 24 using server_configurable_flags::GetServerConfigurableFlag; 25 sockaddrSize(const sockaddr * sa)26socklen_t sockaddrSize(const sockaddr* sa) { 27 if (sa == nullptr) return 0; 28 29 switch (sa->sa_family) { 30 case AF_INET: 31 return sizeof(sockaddr_in); 32 case AF_INET6: 33 return sizeof(sockaddr_in6); 34 default: 35 return 0; 36 } 37 } 38 sockaddrSize(const sockaddr_storage & ss)39socklen_t sockaddrSize(const sockaddr_storage& ss) { 40 return sockaddrSize(reinterpret_cast<const sockaddr*>(&ss)); 41 } 42 getExperimentFlagInt(const std::string & flagName,int defaultValue)43int getExperimentFlagInt(const std::string& flagName, int defaultValue) { 44 int val = defaultValue; 45 ParseInt(GetServerConfigurableFlag("netd_native", flagName, ""), &val); 46 return val; 47 } 48