1 // RUN: %clangxx %s -o %t -lresolv && %run %t %p 2 3 // -lresolv fails on Android. 4 // UNSUPPORTED: android 5 6 #include <assert.h> 7 #include <resolv.h> 8 #include <string.h> 9 10 #include <sanitizer/msan_interface.h> 11 12 void testWrite() { 13 char unsigned input[] = {0xff, 0xc5, 0xf7, 0xff, 0x00, 0x00, 0xff, 0x0a, 0x00, 14 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 15 0x10, 0x01, 0x05, 0x00, 0x01, 0x0a, 0x67, 0x6f, 0x6f, 16 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00}; 17 char output[1024]; 18 19 int res = dn_expand(input, input + sizeof(input), input + 23, output, 20 sizeof(output)); 21 22 assert(res == 12); 23 assert(strcmp(output, "google\\.com") == 0); 24 } 25 26 void testWriteZeroLength() { 27 char unsigned input[] = { 28 0xff, 0xc5, 0xf7, 0xff, 0x00, 0x00, 0xff, 0x0a, 0x00, 0x00, 0x00, 0x01, 29 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x10, 0x01, 0x05, 0x00, 0x01, 0x00, 30 }; 31 char output[1024]; 32 33 int res = dn_expand(input, input + sizeof(input), input + 23, output, 34 sizeof(output)); 35 36 assert(res == 1); 37 assert(strcmp(output, "") == 0); 38 } 39 40 int main(int iArgc, const char *szArgv[]) { 41 testWrite(); 42 testWriteZeroLength(); 43 44 return 0; 45 } 46