blob: 6f753180fd1d2d1e3aabb29d8a9b57984774fa0f [file] [log] [blame]
henrike@webrtc.orgf0488722014-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
Steve Anton10542f22019-01-11 17:11:0011#ifndef RTC_BASE_NET_HELPERS_H_
12#define RTC_BASE_NET_HELPERS_H_
henrike@webrtc.orgf0488722014-05-13 18:00:2613
Henrik Kjellanderec78f1c2017-06-29 05:52:5014#if defined(WEBRTC_POSIX)
Yves Gerey988cc082018-10-23 10:03:0115#include <sys/socket.h>
Henrik Kjellanderec78f1c2017-06-29 05:52:5016#elif WEBRTC_WIN
17#include <winsock2.h> // NOLINT
18#endif
henrike@webrtc.orgf0488722014-05-13 18:00:2619
Yves Gerey2e00abc2018-10-05 13:39:2420#include <vector>
Henrik Kjellanderec78f1c2017-06-29 05:52:5021
Steve Anton10542f22019-01-11 17:11:0022#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"
Henrik Kjellanderec78f1c2017-06-29 05:52:5026
27namespace rtc {
28
deadbeef8290ddf2017-07-11 23:56:0529// AsyncResolver will perform async DNS resolution, signaling the result on
30// the SignalDone from AsyncResolverInterface when the operation completes.
31class AsyncResolver : public SignalThread, public AsyncResolverInterface {
Henrik Kjellanderec78f1c2017-06-29 05:52:5032 public:
33 AsyncResolver();
34 ~AsyncResolver() override;
35
36 void Start(const SocketAddress& addr) override;
37 bool GetResolvedAddress(int family, SocketAddress* addr) const override;
38 int GetError() const override;
39 void Destroy(bool wait) override;
40
41 const std::vector<IPAddress>& addresses() const { return addresses_; }
deadbeef8290ddf2017-07-11 23:56:0542 void set_error(int error) { error_ = error; }
43
44 protected:
45 void DoWork() override;
46 void OnWorkDone() override;
Henrik Kjellanderec78f1c2017-06-29 05:52:5047
48 private:
49 SocketAddress addr_;
50 std::vector<IPAddress> addresses_;
deadbeef8290ddf2017-07-11 23:56:0551 int error_;
Henrik Kjellanderec78f1c2017-06-29 05:52:5052};
53
54// rtc namespaced wrappers for inet_ntop and inet_pton so we can avoid
55// the windows-native versions of these.
Yves Gerey665174f2018-06-19 13:03:0556const char* inet_ntop(int af, const void* src, char* dst, socklen_t size);
57int inet_pton(int af, const char* src, void* dst);
Henrik Kjellanderec78f1c2017-06-29 05:52:5058
59bool HasIPv4Enabled();
60bool HasIPv6Enabled();
61} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:2662
Steve Anton10542f22019-01-11 17:11:0063#endif // RTC_BASE_NET_HELPERS_H_