Ethernet interface for W5500 with bug fixed in socket::close()
Fork of EthernetInterfaceW5500 by
DNSClient/dnsname.h@5:fb15c35d1e28, 2013-08-27 (annotated)
- Committer:
- va009039
- Date:
- Tue Aug 27 12:50:11 2013 +0000
- Revision:
- 5:fb15c35d1e28
WIZ820ioInterface?first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 5:fb15c35d1e28 | 1 | // dnsname.h 2013/8/27 |
va009039 | 5:fb15c35d1e28 | 2 | #pragma once |
va009039 | 5:fb15c35d1e28 | 3 | //#include <string> |
va009039 | 5:fb15c35d1e28 | 4 | #include "pico_string.h" |
va009039 | 5:fb15c35d1e28 | 5 | class dnsname { |
va009039 | 5:fb15c35d1e28 | 6 | public: |
va009039 | 5:fb15c35d1e28 | 7 | uint8_t *buf; |
va009039 | 5:fb15c35d1e28 | 8 | pico_string str; |
va009039 | 5:fb15c35d1e28 | 9 | dnsname(uint8_t *s) { |
va009039 | 5:fb15c35d1e28 | 10 | buf = s; |
va009039 | 5:fb15c35d1e28 | 11 | } |
va009039 | 5:fb15c35d1e28 | 12 | int decode(int pos) { |
va009039 | 5:fb15c35d1e28 | 13 | while(1) { |
va009039 | 5:fb15c35d1e28 | 14 | int len = buf[pos++]; |
va009039 | 5:fb15c35d1e28 | 15 | if (len == 0x00) { |
va009039 | 5:fb15c35d1e28 | 16 | break; |
va009039 | 5:fb15c35d1e28 | 17 | } |
va009039 | 5:fb15c35d1e28 | 18 | if ((len&0xc0) == 0xc0) { //compress |
va009039 | 5:fb15c35d1e28 | 19 | int offset = (len&0x3f)<<8|buf[pos]; |
va009039 | 5:fb15c35d1e28 | 20 | decode(offset); |
va009039 | 5:fb15c35d1e28 | 21 | return pos+1; |
va009039 | 5:fb15c35d1e28 | 22 | } |
va009039 | 5:fb15c35d1e28 | 23 | if (!str.empty()) { |
va009039 | 5:fb15c35d1e28 | 24 | str.append("."); |
va009039 | 5:fb15c35d1e28 | 25 | } |
va009039 | 5:fb15c35d1e28 | 26 | str.append((const char*)(buf+pos), len); |
va009039 | 5:fb15c35d1e28 | 27 | pos += len; |
va009039 | 5:fb15c35d1e28 | 28 | } |
va009039 | 5:fb15c35d1e28 | 29 | return pos; |
va009039 | 5:fb15c35d1e28 | 30 | } |
va009039 | 5:fb15c35d1e28 | 31 | |
va009039 | 5:fb15c35d1e28 | 32 | int encode(int pos, char* s) { |
va009039 | 5:fb15c35d1e28 | 33 | while(*s) { |
va009039 | 5:fb15c35d1e28 | 34 | char *f = strchr(s, '.'); |
va009039 | 5:fb15c35d1e28 | 35 | if (f == NULL) { |
va009039 | 5:fb15c35d1e28 | 36 | int len = strlen(s); |
va009039 | 5:fb15c35d1e28 | 37 | buf[pos++] = len; |
va009039 | 5:fb15c35d1e28 | 38 | memcpy(buf+pos, s, len); |
va009039 | 5:fb15c35d1e28 | 39 | pos += len; |
va009039 | 5:fb15c35d1e28 | 40 | break; |
va009039 | 5:fb15c35d1e28 | 41 | } |
va009039 | 5:fb15c35d1e28 | 42 | int len = f - s; |
va009039 | 5:fb15c35d1e28 | 43 | buf[pos++] = len; |
va009039 | 5:fb15c35d1e28 | 44 | memcpy(buf+pos, s, len); |
va009039 | 5:fb15c35d1e28 | 45 | s = f+1; |
va009039 | 5:fb15c35d1e28 | 46 | pos += len; |
va009039 | 5:fb15c35d1e28 | 47 | } |
va009039 | 5:fb15c35d1e28 | 48 | buf[pos++] = 0x00; |
va009039 | 5:fb15c35d1e28 | 49 | return pos; |
va009039 | 5:fb15c35d1e28 | 50 | } |
va009039 | 5:fb15c35d1e28 | 51 | }; |