aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-03-24 16:43:16 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-24 16:43:16 +0100
commit3d9c69fb4fd0de40db14d2fa095df98a4bacebc3 (patch)
treeb68b17cc913a5a5d7c7be04a92360fddfd43506d /networking/udhcp
parent702f7d6c0bb3242e66efb4d1c55b51e535935eab (diff)
downloadbusybox-3d9c69fb4fd0de40db14d2fa095df98a4bacebc3.tar.gz
udhcp: add testing bits to dns en/decoder
we had two bugs there at least, must have testing Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp')
-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 c81372ad2..f116964b7 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