mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
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>
This commit is contained in:
parent
702f7d6c0b
commit
3d9c69fb4f
@ -6,8 +6,16 @@
|
|||||||
*
|
*
|
||||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||||
*/
|
*/
|
||||||
|
#ifdef DNS_COMPR_TESTING
|
||||||
#include "common.h"
|
# 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_MAXDNAME 1025 /* max domain name length */
|
||||||
#define NS_MAXCDNAME 255 /* max compressed 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;
|
*retlen = d - dname + 1;
|
||||||
return dname;
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user