A set of C functions for IPv(4|6) validation
Find a file
2023-08-26 00:01:41 -03:00
.github/workflows Add GitHub action 2023-08-25 17:38:12 -03:00
include First commit 2023-08-25 15:57:09 -03:00
share/isinetaddr/examples Fix example 2023-08-25 16:18:35 -03:00
src Clarity 2023-08-26 00:01:41 -03:00
test Handle additional edge cases as invalid 2023-08-25 21:01:34 -03:00
.gitignore First commit 2023-08-25 15:57:09 -03:00
.projectile First commit 2023-08-25 15:57:09 -03:00
LICENSE First commit 2023-08-25 15:57:09 -03:00
Makefile Compile with -fstack-protector-all 2023-08-25 20:29:47 -03:00
README.md README: update 2023-08-25 20:46:43 -03:00
VERSION v0.1.2 2023-08-25 23:36:29 -03:00

About

isinetaddr is a simple C library that provides an interface that can be used to validate one or more IPv4 addresses. The library is guided by easy to extend testcases that help verify safety and correctness.

Examples

IPv4

The following example demonstrates the isinetaddr function with both valid and invalid inputs. The isinetaddr function returns 1 when the input given is valid, and otherwise returns 0.

#include <isinetaddr.h>
#include <stdio.h>
#include <stdlib.h>

const char *strings[] = {
  "127.0.0.1", "1.1.1.1", "0.0.0.0",
  "foobar", "0.0.0.0.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 (isinetaddr(str)) {
            printf("%s is a valid IPv4 address\n", str);
        } else {
            printf("%s is an invalid IPv4 address\n", str);
        }
    }
    return EXIT_SUCCESS;
}

When the above source code is compiled and run the output is expected to be as follows:

$ cc -Iinclude src/isinetaddr.c share/isinetaddr/examples/IPv4.c -o example
$ ./example
127.0.0.1 is a valid IPv4 address
1.1.1.1 is a valid IPv4 address
0.0.0.0 is a valid IPv4 address
foobar is an invalid IPv4 address
0.0.0.0.0 is an invalid IPv4 address

Sources

License

BSD Zero Clause.
See LICENSE.