Tweak examples

This commit is contained in:
0x1eef 2023-09-15 00:20:57 -03:00
parent 9032382ea4
commit 92d746ea9a
4 changed files with 66 additions and 60 deletions

View file

@ -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:

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}