From b3fd60e6407b3af029672218b0bff7bb30e7a9d9 Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 30 Dec 2021 12:20:42 +0800 Subject: Add ping check (-p). Support custom error handling command (-c). Add runtime params validation for logging. --- validate.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 validate.c (limited to 'validate.c') diff --git a/validate.c b/validate.c new file mode 100644 index 0000000..49005f0 --- /dev/null +++ b/validate.c @@ -0,0 +1,23 @@ +// +// Created by Keuin on 2021/12/30. +// + +#include "validate.h" +#include + +/** + * Check if a given string is a valid dot-decimal representation of an IPv4 address. + * @param s the string. + * @return Non-zero if true, zero if false. + */ +int is_valid_ipv4(const char *s) { + // TODO buggy +// unsigned int addr[4]; +// if (sscanf(s, "%ud.%ud.%ud.%ud", &addr[0], &addr[1], &addr[2], &addr[3]) != 4) +// return 0; +// for (int i = 0; i < 4; ++i) { +// if (addr[i] > 255) return 0; +// if (addr[i] == 0 && (i == 0 || i == 3)) return 0; +// } + return 1; +} -- cgit v1.2.3