blob: 1e06940be74f84f1227f48d5efd6cb90b83a0530 [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef RTC_BASE_NET_HELPERS_H_
12#define RTC_BASE_NET_HELPERS_H_
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020014#if defined(WEBRTC_POSIX)
Yves Gerey988cc082018-10-23 12:03:01 +020015#include <sys/socket.h>
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020016#elif WEBRTC_WIN
17#include <winsock2.h> // NOLINT
18#endif
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000019
Yves Gerey2e00abc2018-10-05 15:39:24 +020020#include <vector>
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020021
Steve Anton10542f22019-01-11 09:11:00 -080022#include "rtc_base/async_resolver_interface.h"
23#include "rtc_base/ip_address.h"
24#include "rtc_base/signal_thread.h"
25#include "rtc_base/socket_address.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020026#include "rtc_base/system/rtc_export.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020027
28namespace rtc {
29
deadbeef8290ddf2017-07-11 16:56:05 -070030// AsyncResolver will perform async DNS resolution, signaling the result on
31// the SignalDone from AsyncResolverInterface when the operation completes.
Mirko Bonadei35214fc2019-09-23 14:54:28 +020032class RTC_EXPORT AsyncResolver : public SignalThread,
33 public AsyncResolverInterface {
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020034 public:
35 AsyncResolver();
36 ~AsyncResolver() override;
37
38 void Start(const SocketAddress& addr) override;
39 bool GetResolvedAddress(int family, SocketAddress* addr) const override;
40 int GetError() const override;
41 void Destroy(bool wait) override;
42
43 const std::vector<IPAddress>& addresses() const { return addresses_; }
deadbeef8290ddf2017-07-11 16:56:05 -070044 void set_error(int error) { error_ = error; }
45
46 protected:
47 void DoWork() override;
48 void OnWorkDone() override;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020049
50 private:
51 SocketAddress addr_;
52 std::vector<IPAddress> addresses_;
deadbeef8290ddf2017-07-11 16:56:05 -070053 int error_;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020054};
55
56// rtc namespaced wrappers for inet_ntop and inet_pton so we can avoid
57// the windows-native versions of these.
Yves Gerey665174f2018-06-19 15:03:05 +020058const char* inet_ntop(int af, const void* src, char* dst, socklen_t size);
59int inet_pton(int af, const char* src, void* dst);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020060
61bool HasIPv4Enabled();
62bool HasIPv6Enabled();
63} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000064
Steve Anton10542f22019-01-11 09:11:00 -080065#endif // RTC_BASE_NET_HELPERS_H_