1 /* 2 * Copyright (c) 2025 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 COMMUNICATION_NETSTACK_SOCKS5_UTILS_H 17 #define COMMUNICATION_NETSTACK_SOCKS5_UTILS_H 18 19 #include <thread> 20 #include <memory> 21 #include <string> 22 #include <sys/socket.h> 23 24 #include "net_address.h" 25 #include "socks5.h" 26 #include "socks5_instance.h" 27 #include "socks5_package.h" 28 29 namespace OHOS { 30 namespace NetStack { 31 namespace Socks5 { 32 class Socks5Utils { 33 public: 34 static socklen_t GetAddressLen(const Socket::NetAddress &netAddress); 35 static bool Send(int32_t socketId, const char *data, size_t size, sockaddr *addr, socklen_t addrLen); 36 static std::pair<bool, Socks5Buffer> Recv(int32_t socketId, sockaddr *addr, socklen_t addrLen); 37 static bool RequestProxyServer(std::shared_ptr<Socks5Instance> &socks5Inst, std::int32_t socketId, 38 const std::pair<sockaddr *, socklen_t> &addrInfo, Socks5Request *req, Socks5Response *rsp); 39 static std::string GetStatusMessage(Socks5Status status); 40 static void PrintRecvErrMsg(int32_t socketId, const int32_t errCode, const int32_t recvLen, 41 const std::string &tag); 42 static void SetProxyAuthError(BaseContext *context, std::shared_ptr<Socks5::Socks5Instance> &socks5Inst); 43 }; 44 } // Socks5 45 } // NetStack 46 } // OHOS 47 #endif // COMMUNICATION_NETSTACK_SOCKS5_UTILS_H