summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/udhcp/domain_codec.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/networking/udhcp/domain_codec.c b/networking/udhcp/domain_codec.c
index c81372a..f116964 100644
--- a/networking/udhcp/domain_codec.c
+++ b/networking/udhcp/domain_codec.c
@@ -6,8 +6,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-
-#include "common.h"
+#ifdef DNS_COMPR_TESTING
+# define FAST_FUNC /* nothing */
+# define xmalloc malloc
+# include <stdlib.h>
+# include <stdint.h>
+# include <string.h>
+# include <stdio.h>
+#else
+# include "common.h"
+#endif
#define NS_MAXDNAME 1025 /* max domain name length */
#define NS_MAXCDNAME 255 /* max compressed domain name length */
@@ -213,3 +221,28 @@ uint8_t* FAST_FUNC dname_enc(const uint8_t *cstr, int clen, const char *src, int
*retlen = d - dname + 1;
return dname;
}
+
+#ifdef DNS_COMPR_TESTING
+/* gcc -Wall -DDNS_COMPR_TESTING domain_codec.c -o domain_codec && ./domain_codec */
+int main(int argc, char **argv)
+{
+ int len;
+ uint8_t *encoded;
+
+#define DNAME_DEC(encoded,pre) dname_dec((uint8_t*)(encoded), sizeof(encoded), (pre))
+ printf("'%s'\n", DNAME_DEC("\4host\3com\0", "test1:"));
+ printf("test2:'%s'\n", DNAME_DEC("\4host\3com\0\4host\3com\0", ""));
+ printf("test3:'%s'\n", DNAME_DEC("\4host\3com\0\xC0\0", ""));
+ printf("test4:'%s'\n", DNAME_DEC("\4host\3com\0\xC0\5", ""));
+ printf("test5:'%s'\n", DNAME_DEC("\4host\3com\0\xC0\5\1z\xC0\xA", ""));
+
+#define DNAME_ENC(cache,source,lenp) dname_enc((uint8_t*)(cache), sizeof(cache), (source), (lenp))
+ encoded = dname_enc(NULL, 0, "test.net", &len);
+ printf("test6:'%s' len:%d\n", dname_dec(encoded, len, ""), len);
+ encoded = DNAME_ENC("\3net\0", "test.net", &len);
+ printf("test7:'%s' len:%d\n", dname_dec(encoded, len, ""), len);
+ encoded = DNAME_ENC("\4test\3net\0", "test.net", &len);
+ printf("test8:'%s' len:%d\n", dname_dec(encoded, len, ""), len);
+ return 0;
+}
+#endif