Add examples/isinetaddr6.c
This commit is contained in:
parent
b30d723a0d
commit
c4fbb4b67f
1 changed files with 31 additions and 0 deletions
31
share/isinetaddr/examples/isinetaddr6.c
Normal file
31
share/isinetaddr/examples/isinetaddr6.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <isinetaddr.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const char *strings[] = {
|
||||
/* valid */
|
||||
"::",
|
||||
"::1",
|
||||
"0000:0000:0000:0000:0000:0000:0000:0000",
|
||||
|
||||
/* invalid */
|
||||
"foobar",
|
||||
NULL,
|
||||
"00:::0",
|
||||
};
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
const char *str;
|
||||
const int i = sizeof(strings) / sizeof(strings[0]);
|
||||
for (int j = 0; j < i; j++) {
|
||||
str = strings[j];
|
||||
if (isinetaddr6(str)) {
|
||||
printf("%s is a valid IPv6 address\n", str);
|
||||
} else {
|
||||
printf("%s is an invalid IPv6 address\n", str);
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in a new issue