1 /* 2 * Copyright (C) 2010 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 #ifndef _DNSPROXYLISTENER_H__ 18 #define _DNSPROXYLISTENER_H__ 19 20 #include <resolv_netid.h> // struct android_net_context 21 #include <sysutils/FrameworkListener.h> 22 23 #include "NetdCommand.h" 24 25 class NetworkController; 26 27 class DnsProxyListener : public FrameworkListener { 28 public: 29 explicit DnsProxyListener(const NetworkController* netCtrl); ~DnsProxyListener()30 virtual ~DnsProxyListener() {} 31 32 private: 33 const NetworkController *mNetCtrl; 34 class GetAddrInfoCmd : public NetdCommand { 35 public: 36 GetAddrInfoCmd(const DnsProxyListener* dnsProxyListener); ~GetAddrInfoCmd()37 virtual ~GetAddrInfoCmd() {} 38 int runCommand(SocketClient *c, int argc, char** argv); 39 private: 40 const DnsProxyListener* mDnsProxyListener; 41 }; 42 43 class GetAddrInfoHandler { 44 public: 45 // Note: All of host, service, and hints may be NULL 46 GetAddrInfoHandler(SocketClient *c, 47 char* host, 48 char* service, 49 struct addrinfo* hints, 50 const struct android_net_context& netcontext); 51 ~GetAddrInfoHandler(); 52 53 static void* threadStart(void* handler); 54 void start(); 55 56 private: 57 void run(); 58 SocketClient* mClient; // ref counted 59 char* mHost; // owned 60 char* mService; // owned 61 struct addrinfo* mHints; // owned 62 struct android_net_context mNetContext; 63 }; 64 65 /* ------ gethostbyname ------*/ 66 class GetHostByNameCmd : public NetdCommand { 67 public: 68 GetHostByNameCmd(const DnsProxyListener* dnsProxyListener); ~GetHostByNameCmd()69 virtual ~GetHostByNameCmd() {} 70 int runCommand(SocketClient *c, int argc, char** argv); 71 private: 72 const DnsProxyListener* mDnsProxyListener; 73 }; 74 75 class GetHostByNameHandler { 76 public: 77 GetHostByNameHandler(SocketClient *c, 78 char *name, 79 int af, 80 unsigned netId, 81 uint32_t mark); 82 ~GetHostByNameHandler(); 83 static void* threadStart(void* handler); 84 void start(); 85 private: 86 void run(); 87 SocketClient* mClient; //ref counted 88 char* mName; // owned 89 int mAf; 90 unsigned mNetId; 91 uint32_t mMark; 92 }; 93 94 /* ------ gethostbyaddr ------*/ 95 class GetHostByAddrCmd : public NetdCommand { 96 public: 97 GetHostByAddrCmd(const DnsProxyListener* dnsProxyListener); ~GetHostByAddrCmd()98 virtual ~GetHostByAddrCmd() {} 99 int runCommand(SocketClient *c, int argc, char** argv); 100 private: 101 const DnsProxyListener* mDnsProxyListener; 102 }; 103 104 class GetHostByAddrHandler { 105 public: 106 GetHostByAddrHandler(SocketClient *c, 107 void* address, 108 int addressLen, 109 int addressFamily, 110 unsigned netId, 111 uint32_t mark); 112 ~GetHostByAddrHandler(); 113 114 static void* threadStart(void* handler); 115 void start(); 116 117 private: 118 void run(); 119 SocketClient* mClient; // ref counted 120 void* mAddress; // address to lookup; owned 121 int mAddressLen; // length of address to look up 122 int mAddressFamily; // address family 123 unsigned mNetId; 124 uint32_t mMark; 125 }; 126 }; 127 128 #endif 129