summaryrefslogtreecommitdiff
path: root/src/check_prefix_boundary.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/check_prefix_boundary.c')
-rw-r--r--src/check_prefix_boundary.c78
1 files changed, 56 insertions, 22 deletions
diff --git a/src/check_prefix_boundary.c b/src/check_prefix_boundary.c
index b432c788..5fa80d50 100644
--- a/src/check_prefix_boundary.c
+++ b/src/check_prefix_boundary.c
@@ -1,4 +1,33 @@
-#include "check_ucast_static.h"
+/*
+ * Check format of network prefix
+ */
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+typedef struct
+{
+ uint8_t family;
+ uint8_t bytelen;
+ unsigned int plen;
+ uint32_t data[4];
+} inet_prefix;
+
+static void err(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+
+ exit(1);
+}
static void usage(void)
{
@@ -6,6 +35,32 @@ static void usage(void)
exit(1);
}
+static void get_addr_1(inet_prefix *addr, const char *name, int family)
+{
+ memset(addr, 0, sizeof(*addr));
+
+ if (strchr(name, ':')) {
+ addr->family = AF_INET6;
+ addr->bytelen = 16;
+ if (family != AF_UNSPEC && family != AF_INET6)
+ err("IPV6 address not allowed\n");
+
+ if (inet_pton(AF_INET6, name, addr->data) <= 0)
+ err("Invalid IPV6 address: %s\n", name);
+
+ return;
+ }
+
+ addr->family = AF_INET;
+ addr->bytelen = 4;
+ if (family != AF_UNSPEC && family != AF_INET)
+ err("IPV4 address not allowed\n");
+
+ if (inet_pton(AF_INET, name, addr->data) <= 0)
+ err("Invalid IPV4 address: %s\n", name);
+ return;
+}
+
static void get_prefix_1(inet_prefix *dst, char *arg, int family)
{
char *slash, *endp;
@@ -77,27 +132,6 @@ int main(int argc, char **argv)
inet_ntop(msk.family, msk.data, buf, sizeof buf));
}
- /*
- * Macros to check for Mcast are based on:
- *
- * Addr dst.data
- * 224.1.2.2 ==> 0x030201e0
- * ff01:0203:: ==> 0x030201ff
- *
- */
- if (family == AF_INET) {
- if (IS_MULTICAST(dst.data[0])) {
- err("Invalid Prefix...Route cannot be Multicast\n");
- }
- if (IS_BROADCAST(dst.data[0])) {
- err("Invalid Prefix...Route cannot be Broadcast\n");
- }
- } else if (family == AF_INET6) {
- if (IS_IPV6_MULTICAST(dst.data[0])) {
- err("Invalid Prefix...Route cannot be IPv6 Multicast\n");
- }
- }
-
}
return 0;