]> git.meshlink.io Git - catta/blobdiff - util.c
* add DNS packet name compression
[catta] / util.c
diff --git a/util.c b/util.c
index 3edaa8878398166b13e36bfc3efdba6a404cabc5..0fcedc71c0fee844ba99015c4b5a6fcd421bb883 100644 (file)
--- a/util.c
+++ b/util.c
@@ -125,3 +125,34 @@ gint flx_age(const GTimeVal *a) {
 
     return flx_timeval_diff(&now, a);
 }
+
+gboolean flx_domain_equal(const gchar *a, const gchar *b) {
+    g_assert(a);
+    g_assert(b);
+
+    for (;;) {
+        if (*a == 0 && *b == 0)
+            return TRUE;
+        
+        if (*a == 0 && *b == '.' && *(b+1) == 0)
+            return TRUE;
+
+        if (*a == '.' && *(a+1) == 0 && *b == 0)
+            return TRUE;
+
+        if (*a != *b)
+            return FALSE;
+
+        a++;
+        b++;
+    }
+}
+
+guint flx_domain_hash(const gchar *p) {
+    char t[256];
+    strncpy(t, p, sizeof(t)-1);
+    t[sizeof(t)-1] = 0;
+
+    return g_int_hash(t);
+}
+