diff options
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_ntp_peer.c | 60 |
1 files changed, 3 insertions, 57 deletions
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index acca17b5..b40dbfcb 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c | |||
| @@ -172,60 +172,6 @@ void print_ntp_control_message(const ntp_control_message *p){ | |||
| 172 | } | 172 | } |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | /* | ||
| 176 | * Extract the value from NTP key/value pairs, or return NULL. | ||
| 177 | * The value returned can be free()ed. | ||
| 178 | */ | ||
| 179 | char *extract_value(const char *varlist, const char *name){ | ||
| 180 | char *tmp=NULL, *value=NULL; | ||
| 181 | int i; | ||
| 182 | |||
| 183 | while (1) { | ||
| 184 | /* Strip any leading space */ | ||
| 185 | for (varlist; isspace(varlist[0]); varlist++); | ||
| 186 | |||
| 187 | if (strncmp(name, varlist, strlen(name)) == 0) { | ||
| 188 | varlist += strlen(name); | ||
| 189 | /* strip trailing spaces */ | ||
| 190 | for (varlist; isspace(varlist[0]); varlist++); | ||
| 191 | |||
| 192 | if (varlist[0] == '=') { | ||
| 193 | /* We matched the key, go past the = sign */ | ||
| 194 | varlist++; | ||
| 195 | /* strip leading spaces */ | ||
| 196 | for (varlist; isspace(varlist[0]); varlist++); | ||
| 197 | |||
| 198 | if (tmp = index(varlist, ',')) { | ||
| 199 | /* Value is delimited by a comma */ | ||
| 200 | if (tmp-varlist == 0) continue; | ||
| 201 | value = (char *)malloc(tmp-varlist+1); | ||
| 202 | strncpy(value, varlist, tmp-varlist); | ||
| 203 | value[tmp-varlist] = '\0'; | ||
| 204 | } else { | ||
| 205 | /* Value is delimited by a \0 */ | ||
| 206 | if (strlen(varlist) == 0) continue; | ||
| 207 | value = (char *)malloc(strlen(varlist) + 1); | ||
| 208 | strncpy(value, varlist, strlen(varlist)); | ||
| 209 | value[strlen(varlist)] = '\0'; | ||
| 210 | } | ||
| 211 | break; | ||
| 212 | } | ||
| 213 | } | ||
| 214 | if (tmp = index(varlist, ',')) { | ||
| 215 | /* More keys, keep going... */ | ||
| 216 | varlist = tmp + 1; | ||
| 217 | } else { | ||
| 218 | /* We're done */ | ||
| 219 | break; | ||
| 220 | } | ||
| 221 | } | ||
| 222 | |||
| 223 | /* Clean-up trailing spaces/newlines */ | ||
| 224 | if (value) for (i=strlen(value)-1; isspace(value[i]); i--) value[i] = '\0'; | ||
| 225 | |||
| 226 | return value; | ||
| 227 | } | ||
| 228 | |||
| 229 | void | 175 | void |
| 230 | setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){ | 176 | setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){ |
| 231 | memset(p, 0, sizeof(ntp_control_message)); | 177 | memset(p, 0, sizeof(ntp_control_message)); |
| @@ -387,7 +333,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji | |||
| 387 | if(verbose) | 333 | if(verbose) |
| 388 | printf("parsing offset from peer %.2x: ", ntohs(peers[i].assoc)); | 334 | printf("parsing offset from peer %.2x: ", ntohs(peers[i].assoc)); |
| 389 | 335 | ||
| 390 | value = extract_value(data, "offset"); | 336 | value = np_extract_value(data, "offset"); |
| 391 | nptr=NULL; | 337 | nptr=NULL; |
| 392 | /* Convert the value if we have one */ | 338 | /* Convert the value if we have one */ |
| 393 | if(value != NULL) | 339 | if(value != NULL) |
| @@ -411,7 +357,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji | |||
| 411 | if(verbose) { | 357 | if(verbose) { |
| 412 | printf("parsing %s from peer %.2x: ", strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter", ntohs(peers[i].assoc)); | 358 | printf("parsing %s from peer %.2x: ", strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter", ntohs(peers[i].assoc)); |
| 413 | } | 359 | } |
| 414 | value = extract_value(data, strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter"); | 360 | value = np_extract_value(data, strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter"); |
| 415 | nptr=NULL; | 361 | nptr=NULL; |
| 416 | /* Convert the value if we have one */ | 362 | /* Convert the value if we have one */ |
| 417 | if(value != NULL) | 363 | if(value != NULL) |
| @@ -430,7 +376,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji | |||
| 430 | if(verbose) { | 376 | if(verbose) { |
| 431 | printf("parsing stratum from peer %.2x: ", ntohs(peers[i].assoc)); | 377 | printf("parsing stratum from peer %.2x: ", ntohs(peers[i].assoc)); |
| 432 | } | 378 | } |
| 433 | value = extract_value(data, "stratum"); | 379 | value = np_extract_value(data, "stratum"); |
| 434 | nptr=NULL; | 380 | nptr=NULL; |
| 435 | /* Convert the value if we have one */ | 381 | /* Convert the value if we have one */ |
| 436 | if(value != NULL) | 382 | if(value != NULL) |
