sq krb_pa_supported_enctypes
[metze/wireshark/wip.git] / mmdbresolve.c
index 81fd75022d78b81a8a13f2ed896a203a095d8037..3b0018976c8ade8766416fc1ad97dff3ae208ded 100644 (file)
 #define MMDBR_STRINGIFY_S(s) #s
 #define OUT_BUF_SIZE 65536
 
+// Uncomment to enable slow lookups. Only useful on Windows for now.
+// #define MMDB_DEBUG_SLOW 1
+
+#ifdef MMDB_DEBUG_SLOW
+#ifdef _WIN32
+#include <Windows.h>
+#endif
+#endif
+
 static const char *co_iso_key[]     = {"country", "iso_code", NULL};
 static const char *co_name_key[]    = {"country", "names", "en", NULL};
 static const char *ci_name_key[]    = {"city", "names", "en", NULL};
@@ -53,7 +62,7 @@ main(int argc, char *argv[])
 {
     char addr_str[MAX_ADDR_LEN+1];
     size_t mmdb_count = 0;
-    MMDB_s *mmdbs = NULL;
+    MMDB_s *mmdbs = NULL, *new_mmdbs;
     int mmdb_err;
 
     char *out_buf = (char *) malloc(OUT_BUF_SIZE);
@@ -74,11 +83,13 @@ main(int argc, char *argv[])
             fprintf(stdout, "db.%zd.status: ", mmdb_count);
             if (mmdb_err == MMDB_SUCCESS) {
                 mmdb_count++;
-                mmdbs = (MMDB_s *) realloc(mmdbs, mmdb_count * sizeof(MMDB_s));
-                if (mmdbs == NULL) {
+                new_mmdbs = (MMDB_s *) realloc(mmdbs, mmdb_count * sizeof(MMDB_s));
+                if (new_mmdbs == NULL) {
+                    free(mmdbs);
                     fprintf(stdout, "ERROR out of memory\n");
                     return 1;
                 }
+                mmdbs = new_mmdbs;
                 mmdbs[mmdb_count - 1] = try_mmdb;
                 fprintf(stdout, "OK\n");
                 fprintf(stdout, "db.%zd.type: %s\n", mmdb_count, mmdbs[mmdb_count - 1].metadata.database_type);
@@ -105,6 +116,12 @@ main(int argc, char *argv[])
         }
         fprintf(stdout, "[%s]\n", addr_str);
 
+#ifdef MMDB_DEBUG_SLOW
+#ifdef _WIN32
+        Sleep(1000);
+#endif
+#endif
+
         for (size_t mmdb_idx = 0; mmdb_idx < mmdb_count; mmdb_idx++) {
             fprintf(stdout, "# %s\n", mmdbs[mmdb_idx].metadata.database_type);
             MMDB_lookup_result_s result = MMDB_lookup_string(&mmdbs[mmdb_idx], addr_str, &gai_err, &mmdb_err);