1 /*
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 
11 #ifndef RTC_BASE_NET_HELPERS_H_
12 #define RTC_BASE_NET_HELPERS_H_
13 
14 #if defined(WEBRTC_POSIX)
15 #include <sys/socket.h>
16 #elif WEBRTC_WIN
17 #include <winsock2.h>  // NOLINT
18 #endif
19 
20 #include <vector>
21 
22 #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"
26 #include "rtc_base/system/rtc_export.h"
27 
28 namespace rtc {
29 
30 // AsyncResolver will perform async DNS resolution, signaling the result on
31 // the SignalDone from AsyncResolverInterface when the operation completes.
32 class RTC_EXPORT AsyncResolver : public SignalThread,
33                                  public AsyncResolverInterface {
34  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 
addresses()43   const std::vector<IPAddress>& addresses() const { return addresses_; }
set_error(int error)44   void set_error(int error) { error_ = error; }
45 
46  protected:
47   void DoWork() override;
48   void OnWorkDone() override;
49 
50  private:
51   SocketAddress addr_;
52   std::vector<IPAddress> addresses_;
53   int error_;
54 };
55 
56 // rtc namespaced wrappers for inet_ntop and inet_pton so we can avoid
57 // the windows-native versions of these.
58 const char* inet_ntop(int af, const void* src, char* dst, socklen_t size);
59 int inet_pton(int af, const char* src, void* dst);
60 
61 bool HasIPv4Enabled();
62 bool HasIPv6Enabled();
63 }  // namespace rtc
64 
65 #endif  // RTC_BASE_NET_HELPERS_H_
66