.
Fork of WIZnet_Library by
WIZnetInterface/DNSClient/dnsname.h@9:cb8808b47e69, 2015-05-31 (annotated)
- Committer:
- Bongjun
- Date:
- Sun May 31 10:25:40 2015 +0000
- Revision:
- 9:cb8808b47e69
- Parent:
- 0:b72d22e10709
fix some codes of reading Sn_RX_RSR, Sn_TX_FSR in W5100.cpp, W5200.cpp; added is_fin_received() in W5100, W5200 files
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 |