W5200(WIZ820io) network interface
Embed:
(wiki syntax)
Show/hide line numbers
dnsname.h
00001 // dnsname.h 2012/4/13 00002 #ifndef DNSNAME_H 00003 #define DNSNAME_H 00004 class dnsname { 00005 public: 00006 uint8_t *buf; 00007 string str; 00008 dnsname(uint8_t *s) { 00009 buf = s; 00010 } 00011 int decode(int pos) { 00012 while(1) { 00013 int len = buf[pos++]; 00014 if (len == 0x00) { 00015 break; 00016 } 00017 if ((len&0xc0) == 0xc0) { //compress 00018 int offset = (len&0x3f)<<8|buf[pos]; 00019 decode(offset); 00020 return pos+1; 00021 } 00022 if (!str.empty()) { 00023 str.append("."); 00024 } 00025 str.append((const char*)(buf+pos), len); 00026 pos += len; 00027 } 00028 return pos; 00029 } 00030 00031 int encode(int pos, char* s) { 00032 while(*s) { 00033 char *f = strchr(s, '.'); 00034 if (f == NULL) { 00035 int len = strlen(s); 00036 buf[pos++] = len; 00037 memcpy(buf+pos, s, len); 00038 pos += len; 00039 break; 00040 } 00041 int len = f - s; 00042 buf[pos++] = len; 00043 memcpy(buf+pos, s, len); 00044 s = f+1; 00045 pos += len; 00046 } 00047 buf[pos++] = 0x00; 00048 return pos; 00049 } 00050 }; 00051 #endif //DNSNAME_H
Generated on Tue Jul 12 2022 19:58:52 by 1.7.2