1 /*
2 * Copyright 2004 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_WIN32_H_
12 #define RTC_BASE_WIN32_H_
13
14 #ifndef WEBRTC_WIN
15 #error "Only #include this header in Windows builds"
16 #endif
17
18 // Make sure we don't get min/max macros
19 #ifndef NOMINMAX
20 #define NOMINMAX
21 #endif
22
23 // clang-format off
24 // clang formating would change include order.
25 #include <winsock2.h> // must come first
26 #include <windows.h>
27 // clang-format on
28
29 typedef int socklen_t;
30
31 #ifndef SECURITY_MANDATORY_LABEL_AUTHORITY
32 // Add defines that we use if we are compiling against older sdks
33 #define SECURITY_MANDATORY_MEDIUM_RID (0x00002000L)
34 #define TokenIntegrityLevel static_cast<TOKEN_INFORMATION_CLASS>(0x19)
35 typedef struct _TOKEN_MANDATORY_LABEL {
36 SID_AND_ATTRIBUTES Label;
37 } TOKEN_MANDATORY_LABEL, *PTOKEN_MANDATORY_LABEL;
38 #endif // SECURITY_MANDATORY_LABEL_AUTHORITY
39
40 #undef SetPort
41
42 #include <string>
43
44 namespace rtc {
45
46 const char* win32_inet_ntop(int af, const void* src, char* dst, socklen_t size);
47 int win32_inet_pton(int af, const char* src, void* dst);
48
49 enum WindowsMajorVersions {
50 kWindows2000 = 5,
51 kWindowsVista = 6,
52 kWindows10 = 10,
53 };
54
55 #if !defined(WINUWP)
56 bool GetOsVersion(int* major, int* minor, int* build);
57
IsWindowsVistaOrLater()58 inline bool IsWindowsVistaOrLater() {
59 int major;
60 return (GetOsVersion(&major, nullptr, nullptr) && major >= kWindowsVista);
61 }
62
IsWindowsXpOrLater()63 inline bool IsWindowsXpOrLater() {
64 int major, minor;
65 return (GetOsVersion(&major, &minor, nullptr) &&
66 (major >= kWindowsVista || (major == kWindows2000 && minor >= 1)));
67 }
68
IsWindows8OrLater()69 inline bool IsWindows8OrLater() {
70 int major, minor;
71 return (GetOsVersion(&major, &minor, nullptr) &&
72 (major > kWindowsVista || (major == kWindowsVista && minor >= 2)));
73 }
74
IsWindows10OrLater()75 inline bool IsWindows10OrLater() {
76 int major;
77 return (GetOsVersion(&major, nullptr, nullptr) && (major >= kWindows10));
78 }
79
80 #else
81
82 // When targetting WinUWP the OS must be Windows 10 (or greater) as lesser
83 // Windows OS targets are not supported.
IsWindowsVistaOrLater()84 inline bool IsWindowsVistaOrLater() {
85 return true;
86 }
87
IsWindowsXpOrLater()88 inline bool IsWindowsXpOrLater() {
89 return true;
90 }
91
IsWindows8OrLater()92 inline bool IsWindows8OrLater() {
93 return true;
94 }
95
IsWindows10OrLater()96 inline bool IsWindows10OrLater() {
97 return true;
98 }
99
100 #endif // !defined(WINUWP)
101
102 } // namespace rtc
103
104 #endif // RTC_BASE_WIN32_H_
105