[hipl-commit] [trunk] Rev 3907: Forgot to bzr add hit.c and hit.h.

  • From: Miika Komu <miika@xxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Wed, 10 Mar 2010 15:04:07 +0200

Committer: Miika Komu <miika@xxxxxx>
Date: Wed Mar 10 15:04:05 2010 +0200
Revision: 3907
Revision-id: miika@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: trunk

Log:
  Forgot to bzr add hit.c and hit.h.

Modified:
  A  lib/core/hit.c
  A  lib/core/hit.h

=== added file 'lib/core/hit.c'
--- lib/core/hit.c      1970-01-01 00:00:00 +0000
+++ lib/core/hit.c      2010-03-10 13:04:05 +0000
@@ -0,0 +1,69 @@
+/**
+ * @file
+ *
+ * Distributed under <a href="http://www.gnu.org/licenses/gpl2.txt";>GNU/GPL</a>
+ *
+ * @brief HIT-related utility functions
+ *
+ * @author Miika Komu <miika@xxxxxx>
+ */
+
+#define _BSD_SOURCE
+
+#include "config.h"
+#include "hit.h"
+#include "debug.h"
+#include "misc.h"
+
+/**
+ * convert a binary HIT into a string
+ *
+ * @param hit a binary HIT
+ * @param prefix an optional HIT prefix as a string
+ * @param hit_str the HIT as a string with the given prefix
+ * @return zero on success and negative on error
+ */
+int hip_convert_hit_to_str(const hip_hit_t *hit,
+                           const char *prefix,
+                           char *hit_str)
+{
+    int err = 0;
+
+    HIP_ASSERT(hit);
+
+    memset(hit_str, 0, INET6_ADDRSTRLEN);
+    err = !hip_in6_ntop(hit, hit_str);
+
+    if (prefix) {
+        memcpy(hit_str + strlen(hit_str), prefix, strlen(prefix));
+    }
+
+    return err;
+}
+/**
+ * compare two HITs to check which HIT is "bigger"
+ *
+ * @param hit1 the first HIT to be compared
+ * @param hit2 the second HIT to be compared
+ *
+ * @return 1 if hit1 was bigger than hit2, or else 0
+ */
+int hip_hit_is_bigger(const struct in6_addr *hit1,
+                      const struct in6_addr *hit2)
+{
+    return ipv6_addr_cmp(hit1, hit2) > 0;
+}
+
+/**
+ * compare two HITs to check which if they are equal
+ *
+ * @param hit1 the first HIT to be compared
+ * @param hit2 the second HIT to be compared
+ *
+ * @return 1 if the HITs were equal and zero otherwise
+ */
+int hip_hit_are_equal(const struct in6_addr *hit1,
+                      const struct in6_addr *hit2)
+{
+    return ipv6_addr_cmp(hit1, hit2) == 0;
+}

=== added file 'lib/core/hit.h'
--- lib/core/hit.h      1970-01-01 00:00:00 +0000
+++ lib/core/hit.h      2010-03-10 13:04:05 +0000
@@ -0,0 +1,13 @@
+#ifndef HIP_LIB_CORE_HIT_H
+#define HIP_LIB_CORE_HIT_H
+
+#include <netinet/in.h>
+#include "protodefs.h"
+
+int hip_convert_hit_to_str(const hip_hit_t *hit, const char *prefix, char 
*str);
+int hip_hit_is_bigger(const struct in6_addr *hit1,
+                      const struct in6_addr *hit2);
+int hip_hit_are_equal(const struct in6_addr *hit1,
+                      const struct in6_addr *hit2);
+
+#endif /* HIP_LIB_CORE_HIT_H */

Other related posts:

  • » [hipl-commit] [trunk] Rev 3907: Forgot to bzr add hit.c and hit.h. - Miika Komu