OpenVPN 3 Core Library
Loading...
Searching...
No Matches
ver.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_APPLE_VER_H
13#define OPENVPN_APPLE_VER_H
14
15#include <errno.h>
16#include <sys/sysctl.h>
17
18#include <string>
19#include <sstream>
20#include <vector>
21
24
25namespace openvpn {
27{
28 public:
29 int major() const
30 {
31 return ver[0];
32 }
33 int minor() const
34 {
35 return ver[1];
36 }
37 int build() const
38 {
39 return ver[2];
40 }
41
42 std::string to_string() const
43 {
44 std::ostringstream os;
45 os << major() << '.' << minor() << '.' << build();
46 return os.str();
47 }
48
49 protected:
51 {
52 reset();
53 }
54
55 // verstr should be in the form major.minor.build
56 void init(const std::string &verstr)
57 {
58 typedef std::vector<std::string> StringList;
59 reset();
60 StringList sl;
61 sl.reserve(3);
62 Split::by_char_void<StringList, NullLex, Split::NullLimit>(sl, verstr, '.');
63 for (size_t i = 0; i < 3; ++i)
64 {
65 if (i < sl.size())
66 parse_number(sl[i], ver[i]);
67 }
68 }
69
70 private:
71 void reset()
72 {
73 ver[0] = ver[1] = ver[2] = -1;
74 }
75
76 int ver[3];
77};
78} // namespace openvpn
79
80#endif
void init(const std::string &verstr)
Definition ver.hpp:56
int minor() const
Definition ver.hpp:33
int build() const
Definition ver.hpp:37
std::string to_string() const
Definition ver.hpp:42
int major() const
Definition ver.hpp:29
bool parse_number(const char *str, T &retval, const bool nondigit_term=false)
Definition number.hpp:34
std::ostringstream os