From 92d746ea9a32a7413bf08658e6fe8db8d18f0891 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 15 Sep 2023 00:20:57 -0300 Subject: [PATCH] Tweak examples --- README.md | 63 +++++++++++++------------ share/isinetaddr/examples/iscidraddr4.c | 21 +++++---- share/isinetaddr/examples/isinetaddr4.c | 21 +++++---- share/isinetaddr/examples/isinetaddr6.c | 21 +++++---- 4 files changed, 66 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index cdf9248..63b7e11 100644 --- a/README.md +++ b/README.md @@ -20,16 +20,7 @@ when the input given is a valid IPv4 address, and otherwise returns 0. const char *valid[] = { "127.0.0.1", "1.1.1.1", "0.0.0.0" }; const char *invalid[] = { "foobar", "0.0.0.0.0", NULL }; - -void -validate(const char *str) -{ - if (isinetaddr4(str)) { - printf("%s is a valid IPv4 address.\n", str); - } else { - printf("%s is an invalid IPv4 address.\n", str); - } -} +void validate(const char *str); int main(void) @@ -44,6 +35,16 @@ main(void) } return EXIT_SUCCESS; } + +void +validate(const char *str) +{ + if (isinetaddr4(str)) { + printf("%s is a valid IPv4 address.\n", str); + } else { + printf("%s is an invalid IPv4 address.\n", str); + } +} ``` Expected output: @@ -75,16 +76,7 @@ The following example builds on the previous example: const char *valid[] = { "127.0.0.1", "192.168.2.1/32", "192.168.2.1/0" }; const char *invalid[] = { "foobar", "0.0.0.0.0", "192.168.2.1/33" }; - -void -validate(const char *str) -{ - if (iscidraddr4(str)) { - printf("%s is a valid IPv4 address.\n", str); - } else { - printf("%s is an invalid IPv4 address.\n", str); - } -} +void validate(const char *str); int main(void) @@ -99,6 +91,16 @@ main(void) } return EXIT_SUCCESS; } + +void +validate(const char *str) +{ + if (iscidraddr4(str)) { + printf("%s is a valid IPv4 address.\n", str); + } else { + printf("%s is an invalid IPv4 address.\n", str); + } +} ``` Expected output: @@ -129,16 +131,7 @@ when the input given is a valid IPv6 address, and otherwise returns 0. const char *valid[] = { "::", "::1", "0000:0000:0000:0000:0000:0000:0000:0000" }; const char *invalid[] = { "foobar", "00:::0", NULL }; - -void -validate(const char *str) -{ - if (isinetaddr6(str)) { - printf("%s is a valid IPv6 address.\n", str); - } else { - printf("%s is an invalid IPv6 address.\n", str); - } -} +void validate(const char *str); int main(void) @@ -153,6 +146,16 @@ main(void) } return EXIT_SUCCESS; } + +void +validate(const char *str) +{ + if (isinetaddr6(str)) { + printf("%s is a valid IPv6 address.\n", str); + } else { + printf("%s is an invalid IPv6 address.\n", str); + } +} ``` Expected output: diff --git a/share/isinetaddr/examples/iscidraddr4.c b/share/isinetaddr/examples/iscidraddr4.c index 993bb1e..025c3ed 100644 --- a/share/isinetaddr/examples/iscidraddr4.c +++ b/share/isinetaddr/examples/iscidraddr4.c @@ -4,16 +4,7 @@ const char *valid[] = { "127.0.0.1", "192.168.2.1/32", "192.168.2.1/0" }; const char *invalid[] = { "foobar", "0.0.0.0.0", "192.168.2.1/33" }; - -void -validate(const char *str) -{ - if (iscidraddr4(str)) { - printf("%s is a valid IPv4 address.\n", str); - } else { - printf("%s is an invalid IPv4 address.\n", str); - } -} +void validate(const char *str); int main(void) @@ -28,3 +19,13 @@ main(void) } return EXIT_SUCCESS; } + +void +validate(const char *str) +{ + if (iscidraddr4(str)) { + printf("%s is a valid IPv4 address.\n", str); + } else { + printf("%s is an invalid IPv4 address.\n", str); + } +} diff --git a/share/isinetaddr/examples/isinetaddr4.c b/share/isinetaddr/examples/isinetaddr4.c index 9746325..5517fe0 100644 --- a/share/isinetaddr/examples/isinetaddr4.c +++ b/share/isinetaddr/examples/isinetaddr4.c @@ -4,16 +4,7 @@ const char *valid[] = { "127.0.0.1", "1.1.1.1", "0.0.0.0" }; const char *invalid[] = { "foobar", "0.0.0.0.0", NULL }; - -void -validate(const char *str) -{ - if (isinetaddr4(str)) { - printf("%s is a valid IPv4 address.\n", str); - } else { - printf("%s is an invalid IPv4 address.\n", str); - } -} +void validate(const char *str); int main(void) @@ -28,3 +19,13 @@ main(void) } return EXIT_SUCCESS; } + +void +validate(const char *str) +{ + if (isinetaddr4(str)) { + printf("%s is a valid IPv4 address.\n", str); + } else { + printf("%s is an invalid IPv4 address.\n", str); + } +} diff --git a/share/isinetaddr/examples/isinetaddr6.c b/share/isinetaddr/examples/isinetaddr6.c index 7865539..cd7aca6 100644 --- a/share/isinetaddr/examples/isinetaddr6.c +++ b/share/isinetaddr/examples/isinetaddr6.c @@ -4,16 +4,7 @@ const char *valid[] = { "::", "::1", "0000:0000:0000:0000:0000:0000:0000:0000" }; const char *invalid[] = { "foobar", "00:::0", NULL }; - -void -validate(const char *str) -{ - if (isinetaddr6(str)) { - printf("%s is a valid IPv6 address.\n", str); - } else { - printf("%s is an invalid IPv6 address.\n", str); - } -} +void validate(const char *str); int main(void) @@ -28,3 +19,13 @@ main(void) } return EXIT_SUCCESS; } + +void +validate(const char *str) +{ + if (isinetaddr6(str)) { + printf("%s is a valid IPv6 address.\n", str); + } else { + printf("%s is an invalid IPv6 address.\n", str); + } +}