#include "in-report.h" #include "masscan-app.h" #include "crypto-base64.h" #include "proto-x509.h" #include "proto-banout.h" #include "smack.h" #include "util-malloc.h" #include #include #include struct CNDB_Entry { unsigned ip; char *name; struct CNDB_Entry *next; }; struct CNDB_Database { struct CNDB_Entry *entries[65536]; }; /*************************************************************************** ***************************************************************************/ static struct CNDB_Database *db = NULL; /*************************************************************************** ***************************************************************************/ static const char * cndb_lookup(unsigned ip) { const struct CNDB_Entry *entry; if (db == NULL) return 0; entry = db->entries[ip&0xFFFF]; while (entry && entry->ip != ip) entry = entry->next; if (entry) return entry->name; else { return 0; } } /*************************************************************************** ***************************************************************************/ static void cndb_add(unsigned ip, const unsigned char *name, size_t name_length) { struct CNDB_Entry *entry; if (name_length == 0) return; if (db == NULL) { db = CALLOC(1, sizeof(*db)); } entry = MALLOC(sizeof(*entry)); entry->ip =ip; entry->name = MALLOC(name_length+1); memcpy(entry->name, name, name_length+1); entry->name[name_length] = '\0'; entry->next = db->entries[ip&0xFFFF]; db->entries[ip&0xFFFF] = entry; } /*************************************************************************** ***************************************************************************/ #if 0 static void cndb_add_cn(unsigned ip, const unsigned char *data, size_t length) { size_t offset = 0; size_t name_offset; size_t name_length; if (length < 7) return; /*cipher:0x39 , safe-we1.dyndns.org*/ if (memcmp(data+offset, "cipher:", 7) != 0) return; offset += 7; /* skip to name */ while (offset < length && data[offset] != ',') offset++; if (offset >= length) return; else offset++; /* skip ',' */ while (offset < length && data[offset] == ' ') offset++; if (offset >= length) return; /* we should have a good name */ name_offset = offset; while (offset < length && data[offset] != ',') offset++; name_length = offset - name_offset; /* now insert into database */ cndb_add(ip, data+name_offset, name_length); } #endif /*************************************************************************** ***************************************************************************/ #if 0 static unsigned found(const char *str, size_t str_len, const unsigned char *p, size_t length) { size_t i; if (str_len > length) return 0; for (i=0; i