blob: e118b27dbc0b9cd18e4c869407b3e574afffcce3 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_BASE_NETHELPERS_H_
12#define RTC_BASE_NETHELPERS_H_
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020014#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.orgf0488722014-05-13 18:00:26 +000020
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020021#include <list>
22
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/asyncresolverinterface.h"
24#include "rtc_base/signalthread.h"
25#include "rtc_base/sigslot.h"
26#include "rtc_base/socketaddress.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020027
28namespace rtc {
29
deadbeef8290ddf2017-07-11 16:56:05 -070030class AsyncResolverTest;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020031
deadbeef8290ddf2017-07-11 16:56:05 -070032// 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 Kjellanderec78f1c2017-06-29 07:52:50 +020035 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_; }
deadbeef8290ddf2017-07-11 16:56:05 -070045 void set_error(int error) { error_ = error; }
46
47 protected:
48 void DoWork() override;
49 void OnWorkDone() override;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020050
51 private:
52 SocketAddress addr_;
53 std::vector<IPAddress> addresses_;
deadbeef8290ddf2017-07-11 16:56:05 -070054 int error_;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020055};
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.orgf0488722014-05-13 18:00:26 +000065
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020066#endif // RTC_BASE_NETHELPERS_H_