189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk/* 289c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * Copyright (C) 2011 The Android Open Source Project 389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * 489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * Licensed under the Apache License, Version 2.0 (the "License"); 589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * you may not use this file except in compliance with the License. 689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * You may obtain a copy of the License at 789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * 889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * http://www.apache.org/licenses/LICENSE-2.0 989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * 1089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * Unless required by applicable law or agreed to in writing, software 1189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * distributed under the License is distributed on an "AS IS" BASIS, 1289c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * See the License for the specific language governing permissions and 1489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * limitations under the License. 1589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk */ 1689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 1789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk#define LOG_TAG "ResolverController" 1889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk#define DBG 0 1989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 2089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk#include <cutils/log.h> 2189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 22970274a61800e047430d81269df977de9dbe45efElliott Hughes#include <net/if.h> 234da10dd08f12002c3821c5d4ceba302daae33e03David 'Digit' Turner 244da10dd08f12002c3821c5d4ceba302daae33e03David 'Digit' Turner// NOTE: <resolv_iface.h> is a private C library header that provides 254da10dd08f12002c3821c5d4ceba302daae33e03David 'Digit' Turner// declarations for _resolv_set_default_iface() and others. 264da10dd08f12002c3821c5d4ceba302daae33e03David 'Digit' Turner#include <resolv_iface.h> 2789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 2889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk#include "ResolverController.h" 2989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 3089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falkint ResolverController::setDefaultInterface(const char* iface) { 3189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk if (DBG) { 327b984e3f7e724f8a3547a707210319f3d479f261Steve Block ALOGD("setDefaultInterface iface = %s\n", iface); 3389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk } 3489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 3589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk _resolv_set_default_iface(iface); 3689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 3789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk return 0; 3889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk} 3989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 4089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falkint ResolverController::setInterfaceDnsServers(const char* iface, char** servers, int numservers) { 4189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk if (DBG) { 427b984e3f7e724f8a3547a707210319f3d479f261Steve Block ALOGD("setInterfaceDnsServers iface = %s\n", iface); 4389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk } 4489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 4589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk _resolv_set_nameservers_for_iface(iface, servers, numservers); 4689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 4789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk return 0; 4889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk} 4989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 5089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falkint ResolverController::setInterfaceAddress(const char* iface, struct in_addr* addr) { 5189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk if (DBG) { 527b984e3f7e724f8a3547a707210319f3d479f261Steve Block ALOGD("setInterfaceAddress iface = %s\n", iface); 5389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk } 5489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 5589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk _resolv_set_addr_of_iface(iface, addr); 5689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 5789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk return 0; 5889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk} 5989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 6089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falkint ResolverController::flushDefaultDnsCache() { 6189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk if (DBG) { 627b984e3f7e724f8a3547a707210319f3d479f261Steve Block ALOGD("flushDefaultDnsCache\n"); 6389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk } 6489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 6589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk _resolv_flush_cache_for_default_iface(); 6689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 6789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk return 0; 6889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk} 6989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 7089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falkint ResolverController::flushInterfaceDnsCache(const char* iface) { 7189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk if (DBG) { 727b984e3f7e724f8a3547a707210319f3d479f261Steve Block ALOGD("flushInterfaceDnsCache iface = %s\n", iface); 7389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk } 7489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 7589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk _resolv_flush_cache_for_iface(iface); 7689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk 7789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk return 0; 7889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk} 79