Ensure <netinet/in.h> is included by using rtc_base/ip_address.h.

Change-Id: I1b48275ef458bcd579d027b879240c702975ab56
Bug: b/236227627
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/362280
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Cr-Commit-Position: refs/heads/main@{#43001}
This commit is contained in:
Jeremy Leconte 2024-09-11 04:48:41 +02:00 committed by WebRTC LUCI CQ
parent 47d48a2089
commit 1bd331f102
17 changed files with 73 additions and 75 deletions

View File

@ -1052,7 +1052,8 @@ def CommonChecks(input_api, output_api):
results.extend( results.extend(
CheckObjcApiSymbols(input_api, output_api, non_third_party_sources)) CheckObjcApiSymbols(input_api, output_api, non_third_party_sources))
results.extend( results.extend(
CheckSysSocketInclude(input_api, output_api, non_third_party_sources)) CheckConditionalIncludes(input_api, output_api,
non_third_party_sources))
return results return results
@ -1159,27 +1160,31 @@ def CheckBannedAbslOptional(input_api, output_api, source_file_filter):
return [] return []
def CheckSysSocketInclude(input_api, output_api, source_file_filter): def CheckConditionalIncludes(input_api, output_api, source_file_filter):
sys_socket = re.compile( conditional_includes = {
'^#include <sys/socket.h>((?!IWYU pragma|no-presubmit-check).)*$') '<netinet/in.h>': '"rtc_base/ip_address.h"',
'<sys/socket.h>': '"rtc_base/net_helpers.h"',
}
file_filter = lambda f: (f.LocalPath().endswith( file_filter = lambda f: (f.LocalPath().endswith(
('.cc', '.h')) and source_file_filter(f)) ('.cc', '.h')) and source_file_filter(f))
results = []
for key, value in conditional_includes.items():
include_regex = re.compile('^#include ' + key +
'((?!IWYU pragma|no-presubmit-check).)*$')
files = [] files = []
for f in input_api.AffectedFiles(include_deletes=False, for f in input_api.AffectedFiles(include_deletes=False,
file_filter=file_filter): file_filter=file_filter):
for _, line in f.ChangedContents(): for _, line in f.ChangedContents():
if sys_socket.search(line): if include_regex.search(line):
files.append(f.LocalPath()) files.append(f.LocalPath())
break break
if files: if files:
return [ results.append(
output_api.PresubmitError( output_api.PresubmitError(
'PleaseInclude "rtc_base/net_helpers.h" instead of ' 'Please include ' + value + ' instead of ' + key +
'<sys/socket.h>.\nAffected files:', files) '.\nAffected files:', files))
] return results
return []
def CheckObjcApiSymbols(input_api, output_api, source_file_filter): def CheckObjcApiSymbols(input_api, output_api, source_file_filter):

View File

@ -10,9 +10,6 @@
#include "api/transport/stun.h" #include "api/transport/stun.h"
#if defined(WEBRTC_POSIX)
#include <netinet/in.h>
#endif
#include <string.h> #include <string.h>
#include <algorithm> // IWYU pragma: keep #include <algorithm> // IWYU pragma: keep

View File

@ -10,9 +10,6 @@
#include "api/transport/stun.h" #include "api/transport/stun.h"
#if defined(WEBRTC_POSIX)
#include <netinet/in.h>
#endif
#include <string.h> #include <string.h>
#include <cstdint> #include <cstdint>

View File

@ -792,6 +792,7 @@ if (is_linux || is_chromeos || is_win) {
] ]
deps = [ deps = [
"../rtc_base:checks", "../rtc_base:checks",
"../rtc_base:ip_address",
"../rtc_base:net_helpers", "../rtc_base:net_helpers",
"../rtc_base:stringutils", "../rtc_base:stringutils",
"../system_wrappers:field_trial", "../system_wrappers:field_trial",

View File

@ -13,13 +13,13 @@
#include <string> #include <string>
#include "rtc_base/ip_address.h"
#include "rtc_base/net_helpers.h" #include "rtc_base/net_helpers.h"
#ifdef WIN32 #ifdef WIN32
typedef int socklen_t; typedef int socklen_t;
typedef SOCKET NativeSocket; typedef SOCKET NativeSocket;
#else #else
#include <netinet/in.h>
#include <sys/select.h> #include <sys/select.h>
#define closesocket close #define closesocket close
typedef int NativeSocket; typedef int NativeSocket;

View File

@ -823,6 +823,7 @@ rtc_library("neteq_test_tools") {
"../../common_audio", "../../common_audio",
"../../rtc_base:buffer", "../../rtc_base:buffer",
"../../rtc_base:checks", "../../rtc_base:checks",
"../../rtc_base:copy_on_write_buffer",
"../../rtc_base:digest", "../../rtc_base:digest",
"../../rtc_base:stringutils", "../../rtc_base:stringutils",
"../../rtc_base/system:arch", "../../rtc_base/system:arch",
@ -1380,6 +1381,7 @@ if (rtc_include_tests) {
deps = [ deps = [
":audio_coding", ":audio_coding",
":audio_coding_module_typedefs",
":audio_encoder_cng", ":audio_encoder_cng",
":neteq_input_audio_tools", ":neteq_input_audio_tools",
"../../api/audio:audio_frame_api", "../../api/audio:audio_frame_api",
@ -1389,10 +1391,11 @@ if (rtc_include_tests) {
"../../api/audio_codecs/ilbc:audio_encoder_ilbc", "../../api/audio_codecs/ilbc:audio_encoder_ilbc",
"../../api/audio_codecs/opus:audio_encoder_opus", "../../api/audio_codecs/opus:audio_encoder_opus",
"../../api/environment:environment_factory", "../../api/environment:environment_factory",
"../../rtc_base:checks",
"../../rtc_base:ip_address",
"../../rtc_base:safe_conversions", "../../rtc_base:safe_conversions",
"//third_party/abseil-cpp/absl/flags:flag", "//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse", "//third_party/abseil-cpp/absl/flags:parse",
"//third_party/abseil-cpp/absl/memory",
] ]
deps += audio_coding_deps deps += audio_coding_deps

View File

@ -10,21 +10,20 @@
#include <stdio.h> #include <stdio.h>
#include <cstdint>
#include <memory>
#include <utility>
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h> #include <winsock2.h>
#endif #endif
#if defined(WEBRTC_LINUX) || defined(WEBRTC_FUCHSIA)
#include <netinet/in.h>
#endif
#include <iostream>
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/flags/flag.h" #include "absl/flags/flag.h"
#include "absl/flags/parse.h" #include "absl/flags/parse.h"
#include "absl/memory/memory.h"
#include "api/audio/audio_frame.h" #include "api/audio/audio_frame.h"
#include "api/audio_codecs/L16/audio_encoder_L16.h" #include "api/audio_codecs/L16/audio_encoder_L16.h"
#include "api/audio_codecs/g711/audio_encoder_g711.h" #include "api/audio_codecs/g711/audio_encoder_g711.h"
@ -34,7 +33,10 @@
#include "api/environment/environment_factory.h" #include "api/environment/environment_factory.h"
#include "modules/audio_coding/codecs/cng/audio_encoder_cng.h" #include "modules/audio_coding/codecs/cng/audio_encoder_cng.h"
#include "modules/audio_coding/include/audio_coding_module.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "modules/audio_coding/neteq/tools/input_audio_file.h" #include "modules/audio_coding/neteq/tools/input_audio_file.h"
#include "rtc_base/checks.h"
#include "rtc_base/ip_address.h"
#include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/numerics/safe_conversions.h"
ABSL_FLAG(bool, list_codecs, false, "Enumerate all codecs"); ABSL_FLAG(bool, list_codecs, false, "Enumerate all codecs");

View File

@ -12,15 +12,16 @@
#include <string.h> #include <string.h>
#include "absl/strings/string_view.h" #include <cstdint>
#ifndef WIN32
#include <netinet/in.h>
#endif
#include <memory> #include <memory>
#include <optional>
#include "absl/strings/string_view.h"
#include "modules/audio_coding/neteq/tools/packet.h" #include "modules/audio_coding/neteq/tools/packet.h"
#include "modules/audio_coding/neteq/tools/packet_source.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "test/rtp_file_reader.h" #include "test/rtp_file_reader.h"
namespace webrtc { namespace webrtc {

View File

@ -1063,6 +1063,7 @@ rtc_library("socket") {
deps = [ deps = [
":buffer", ":buffer",
":checks", ":checks",
":ip_address",
":macromagic", ":macromagic",
":net_helpers", ":net_helpers",
":socket_address", ":socket_address",
@ -1936,6 +1937,7 @@ if (rtc_include_tests) {
":macromagic", ":macromagic",
":mod_ops", ":mod_ops",
":moving_max_counter", ":moving_max_counter",
":net_helpers",
":null_socket_server", ":null_socket_server",
":one_time_event", ":one_time_event",
":platform_thread", ":platform_thread",

View File

@ -44,7 +44,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <winsock2.h> #include <winsock2.h>
#else #else
#include <netinet/in.h> #include <netinet/in.h> // no-presubmit-check
#endif // defined(WEBRTC_WIN) #endif // defined(WEBRTC_WIN)
#if defined(WEBRTC_ARCH_LITTLE_ENDIAN) #if defined(WEBRTC_ARCH_LITTLE_ENDIAN)

View File

@ -15,7 +15,7 @@
#include <linux/netlink.h> #include <linux/netlink.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <net/if.h> #include <net/if.h>
#include <netinet/in.h> #include <netinet/in.h> // no-presubmit-check
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>

View File

@ -8,28 +8,26 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <string>
#if defined(WEBRTC_POSIX) #if defined(WEBRTC_POSIX)
#include <netinet/in.h>
#include "absl/strings/string_view.h"
#ifdef OPENBSD #ifdef OPENBSD
#include <netinet/in_systm.h> #include <netinet/in_systm.h>
#endif #endif
#ifndef __native_client__ #ifndef __native_client__
#include <netinet/ip.h>
#endif #endif
#include <netdb.h> #include <netdb.h>
#endif #endif
#include "absl/strings/string_view.h"
#include "rtc_base/byte_order.h" #include "rtc_base/byte_order.h"
#include "rtc_base/ip_address.h" #include "rtc_base/ip_address.h"
#include "rtc_base/net_helpers.h" #include "rtc_base/net_helpers.h"
#include "rtc_base/string_utils.h" #include "rtc_base/string_utils.h"
#if defined(WEBRTC_WIN)
#include "rtc_base/win32.h"
#endif // WEBRTC_WIN
namespace rtc { namespace rtc {
// Prefixes used for categorizing IPv6 addresses. // Prefixes used for categorizing IPv6 addresses.

View File

@ -11,10 +11,11 @@
#ifndef RTC_BASE_IP_ADDRESS_H_ #ifndef RTC_BASE_IP_ADDRESS_H_
#define RTC_BASE_IP_ADDRESS_H_ #define RTC_BASE_IP_ADDRESS_H_
#include <cstdint>
#if defined(WEBRTC_POSIX) #if defined(WEBRTC_POSIX)
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h> // IWYU pragma: export
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#endif #endif

View File

@ -13,19 +13,20 @@
#include <errno.h> #include <errno.h>
#include <cstddef>
#include <cstdint>
#include <optional> #include <optional>
#include "rtc_base/checks.h"
#if defined(WEBRTC_POSIX) #if defined(WEBRTC_POSIX)
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h> #include <sys/types.h>
#define SOCKET_EACCES EACCES #define SOCKET_EACCES EACCES
#endif #endif
#include "api/units/timestamp.h" #include "api/units/timestamp.h"
#include "rtc_base/buffer.h" #include "rtc_base/buffer.h"
#include "rtc_base/checks.h"
#include "rtc_base/ip_address.h"
#include "rtc_base/net_helpers.h" #include "rtc_base/net_helpers.h"
#include "rtc_base/network/ecn_marking.h" #include "rtc_base/network/ecn_marking.h"
#include "rtc_base/socket_address.h" #include "rtc_base/socket_address.h"

View File

@ -10,33 +10,27 @@
#include "rtc_base/socket_address.h" #include "rtc_base/socket_address.h"
#include "absl/strings/string_view.h" #include <cstddef>
#include "rtc_base/numerics/safe_conversions.h" #include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#if defined(WEBRTC_POSIX) #if defined(WEBRTC_POSIX)
#include <netinet/in.h>
#include <sys/types.h>
#if defined(OPENBSD) #if defined(OPENBSD)
#include <netinet/in_systm.h> #include <netinet/in_systm.h>
#endif #endif
#if !defined(__native_client__) #if !defined(__native_client__)
#include <netinet/ip.h>
#endif #endif
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#endif #endif
#include "absl/strings/string_view.h"
#include "rtc_base/byte_order.h" #include "rtc_base/byte_order.h"
#include "rtc_base/checks.h" #include "rtc_base/ip_address.h"
#include "rtc_base/logging.h"
#include "rtc_base/net_helpers.h" #include "rtc_base/net_helpers.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/strings/string_builder.h" #include "rtc_base/strings/string_builder.h"
#if defined(WEBRTC_WIN)
#include "rtc_base/win32.h"
#endif
namespace rtc { namespace rtc {
SocketAddress::SocketAddress() { SocketAddress::SocketAddress() {

View File

@ -8,14 +8,14 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#if defined(WEBRTC_POSIX) #include "rtc_base/socket_address.h"
#include <netinet/in.h> // for sockaddr_in
#endif
#include <string.h> #include <string.h>
#include <string>
#include "rtc_base/ip_address.h" #include "rtc_base/ip_address.h"
#include "rtc_base/socket_address.h" #include "rtc_base/net_helpers.h"
#include "test/gtest.h" #include "test/gtest.h"
namespace rtc { namespace rtc {

View File

@ -14,14 +14,8 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "rtc_base/network/received_packet.h"
#if defined(WEBRTC_POSIX)
#include <netinet/in.h>
#endif
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <utility>
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "api/units/time_delta.h" #include "api/units/time_delta.h"
@ -32,6 +26,8 @@
#include "rtc_base/gunit.h" #include "rtc_base/gunit.h"
#include "rtc_base/ip_address.h" #include "rtc_base/ip_address.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/net_helpers.h"
#include "rtc_base/network/received_packet.h"
#include "rtc_base/socket.h" #include "rtc_base/socket.h"
#include "rtc_base/socket_address.h" #include "rtc_base/socket_address.h"
#include "rtc_base/task_utils/repeating_task.h" #include "rtc_base/task_utils/repeating_task.h"