2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _DNSPROXYLISTENER_H__
18 #define _DNSPROXYLISTENER_H__
20 #include <sysutils/FrameworkListener.h>
22 #include "NetdCommand.h"
24 class NetworkController;
25 class PermissionsController;
27 class DnsProxyListener : public FrameworkListener {
29 DnsProxyListener(const NetworkController* netCtrl, const PermissionsController* permCtrl);
30 virtual ~DnsProxyListener() {}
33 const NetworkController *mNetCtrl;
34 const PermissionsController *mPermCtrl;
35 class GetAddrInfoCmd : public NetdCommand {
37 GetAddrInfoCmd(const DnsProxyListener* dnsProxyListener);
38 virtual ~GetAddrInfoCmd() {}
39 int runCommand(SocketClient *c, int argc, char** argv);
41 const DnsProxyListener* mDnsProxyListener;
44 class GetAddrInfoHandler {
46 // Note: All of host, service, and hints may be NULL
47 GetAddrInfoHandler(SocketClient *c,
50 struct addrinfo* hints,
53 ~GetAddrInfoHandler();
55 static void* threadStart(void* handler);
60 SocketClient* mClient; // ref counted
62 char* mService; // owned
63 struct addrinfo* mHints; // owned
68 /* ------ gethostbyname ------*/
69 class GetHostByNameCmd : public NetdCommand {
71 GetHostByNameCmd(const DnsProxyListener* dnsProxyListener);
72 virtual ~GetHostByNameCmd() {}
73 int runCommand(SocketClient *c, int argc, char** argv);
75 const DnsProxyListener* mDnsProxyListener;
78 class GetHostByNameHandler {
80 GetHostByNameHandler(SocketClient *c,
85 ~GetHostByNameHandler();
86 static void* threadStart(void* handler);
90 SocketClient* mClient; //ref counted
97 /* ------ gethostbyaddr ------*/
98 class GetHostByAddrCmd : public NetdCommand {
100 GetHostByAddrCmd(const DnsProxyListener* dnsProxyListener);
101 virtual ~GetHostByAddrCmd() {}
102 int runCommand(SocketClient *c, int argc, char** argv);
104 const DnsProxyListener* mDnsProxyListener;
107 class GetHostByAddrHandler {
109 GetHostByAddrHandler(SocketClient *c,
115 ~GetHostByAddrHandler();
117 static void* threadStart(void* handler);
122 SocketClient* mClient; // ref counted
123 void* mAddress; // address to lookup; owned
124 int mAddressLen; // length of address to look up
125 int mAddressFamily; // address family
130 // Calculate the socket mark to use for a DNS resolution.
131 uint32_t calcMark(SocketClient *c, unsigned netId) const;