blob: d25879e78599820840063e1df77205717b03d253 [file] [log] [blame]
henrike@webrtc.org47be73b2014-05-13 18:00:261/*
2 * Copyright 2008 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Henrik Kjellanderfb3e1b62017-06-29 06:03:0411#ifndef WEBRTC_RTC_BASE_NETHELPERS_H_
12#define WEBRTC_RTC_BASE_NETHELPERS_H_
henrike@webrtc.org47be73b2014-05-13 18:00:2613
Henrik Kjellander88b2dd42017-06-29 05:52:5014#if defined(WEBRTC_POSIX)
15#include <netdb.h>
16#include <stddef.h>
17#elif WEBRTC_WIN
18#include <winsock2.h> // NOLINT
19#endif
henrike@webrtc.org47be73b2014-05-13 18:00:2620
Henrik Kjellander88b2dd42017-06-29 05:52:5021#include <list>
22
kjellander19796962017-06-30 17:45:2123#include "webrtc/rtc_base/asyncresolverinterface.h"
deadbeef23379702017-07-11 23:56:0524#include "webrtc/rtc_base/signalthread.h"
kjellander19796962017-06-30 17:45:2125#include "webrtc/rtc_base/sigslot.h"
26#include "webrtc/rtc_base/socketaddress.h"
Henrik Kjellander88b2dd42017-06-29 05:52:5027
28namespace rtc {
29
deadbeef23379702017-07-11 23:56:0530class AsyncResolverTest;
Henrik Kjellander88b2dd42017-06-29 05:52:5031
deadbeef23379702017-07-11 23:56:0532// AsyncResolver will perform async DNS resolution, signaling the result on
33// the SignalDone from AsyncResolverInterface when the operation completes.
34class AsyncResolver : public SignalThread, public AsyncResolverInterface {
Henrik Kjellander88b2dd42017-06-29 05:52:5035 public:
36 AsyncResolver();
37 ~AsyncResolver() override;
38
39 void Start(const SocketAddress& addr) override;
40 bool GetResolvedAddress(int family, SocketAddress* addr) const override;
41 int GetError() const override;
42 void Destroy(bool wait) override;
43
44 const std::vector<IPAddress>& addresses() const { return addresses_; }
deadbeef23379702017-07-11 23:56:0545 void set_error(int error) { error_ = error; }
46
47 protected:
48 void DoWork() override;
49 void OnWorkDone() override;
Henrik Kjellander88b2dd42017-06-29 05:52:5050
51 private:
52 SocketAddress addr_;
53 std::vector<IPAddress> addresses_;
deadbeef23379702017-07-11 23:56:0554 int error_;
Henrik Kjellander88b2dd42017-06-29 05:52:5055};
56
57// rtc namespaced wrappers for inet_ntop and inet_pton so we can avoid
58// the windows-native versions of these.
59const char* inet_ntop(int af, const void *src, char* dst, socklen_t size);
60int inet_pton(int af, const char* src, void *dst);
61
62bool HasIPv4Enabled();
63bool HasIPv6Enabled();
64} // namespace rtc
henrike@webrtc.org47be73b2014-05-13 18:00:2665
Henrik Kjellanderfb3e1b62017-06-29 06:03:0466#endif // WEBRTC_RTC_BASE_NETHELPERS_H_