aboutsummaryrefslogtreecommitdiff
path: root/src/cidr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cidr.c')
-rw-r--r--src/cidr.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/cidr.c b/src/cidr.c
index 7566fa6..32c7905 100644
--- a/src/cidr.c
+++ b/src/cidr.c
@@ -1,4 +1,4 @@
-/* grecs - Gray's Extensible Configuration System
+/* argot - Gray's Extensible Configuration System
Copyright (C) 2007-2016 Sergey Poznyakoff
Grecs is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
-#include "grecs.h"
+#include "argot.h"
static void
uint32_to_bytes (unsigned char *bytes, uint32_t u)
@@ -37,7 +37,7 @@ uint32_to_bytes (unsigned char *bytes, uint32_t u)
}
int
-grecs_inaddr_to_bytes(int af, void *buf, unsigned char *bytes)
+argot_inaddr_to_bytes(int af, void *buf, unsigned char *bytes)
{
uint32_t u;
@@ -55,7 +55,7 @@ grecs_inaddr_to_bytes(int af, void *buf, unsigned char *bytes)
}
int
-grecs_sockaddr_to_bytes(unsigned char *bytes, struct sockaddr const *sa)
+argot_sockaddr_to_bytes(unsigned char *bytes, struct sockaddr const *sa)
{
switch (sa->sa_family) {
case AF_INET:
@@ -71,19 +71,19 @@ grecs_sockaddr_to_bytes(unsigned char *bytes, struct sockaddr const *sa)
}
int
-grecs_sockaddr_to_cidr(struct grecs_cidr *cidr, const struct sockaddr *sa)
+argot_sockaddr_to_cidr(struct argot_cidr *cidr, const struct sockaddr *sa)
{
- unsigned char address[GRECS_INADDR_BYTES];
+ unsigned char address[ARGOT_INADDR_BYTES];
int len;
int i;
- len = grecs_sockaddr_to_bytes(address, sa);
+ len = argot_sockaddr_to_bytes(address, sa);
if (len == 0)
return -1;
cidr->family = sa->sa_family;
cidr->len = len;
memcpy(cidr->address, address, sizeof(cidr->address));
- for (i = 0; i < GRECS_INADDR_BYTES; i++)
+ for (i = 0; i < ARGOT_INADDR_BYTES; i++)
cidr->netmask[i] = 0xff;
return 0;
}
@@ -96,21 +96,21 @@ masklen_to_netmask(unsigned char *buf, size_t len, size_t masklen)
cnt = masklen / 8;
for (i = 0; i < cnt; i++)
buf[i] = 0xff;
- if (i == GRECS_INADDR_BYTES)
+ if (i == ARGOT_INADDR_BYTES)
return;
cnt = 8 - masklen % 8;
buf[i++] = (0xff >> cnt) << cnt;
- for (; i < GRECS_INADDR_BYTES; i++)
+ for (; i < ARGOT_INADDR_BYTES; i++)
buf[i] = 0;
}
int
-grecs_str_to_cidr(struct grecs_cidr *pcidr, const char *str,
- grecs_locus_t const *locus)
+argot_str_to_cidr(struct argot_cidr *pcidr, const char *str,
+ argot_locus_t const *locus)
{
int rc;
char ipbuf[41];
- struct grecs_cidr cidr;
+ struct argot_cidr cidr;
char *p;
size_t len;
union {
@@ -125,7 +125,7 @@ grecs_str_to_cidr(struct grecs_cidr *pcidr, const char *str,
len = strlen(str);
if (len > sizeof(ipbuf)) {
- grecs_error(locus, 0, _("invalid network mask: %s"),
+ argot_error(locus, 0, _("invalid network mask: %s"),
str);
return -1;
}
@@ -133,30 +133,30 @@ grecs_str_to_cidr(struct grecs_cidr *pcidr, const char *str,
memcpy(ipbuf, str, len);
ipbuf[len] = 0;
- if (grecs_str_is_ipv4(ipbuf))
+ if (argot_str_is_ipv4(ipbuf))
cidr.family = AF_INET;
- else if (grecs_str_is_ipv6(ipbuf))
+ else if (argot_str_is_ipv6(ipbuf))
cidr.family = AF_INET6;
else {
- grecs_error(locus, 0, _("unrecognized address family: %s"),
+ argot_error(locus, 0, _("unrecognized address family: %s"),
str);
return -1;
}
rc = inet_pton(cidr.family, ipbuf, &inaddr);
if (rc == -1) {
- grecs_error(locus, 0, _("unrecognized address family: %s"),
+ argot_error(locus, 0, _("unrecognized address family: %s"),
str);
return -1;
} else if (rc != 1) {
- grecs_error(locus, 0, _("invalid network address: %s"),
+ argot_error(locus, 0, _("invalid network address: %s"),
str);
return -1;
}
- cidr.len = grecs_inaddr_to_bytes(cidr.family, &inaddr, cidr.address);
+ cidr.len = argot_inaddr_to_bytes(cidr.family, &inaddr, cidr.address);
if (cidr.len == 0) {
- grecs_error(locus, 0, _("unrecognized address family: %s"),
+ argot_error(locus, 0, _("unrecognized address family: %s"),
str);
return -1;
}
@@ -170,19 +170,19 @@ grecs_str_to_cidr(struct grecs_cidr *pcidr, const char *str,
masklen = strtoul(p, &end, 10);
if (*end == 0)
masklen_to_netmask(cidr.netmask, cidr.len, masklen);
- else if ((cidr.family == AF_INET && grecs_str_is_ipv4(p))
+ else if ((cidr.family == AF_INET && argot_str_is_ipv4(p))
|| (cidr.family == AF_INET6
- && grecs_str_is_ipv6(ipbuf))) {
+ && argot_str_is_ipv6(ipbuf))) {
rc = inet_pton(cidr.family, p, &inaddr);
if (rc != 1) {
- grecs_error(locus, 0, _("invalid network mask: %s"),
+ argot_error(locus, 0, _("invalid network mask: %s"),
str);
return -1;
}
- grecs_inaddr_to_bytes(cidr.family, &inaddr,
+ argot_inaddr_to_bytes(cidr.family, &inaddr,
cidr.netmask);
} else {
- grecs_error(locus, 0, _("invalid network mask: %s"),
+ argot_error(locus, 0, _("invalid network mask: %s"),
str);
return -1;
}
@@ -194,7 +194,7 @@ grecs_str_to_cidr(struct grecs_cidr *pcidr, const char *str,
}
int
-grecs_cidr_match(struct grecs_cidr *a, struct grecs_cidr *b)
+argot_cidr_match(struct argot_cidr *a, struct argot_cidr *b)
{
int i;
@@ -208,10 +208,10 @@ grecs_cidr_match(struct grecs_cidr *a, struct grecs_cidr *b)
}
int
-grecs_sockadd_cidr_match(struct sockaddr *sa, struct grecs_cidr *cidr)
+argot_sockadd_cidr_match(struct sockaddr *sa, struct argot_cidr *cidr)
{
- struct grecs_cidr t;
- if (grecs_sockaddr_to_cidr(&t, sa))
+ struct argot_cidr t;
+ if (argot_sockaddr_to_cidr(&t, sa))
return 1;
- return grecs_cidr_match(cidr, &t);
+ return argot_cidr_match(cidr, &t);
}

Return to:

Send suggestions and report system problems to the System administrator.