This is WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500, W5200 and W5100. One of them can be selected by enabling it in wiznet.h.
Fork of WIZnet_Library by
WIZnetInterface/DNSClient/dnsname.h@0:b72d22e10709, 2014-05-08 (annotated)
- Committer:
- jbkim
- Date:
- Thu May 08 03:57:58 2014 +0000
- Revision:
- 0:b72d22e10709
1st commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbkim | 0:b72d22e10709 | 1 | // dnsname.h 2013/8/27 |
jbkim | 0:b72d22e10709 | 2 | #pragma once |
jbkim | 0:b72d22e10709 | 3 | //#include <string> |
jbkim | 0:b72d22e10709 | 4 | #include "pico_string.h" |
jbkim | 0:b72d22e10709 | 5 | class dnsname { |
jbkim | 0:b72d22e10709 | 6 | public: |
jbkim | 0:b72d22e10709 | 7 | uint8_t *buf; |
jbkim | 0:b72d22e10709 | 8 | pico_string str; |
jbkim | 0:b72d22e10709 | 9 | dnsname(uint8_t *s) { |
jbkim | 0:b72d22e10709 | 10 | buf = s; |
jbkim | 0:b72d22e10709 | 11 | } |
jbkim | 0:b72d22e10709 | 12 | int decode(int pos) { |
jbkim | 0:b72d22e10709 | 13 | while(1) { |
jbkim | 0:b72d22e10709 | 14 | int len = buf[pos++]; |
jbkim | 0:b72d22e10709 | 15 | if (len == 0x00) { |
jbkim | 0:b72d22e10709 | 16 | break; |
jbkim | 0:b72d22e10709 | 17 | } |
jbkim | 0:b72d22e10709 | 18 | if ((len&0xc0) == 0xc0) { //compress |
jbkim | 0:b72d22e10709 | 19 | int offset = (len&0x3f)<<8|buf[pos]; |
jbkim | 0:b72d22e10709 | 20 | decode(offset); |
jbkim | 0:b72d22e10709 | 21 | return pos+1; |
jbkim | 0:b72d22e10709 | 22 | } |
jbkim | 0:b72d22e10709 | 23 | if (!str.empty()) { |
jbkim | 0:b72d22e10709 | 24 | str.append("."); |
jbkim | 0:b72d22e10709 | 25 | } |
jbkim | 0:b72d22e10709 | 26 | str.append((const char*)(buf+pos), len); |
jbkim | 0:b72d22e10709 | 27 | pos += len; |
jbkim | 0:b72d22e10709 | 28 | } |
jbkim | 0:b72d22e10709 | 29 | return pos; |
jbkim | 0:b72d22e10709 | 30 | } |
jbkim | 0:b72d22e10709 | 31 | |
jbkim | 0:b72d22e10709 | 32 | int encode(int pos, char* s) { |
jbkim | 0:b72d22e10709 | 33 | while(*s) { |
jbkim | 0:b72d22e10709 | 34 | char *f = strchr(s, '.'); |
jbkim | 0:b72d22e10709 | 35 | if (f == NULL) { |
jbkim | 0:b72d22e10709 | 36 | int len = strlen(s); |
jbkim | 0:b72d22e10709 | 37 | buf[pos++] = len; |
jbkim | 0:b72d22e10709 | 38 | memcpy(buf+pos, s, len); |
jbkim | 0:b72d22e10709 | 39 | pos += len; |
jbkim | 0:b72d22e10709 | 40 | break; |
jbkim | 0:b72d22e10709 | 41 | } |
jbkim | 0:b72d22e10709 | 42 | int len = f - s; |
jbkim | 0:b72d22e10709 | 43 | buf[pos++] = len; |
jbkim | 0:b72d22e10709 | 44 | memcpy(buf+pos, s, len); |
jbkim | 0:b72d22e10709 | 45 | s = f+1; |
jbkim | 0:b72d22e10709 | 46 | pos += len; |
jbkim | 0:b72d22e10709 | 47 | } |
jbkim | 0:b72d22e10709 | 48 | buf[pos++] = 0x00; |
jbkim | 0:b72d22e10709 | 49 | return pos; |
jbkim | 0:b72d22e10709 | 50 | } |
jbkim | 0:b72d22e10709 | 51 | }; |
jbkim | 0:b72d22e10709 | 52 |