#include "ipenc.h" #include "panon.h" #include #include #include #include #ifndef HAVE_STRLCPY static size_t strlcpy(char *dest, const char *src, size_t size) { size_t ret; for(ret=0;src[ret] && ret=0 && bits<=32); netmask = masks[bits]; } static uint32_t prefix_substitute(uint32_t ip) { return (prefix & netmask) | (ip & ~netmask); } void enc_init(enum enc_type_t type, char *key) { char cryptopan_key[32]; memset(cryptopan_key,0,sizeof(cryptopan_key)); enc_type = type; switch (enc_type) { case ENC_NONE: break; case ENC_PREFIX_SUBSTITUTION: init_prefix(key); break; case ENC_CRYPTOPAN: strlcpy(cryptopan_key,key,sizeof(cryptopan_key)); panon_init(cryptopan_key); break; default: assert(0 /* unknown encryption type */); _exit(1); } } uint32_t enc_ip(uint32_t orig_addr) { switch (enc_type) { case ENC_NONE: return orig_addr; case ENC_PREFIX_SUBSTITUTION: return prefix_substitute(orig_addr); case ENC_CRYPTOPAN: return cpp_anonymize(orig_addr); default: assert(0 /* unknown encryption type */); _exit(1); } }