33 #include <sys/utsname.h>
35 #define VERSION_REGEX "^([0-9]+)\\.([0-9]+)"
39 struct utsname kuname;
40 pcre2_code *version_regex;
41 pcre2_match_data *version_regex_match;
49 if (uname(&kuname) != 0) {
50 SCLogError(
"Invalid uname return: %s", strerror(errno));
54 SCLogDebug(
"Kernel release is '%s'", kuname.release);
57 pcre2_compile((PCRE2_SPTR8)
VERSION_REGEX, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
58 if (version_regex == NULL) {
59 PCRE2_UCHAR errbuffer[256];
60 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
61 SCLogError(
"pcre2 compile of \"%s\" failed at "
66 version_regex_match = pcre2_match_data_create_from_pattern(version_regex, NULL);
68 ret = pcre2_match(version_regex, (PCRE2_SPTR8)kuname.release, strlen(kuname.release), 0, 0,
69 version_regex_match, NULL);
77 SCLogError(
"Version major and minor not found (ret %d)", ret);
82 size_t pcre2len =
sizeof(majorstr);
83 ret = pcre2_substring_copy_bynumber(
84 version_regex_match, 1, (PCRE2_UCHAR8 *)majorstr, &pcre2len);
86 SCLogError(
"pcre2_substring_copy_bynumber failed");
91 pcre2len =
sizeof(majorstr);
92 ret = pcre2_substring_copy_bynumber(
93 version_regex_match, 2, (PCRE2_UCHAR8 *)minorstr, &pcre2len);
95 SCLogError(
"pcre2_substring_copy_bynumber failed");
100 SCLogError(
"Invalid value for kmajor: '%s'", minorstr);
104 SCLogError(
"Invalid value for kminor: '%s'", minorstr);
108 pcre2_match_data_free(version_regex_match);
109 pcre2_code_free(version_regex);
113 if (kmajor == major && kminor >= minor)
123 SCLogError(
"OS compare is not supported on Windows");