diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2024-10-31 15:27:01 +0100 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2024-10-31 15:27:01 +0100 |
| commit | fa15fdcf5dc2d40aba2f8520108e552b73b1df2b (patch) | |
| tree | d51d62db024b317091f42d9ee540da7371e9d170 /lib/utils_tcp.c | |
| parent | 0fd0421052fed1972ecbdfdabecba5a616eaa109 (diff) | |
| parent | 87eb2bef1ee2a6a42793437b2f5d63f41b1e1806 (diff) | |
| download | monitoring-plugins-fa15fdc.tar.gz | |
Merge branch 'master' into fix/check_ssh-variable-stuff
Diffstat (limited to 'lib/utils_tcp.c')
| -rw-r--r-- | lib/utils_tcp.c | 78 |
1 files changed, 36 insertions, 42 deletions
diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c index 23ee4a95..daae1d54 100644 --- a/lib/utils_tcp.c +++ b/lib/utils_tcp.c | |||
| @@ -1,51 +1,46 @@ | |||
| 1 | /***************************************************************************** | 1 | /***************************************************************************** |
| 2 | * | 2 | * |
| 3 | * Library for check_tcp | 3 | * Library for check_tcp |
| 4 | * | 4 | * |
| 5 | * License: GPL | 5 | * License: GPL |
| 6 | * Copyright (c) 1999-2013 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2024 Monitoring Plugins Development Team |
| 7 | * | 7 | * |
| 8 | * Description: | 8 | * Description: |
| 9 | * | 9 | * |
| 10 | * This file contains utilities for check_tcp. These are tested by libtap | 10 | * This file contains utilities for check_tcp. These are tested by libtap |
| 11 | * | 11 | * |
| 12 | * | 12 | * |
| 13 | * This program is free software: you can redistribute it and/or modify | 13 | * This program is free software: you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by | 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation, either version 3 of the License, or | 15 | * the Free Software Foundation, either version 3 of the License, or |
| 16 | * (at your option) any later version. | 16 | * (at your option) any later version. |
| 17 | * | 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, | 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. | 21 | * GNU General Public License for more details. |
| 22 | * | 22 | * |
| 23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 25 | * | 25 | * |
| 26 | * | 26 | * |
| 27 | *****************************************************************************/ | 27 | *****************************************************************************/ |
| 28 | 28 | ||
| 29 | #include "common.h" | 29 | #include "common.h" |
| 30 | #include "utils_tcp.h" | 30 | #include "utils_tcp.h" |
| 31 | 31 | ||
| 32 | #define VERBOSE(message) \ | 32 | #define VERBOSE(message) \ |
| 33 | do { \ | 33 | do { \ |
| 34 | if (flags & NP_MATCH_VERBOSE) \ | 34 | if (flags & NP_MATCH_VERBOSE) \ |
| 35 | puts(message); \ | 35 | puts(message); \ |
| 36 | } while (0) | 36 | } while (0) |
| 37 | 37 | ||
| 38 | enum np_match_result | 38 | enum np_match_result np_expect_match(char *status, char **server_expect, int expect_count, int flags) { |
| 39 | np_expect_match(char *status, char **server_expect, int expect_count, int flags) | ||
| 40 | { | ||
| 41 | int i, match = 0, partial = 0; | 39 | int i, match = 0, partial = 0; |
| 42 | 40 | ||
| 43 | for (i = 0; i < expect_count; i++) { | 41 | for (i = 0; i < expect_count; i++) { |
| 44 | if (flags & NP_MATCH_VERBOSE) | 42 | if (flags & NP_MATCH_VERBOSE) |
| 45 | printf("looking for [%s] %s [%s]\n", server_expect[i], | 43 | printf("looking for [%s] %s [%s]\n", server_expect[i], (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", status); |
| 46 | (flags & NP_MATCH_EXACT) ? | ||
| 47 | "in beginning of" : "anywhere in", | ||
| 48 | status); | ||
| 49 | 44 | ||
| 50 | if (flags & NP_MATCH_EXACT) { | 45 | if (flags & NP_MATCH_EXACT) { |
| 51 | if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0) { | 46 | if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0) { |
| @@ -58,15 +53,14 @@ np_expect_match(char *status, char **server_expect, int expect_count, int flags) | |||
| 58 | continue; | 53 | continue; |
| 59 | } | 54 | } |
| 60 | } else if (strstr(status, server_expect[i]) != NULL) { | 55 | } else if (strstr(status, server_expect[i]) != NULL) { |
| 61 | VERBOSE("found it"); | 56 | VERBOSE("found it"); |
| 62 | match++; | 57 | match++; |
| 63 | continue; | 58 | continue; |
| 64 | } | 59 | } |
| 65 | VERBOSE("couldn't find it"); | 60 | VERBOSE("couldn't find it"); |
| 66 | } | 61 | } |
| 67 | 62 | ||
| 68 | if ((flags & NP_MATCH_ALL && match == expect_count) || | 63 | if ((flags & NP_MATCH_ALL && match == expect_count) || (!(flags & NP_MATCH_ALL) && match >= 1)) |
| 69 | (!(flags & NP_MATCH_ALL) && match >= 1)) | ||
| 70 | return NP_MATCH_SUCCESS; | 64 | return NP_MATCH_SUCCESS; |
| 71 | else if (partial > 0 || !(flags & NP_MATCH_EXACT)) | 65 | else if (partial > 0 || !(flags & NP_MATCH_EXACT)) |
| 72 | return NP_MATCH_RETRY; | 66 | return NP_MATCH_RETRY; |
