diff options
author | Keuin <[email protected]> | 2021-12-30 12:20:42 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2021-12-30 12:20:42 +0800 |
commit | b3fd60e6407b3af029672218b0bff7bb30e7a9d9 (patch) | |
tree | 1536fec6761b9913a47117725fd5b4b5f70caa62 /validate.c | |
parent | 5651bc231389ebfa05e3750a431b33c28f4ed205 (diff) |
Add ping check (-p).
Support custom error handling command (-c).
Add runtime params validation for logging.
Diffstat (limited to 'validate.c')
-rw-r--r-- | validate.c | 23 |
1 files changed, 23 insertions, 0 deletions
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 <stdio.h> + +/** + * 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; +} |