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