blob: 429f0c0c746b08caaa8ca01c6cc91ec0a6f51e6b [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
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef RTC_BASE_NETHELPERS_H_
12#define RTC_BASE_NETHELPERS_H_
henrike@webrtc.orgf0488722014-05-13 18:00:2613
Henrik Kjellanderec78f1c2017-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.orgf0488722014-05-13 18:00:2620
Yves Gerey2e00abc2018-10-05 13:39:2421#include <vector>
Henrik Kjellanderec78f1c2017-06-29 05:52:5022
Mirko Bonadei92ea95e2017-09-15 04:47:3123#include "rtc_base/asyncresolverinterface.h"
Yves Gerey2e00abc2018-10-05 13:39:2424#include "rtc_base/ipaddress.h" // for IPAddress
Mirko Bonadei92ea95e2017-09-15 04:47:3125#include "rtc_base/signalthread.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3126#include "rtc_base/socketaddress.h"
Henrik Kjellanderec78f1c2017-06-29 05:52:5027
28namespace rtc {
29
deadbeef8290ddf2017-07-11 23:56:0530// AsyncResolver will perform async DNS resolution, signaling the result on
31// the SignalDone from AsyncResolverInterface when the operation completes.
32class AsyncResolver : public SignalThread, public AsyncResolverInterface {
Henrik Kjellanderec78f1c2017-06-29 05:52:5033 public:
34 AsyncResolver();
35 ~AsyncResolver() override;
36
37 void Start(const SocketAddress& addr) override;
38 bool GetResolvedAddress(int family, SocketAddress* addr) const override;
39 int GetError() const override;
40 void Destroy(bool wait) override;
41
42 const std::vector<IPAddress>& addresses() const { return addresses_; }
deadbeef8290ddf2017-07-11 23:56:0543 void set_error(int error) { error_ = error; }
44
45 protected:
46 void DoWork() override;
47 void OnWorkDone() override;
Henrik Kjellanderec78f1c2017-06-29 05:52:5048
49 private:
50 SocketAddress addr_;
51 std::vector<IPAddress> addresses_;
deadbeef8290ddf2017-07-11 23:56:0552 int error_;
Henrik Kjellanderec78f1c2017-06-29 05:52:5053};
54
55// rtc namespaced wrappers for inet_ntop and inet_pton so we can avoid
56// the windows-native versions of these.
Yves Gerey665174f2018-06-19 13:03:0557const char* inet_ntop(int af, const void* src, char* dst, socklen_t size);
58int inet_pton(int af, const char* src, void* dst);
Henrik Kjellanderec78f1c2017-06-29 05:52:5059
60bool HasIPv4Enabled();
61bool HasIPv6Enabled();
62} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:2663
Mirko Bonadei92ea95e2017-09-15 04:47:3164#endif // RTC_BASE_NETHELPERS_H_