henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "rtc_base/net_helpers.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 12 | |
Mirko Bonadei | e5f4c6b | 2021-01-15 09:41:01 | [diff] [blame] | 13 | #include <memory> |
Ali Tofigh | 2ab914c | 2022-04-13 10:55:15 | [diff] [blame] | 14 | #include <string> |
| 15 | |
| 16 | #include "absl/strings/string_view.h" |
Mirko Bonadei | e5f4c6b | 2021-01-15 09:41:01 | [diff] [blame] | 17 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 18 | #if defined(WEBRTC_WIN) |
| 19 | #include <ws2spi.h> |
| 20 | #include <ws2tcpip.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 21 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 22 | #endif |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 23 | #if defined(WEBRTC_POSIX) && !defined(__native_client__) |
Mirko Bonadei | e5f4c6b | 2021-01-15 09:41:01 | [diff] [blame] | 24 | #include <arpa/inet.h> |
Taylor Brandstetter | 2b3bf6b | 2016-05-19 21:57:31 | [diff] [blame] | 25 | #endif // defined(WEBRTC_POSIX) && !defined(__native_client__) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 26 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 27 | namespace rtc { |
| 28 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 29 | const char* inet_ntop(int af, const void* src, char* dst, socklen_t size) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 30 | #if defined(WEBRTC_WIN) |
| 31 | return win32_inet_ntop(af, src, dst, size); |
| 32 | #else |
| 33 | return ::inet_ntop(af, src, dst, size); |
| 34 | #endif |
| 35 | } |
| 36 | |
Ali Tofigh | 2ab914c | 2022-04-13 10:55:15 | [diff] [blame] | 37 | int inet_pton(int af, absl::string_view src, void* dst) { |
Ali Tofigh | 98bfd99 | 2022-07-22 20:10:49 | [diff] [blame] | 38 | std::string src_str(src); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 39 | #if defined(WEBRTC_WIN) |
Ali Tofigh | 2ab914c | 2022-04-13 10:55:15 | [diff] [blame] | 40 | return win32_inet_pton(af, src_str.c_str(), dst); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 41 | #else |
Ali Tofigh | 2ab914c | 2022-04-13 10:55:15 | [diff] [blame] | 42 | return ::inet_pton(af, src_str.c_str(), dst); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 43 | #endif |
| 44 | } |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 45 | } // namespace rtc |