You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #ifndef RTC_BASE_NET_HELPERS_H_
  11. #define RTC_BASE_NET_HELPERS_H_
  12. #if defined(WEBRTC_POSIX)
  13. #include <sys/socket.h>
  14. #elif WEBRTC_WIN
  15. #include <winsock2.h> // NOLINT
  16. #endif
  17. #include <vector>
  18. #include "rtc_base/async_resolver_interface.h"
  19. #include "rtc_base/ip_address.h"
  20. #include "rtc_base/signal_thread.h"
  21. #include "rtc_base/socket_address.h"
  22. #include "rtc_base/system/rtc_export.h"
  23. namespace rtc {
  24. // AsyncResolver will perform async DNS resolution, signaling the result on
  25. // the SignalDone from AsyncResolverInterface when the operation completes.
  26. class RTC_EXPORT AsyncResolver : public SignalThread,
  27. public AsyncResolverInterface {
  28. public:
  29. AsyncResolver();
  30. ~AsyncResolver() override;
  31. void Start(const SocketAddress& addr) override;
  32. bool GetResolvedAddress(int family, SocketAddress* addr) const override;
  33. int GetError() const override;
  34. void Destroy(bool wait) override;
  35. const std::vector<IPAddress>& addresses() const { return addresses_; }
  36. void set_error(int error) { error_ = error; }
  37. protected:
  38. void DoWork() override;
  39. void OnWorkDone() override;
  40. private:
  41. SocketAddress addr_;
  42. std::vector<IPAddress> addresses_;
  43. int error_;
  44. };
  45. // rtc namespaced wrappers for inet_ntop and inet_pton so we can avoid
  46. // the windows-native versions of these.
  47. const char* inet_ntop(int af, const void* src, char* dst, socklen_t size);
  48. int inet_pton(int af, const char* src, void* dst);
  49. bool HasIPv4Enabled();
  50. bool HasIPv6Enabled();
  51. } // namespace rtc
  52. #endif // RTC_BASE_NET_HELPERS_H_