Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/shill_ares.h" |
| 6 | |
| 7 | namespace shill { |
| 8 | |
Ben Chan | bbdef5f | 2012-04-23 13:58:15 -0700 | [diff] [blame] | 9 | namespace { |
| 10 | base::LazyInstance<Ares> g_ares = LAZY_INSTANCE_INITIALIZER; |
| 11 | } // namespace |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 12 | |
| 13 | Ares::Ares() { } |
| 14 | |
| 15 | Ares::~Ares() { } |
| 16 | |
| 17 | Ares* Ares::GetInstance() { |
| 18 | return g_ares.Pointer(); |
| 19 | } |
| 20 | |
| 21 | void Ares::Destroy(ares_channel channel) { |
| 22 | ares_destroy(channel); |
| 23 | } |
| 24 | |
| 25 | void Ares::GetHostByName(ares_channel channel, |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 26 | const char* hostname, |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 27 | int family, |
| 28 | ares_host_callback callback, |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 29 | void* arg) { |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 30 | ares_gethostbyname(channel, hostname, family, callback, arg); |
| 31 | } |
| 32 | |
| 33 | int Ares::GetSock(ares_channel channel, |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 34 | ares_socket_t* socks, |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 35 | int numsocks) { |
| 36 | return ares_getsock(channel, socks, numsocks); |
| 37 | } |
| 38 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 39 | int Ares::InitOptions(ares_channel* channelptr, |
| 40 | struct ares_options* options, |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 41 | int optmask) { |
| 42 | return ares_init_options(channelptr, options, optmask); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | void Ares::ProcessFd(ares_channel channel, |
| 47 | ares_socket_t read_fd, |
| 48 | ares_socket_t write_fd) { |
| 49 | return ares_process_fd(channel, read_fd, write_fd); |
| 50 | } |
| 51 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 52 | void Ares::SetLocalDev(ares_channel channel, const char* local_dev_name) { |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 53 | ares_set_local_dev(channel, local_dev_name); |
| 54 | } |
| 55 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 56 | struct timeval* Ares::Timeout(ares_channel channel, |
| 57 | struct timeval* maxtv, |
| 58 | struct timeval* tv) { |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 59 | return ares_timeout(channel, maxtv, tv); |
| 60 | } |
| 61 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 62 | int Ares::SetServersCsv(ares_channel channel, const char* servers) { |
Peter Qiu | f3a8f90 | 2014-08-20 10:05:42 -0700 | [diff] [blame] | 63 | return ares_set_servers_csv(channel, servers); |
| 64 | } |
| 65 | |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 66 | } // namespace shill |