Author: adrian.chadd
Date: Mon Jun 1 02:11:38 2009
New Revision: 14081
Modified:
branches/LUSCA_HEAD/libcore/radix.c
branches/LUSCA_HEAD/libcore/radix.h
Log:
add some public prefix building tools.
Modified: branches/LUSCA_HEAD/libcore/radix.c
==============================================================================
--- branches/LUSCA_HEAD/libcore/radix.c (original)
+++ branches/LUSCA_HEAD/libcore/radix.c Mon Jun 1 02:11:38 2009
@@ -102,8 +102,27 @@
return (0);
}
-static prefix_t
-*New_Prefix2(int family, void *dest, int bitlen, prefix_t *prefix)
+int
+Init_Prefix(prefix_t *pfx, u_int family, void *dest, u_int bitlen)
+{
+ if (family == AF_INET6) {
+ memcpy(&pfx->add.sin6, dest, 16);
+ pfx->bitlen = (bitlen >= 0) ? bitlen : 128;
+ pfx->family = AF_INET6;
+ pfx->ref_count = 0;
+ return 1;
+ } else if (family == AF_INET) {
+ memcpy(&pfx->add.sin, dest, 4);
+ pfx->bitlen = (bitlen >= 0) ? bitlen : 32;
+ pfx->family = AF_INET;
+ pfx->ref_count = 0;
+ return 1;
+ } else
+ return 0;
+}
+
+prefix_t
+*New_Prefix(int family, void *dest, int bitlen, prefix_t *prefix)
{
int dynamic_allocated = 0;
int default_bitlen = 32;
@@ -144,7 +163,7 @@
return (NULL);
if (prefix->ref_count == 0) {
/* make a copy in case of a static prefix */
- return (New_Prefix2(prefix->family, &prefix->add,
+ return (New_Prefix(prefix->family, &prefix->add,
prefix->bitlen, NULL));
}
prefix->ref_count++;
@@ -626,7 +645,7 @@
goto out;
}
- ret = New_Prefix2(ai->ai_addr->sa_family, addr, len, NULL);
+ ret = New_Prefix(ai->ai_addr->sa_family, addr, len, NULL);
if (ret == NULL)
*errmsg = "New_Prefix2 failed";
out:
@@ -658,7 +677,7 @@
prefixlen = maxprefix;
if (prefixlen < 0 || prefixlen > maxprefix)
return NULL;
- return (New_Prefix2(family, blob, prefixlen, NULL));
+ return (New_Prefix(family, blob, prefixlen, NULL));
}
const char *
Modified: branches/LUSCA_HEAD/libcore/radix.h
==============================================================================
--- branches/LUSCA_HEAD/libcore/radix.h (original)
+++ branches/LUSCA_HEAD/libcore/radix.h Mon Jun 1 02:11:38 2009
@@ -95,6 +95,8 @@
} prefix_t;
void Deref_Prefix(prefix_t *prefix);
+extern int Init_Prefix(prefix_t *prefix, u_int af_family, void *dest,
u_int bitlen);
+extern prefix_t *New_Prefix(int family, void *dest, int bitlen, prefix_t
*prefix);
/*
* Originally from MRT include/radix.h
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---