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