1 /* 2 * Copyright (c) 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 COMMUNICATION_NETMANAGER_BASE_DNS_CONFIG_CLIENT_H 17 #define COMMUNICATION_NETMANAGER_BASE_DNS_CONFIG_CLIENT_H 18 19 #include <arpa/inet.h> 20 #include <netdb.h> 21 #include <stdint.h> 22 23 #include "securec.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #if DNS_CONFIG_DEBUG 30 #ifndef DNS_CONFIG_PRINT 31 #define DNS_CONFIG_PRINT(fmt, ...) printf("DNS" fmt "\n", ##__VA_ARGS__) 32 #endif 33 #else 34 #define DNS_CONFIG_PRINT(fmt, ...) 35 #endif 36 37 #define MAX_SERVER_NUM 4 38 #define MAX_SERVER_LENGTH 50 39 #define DNS_SOCKET_PATH "/dev/unix/socket/dnsproxyd" 40 #define DNS_SOCKET_NAME "dnsproxyd" 41 #define MAX_RESULTS 32 42 #define MAX_CANON_NAME 256 43 #define MAX_HOST_NAME_LEN 256 44 #define MAX_KEY_LENGTH (MAX_HOST_NAME_LEN + 1 + MAX_SERVER_LENGTH + 1 + sizeof(uint32_t) * 4 + 3 + 1) 45 #define DEFAULT_TIMEOUT 5000 46 #define DEFAULT_RETRY 2 47 #define DEFAULT_SERVER_LENTH 16 48 #define DEFAULT_SERVER_NAME 114 49 50 enum CommandType { GET_CONFIG = 1, GET_CACHE = 2, SET_CACHE = 3 }; 51 52 struct RequestInfo { 53 uint32_t command; 54 uint32_t netId; 55 }; 56 57 struct ResolvConfig { 58 int32_t error; 59 int32_t timeoutMs; 60 uint32_t retryCount; 61 char nameservers[MAX_SERVER_NUM][MAX_SERVER_LENGTH + 1]; 62 }; 63 64 typedef union { 65 struct sockaddr sa; 66 struct sockaddr_in6 sin6; 67 struct sockaddr_in sin; 68 } AlignedSockAddr; 69 70 struct AddrInfo { 71 uint32_t aiFlags; 72 uint32_t aiFamily; 73 uint32_t aiSockType; 74 uint32_t aiProtocol; 75 uint32_t aiAddrLen; 76 AlignedSockAddr aiAddr; 77 char aiCanonName[MAX_CANON_NAME + 1]; 78 }; 79 80 struct ParamWrapper { 81 char *host; 82 char *serv; 83 struct addrinfo *hint; 84 }; 85 86 #ifdef __cplusplus 87 } 88 #endif 89 #endif // COMMUNICATION_NETMANAGER_BASE_1_DNS_CONFIG_CLIENT_H 90