summaryrefslogtreecommitdiff
path: root/lib/prefix.c
diff options
context:
space:
mode:
authorhasso <hasso>2004-10-04 19:10:31 +0000
committerhasso <hasso>2004-10-04 19:10:31 +0000
commitb04c699ecfb4704a67f4583e4ea929a6a3e49856 (patch)
tree9149adb41b7bc1acca6c882ab413f68b19b2a64d /lib/prefix.c
parent97c52f4e397848fb18c689dfe161d0b8f7803722 (diff)
First small part of lib cleanup. Mainly "constification" of arguments and
adding FIXME's.
Diffstat (limited to 'lib/prefix.c')
-rw-r--r--lib/prefix.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/lib/prefix.c b/lib/prefix.c
index 5a3e71bf..d9751e3f 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -66,7 +66,7 @@ family2afi (int family)
/* If n includes p prefix then return 1 else return 0. */
int
-prefix_match (struct prefix *n, struct prefix *p)
+prefix_match (const struct prefix *n, const struct prefix *p)
{
int offset;
int shift;
@@ -94,7 +94,7 @@ prefix_match (struct prefix *n, struct prefix *p)
/* Copy prefix from src to dest. */
void
-prefix_copy (struct prefix *dest, struct prefix *src)
+prefix_copy (struct prefix *dest, const struct prefix *src)
{
dest->family = src->family;
dest->prefixlen = src->prefixlen;
@@ -127,7 +127,7 @@ prefix_copy (struct prefix *dest, struct prefix *src)
* as '==' (which is different from prefix_cmp).
*/
int
-prefix_same (struct prefix *p1, struct prefix *p2)
+prefix_same (const struct prefix *p1, const struct prefix *p2)
{
if (p1->family == p2->family && p1->prefixlen == p2->prefixlen)
{
@@ -154,7 +154,7 @@ prefix_same (struct prefix *p1, struct prefix *p2)
* from prefix_same).
*/
int
-prefix_cmp (struct prefix *p1, struct prefix *p2)
+prefix_cmp (const struct prefix *p1, const struct prefix *p2)
{
int offset;
int shift;
@@ -181,8 +181,8 @@ prefix_cmp (struct prefix *p1, struct prefix *p2)
}
/* Return prefix family type string. */
-char *
-prefix_family_str (struct prefix *p)
+const char *
+prefix_family_str (const struct prefix *p)
{
if (p->family == AF_INET)
return "inet";
@@ -213,7 +213,7 @@ prefix_ipv4_free (struct prefix_ipv4 *p)
/* When string format is invalid return 0. */
int
-str2prefix_ipv4 (char *str, struct prefix_ipv4 *p)
+str2prefix_ipv4 (const char *str, struct prefix_ipv4 *p)
{
int ret;
int plen;
@@ -335,7 +335,7 @@ apply_mask_ipv4 (struct prefix_ipv4 *p)
/* If prefix is 0.0.0.0/0 then return 1 else return 0. */
int
-prefix_ipv4_any (struct prefix_ipv4 *p)
+prefix_ipv4_any (const struct prefix_ipv4 *p)
{
return (p->prefix.s_addr == 0 && p->prefixlen == 0);
}
@@ -362,7 +362,7 @@ prefix_ipv6_free (struct prefix_ipv6 *p)
/* If given string is valid return pin6 else return NULL */
int
-str2prefix_ipv6 (char *str, struct prefix_ipv6 *p)
+str2prefix_ipv6 (const char *str, struct prefix_ipv6 *p)
{
char *pnt;
char *cp;
@@ -399,7 +399,8 @@ str2prefix_ipv6 (char *str, struct prefix_ipv6 *p)
return ret;
}
-/* Convert struct in6_addr netmask into integer. */
+/* Convert struct in6_addr netmask into integer.
+ * FIXME return u_char as ip_maskleni() does. */
int
ip6_masklen (struct in6_addr netmask)
{
@@ -470,7 +471,7 @@ apply_mask_ipv6 (struct prefix_ipv6 *p)
}
void
-str2in6_addr (char *str, struct in6_addr *addr)
+str2in6_addr (const char *str, struct in6_addr *addr)
{
int i;
unsigned int x;
@@ -503,10 +504,11 @@ apply_mask (struct prefix *p)
return;
}
-/* Utility function of convert between struct prefix <=> union sockunion */
+/* Utility function of convert between struct prefix <=> union sockunion.
+ * FIXME This function isn't used anywhere. */
struct prefix *
-sockunion2prefix (union sockunion *dest,
- union sockunion *mask)
+sockunion2prefix (const union sockunion *dest,
+ const union sockunion *mask)
{
if (dest->sa.sa_family == AF_INET)
{
@@ -533,9 +535,9 @@ sockunion2prefix (union sockunion *dest,
return NULL;
}
-/* Utility function of convert between struct prefix <=> union sockunion */
+/* Utility function of convert between struct prefix <=> union sockunion. */
struct prefix *
-sockunion2hostprefix (union sockunion *su)
+sockunion2hostprefix (const union sockunion *su)
{
if (su->sa.sa_family == AF_INET)
{
@@ -563,7 +565,7 @@ sockunion2hostprefix (union sockunion *su)
}
int
-prefix_blen (struct prefix *p)
+prefix_blen (const struct prefix *p)
{
switch (p->family)
{
@@ -581,7 +583,7 @@ prefix_blen (struct prefix *p)
/* Generic function for conversion string to struct prefix. */
int
-str2prefix (char *str, struct prefix *p)
+str2prefix (const char *str, struct prefix *p)
{
int ret;
@@ -601,7 +603,7 @@ str2prefix (char *str, struct prefix *p)
}
int
-prefix2str (struct prefix *p, char *str, int size)
+prefix2str (const struct prefix *p, char *str, int size)
{
char buf[BUFSIZ];
@@ -627,9 +629,10 @@ prefix_free (struct prefix *p)
}
/* Utility function. Check the string only contains digit
- character. */
+ * character.
+ * FIXME str.[c|h] would be better place for this function. */
int
-all_digit (char *str)
+all_digit (const char *str)
{
for (; *str != '\0'; str++)
if (!isdigit ((int) *str))
@@ -668,7 +671,8 @@ void apply_classful_mask_ipv4 (struct prefix_ipv4 *p)
ex.) "1.1.0.0" "255.255.0.0" => "1.1.0.0/16"
ex.) "1.0.0.0" NULL => "1.0.0.0/8" */
int
-netmask_str2prefix_str (char *net_str, char *mask_str, char *prefix_str)
+netmask_str2prefix_str (const char *net_str, const char *mask_str,
+ char *prefix_str)
{
struct in_addr network;
struct in_addr mask;