diff options
author | Tom Gundersen <teg@jklm.no> | 2015-11-19 02:27:10 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-11-19 02:27:10 +0100 |
commit | dc9715d41998be6d9e7037955894ff8022d95e71 (patch) | |
tree | 2c420020f7364457f5d7ad1bbac5d719fdb45e3d /src/shared/dns-domain.c | |
parent | 854c1123f5fb6704e900d34c0165360f77ce4ef8 (diff) | |
parent | 06d91ad77eb81a63f3228a21affdb560bf7947c9 (diff) |
Merge pull request #1931 from bengal/dhcp-fqdn-v2
libsystemd-network: add support for "Client FQDN" DHCP option (v2)
Diffstat (limited to 'src/shared/dns-domain.c')
-rw-r--r-- | src/shared/dns-domain.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c index 7af15e0098..423ccca9cc 100644 --- a/src/shared/dns-domain.c +++ b/src/shared/dns-domain.c @@ -715,3 +715,37 @@ int dns_name_single_label(const char *name) { return r == 0 && *name == 0; } + +/* Encode a domain name according to RFC 1035 Section 3.1 */ +int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len) { + uint8_t *label_length; + uint8_t *out; + int r; + + assert_return(buffer, -EINVAL); + assert_return(domain, -EINVAL); + assert_return(domain[0], -EINVAL); + + out = buffer; + + do { + /* reserve a byte for label length */ + if (len == 0) + return -ENOBUFS; + len--; + label_length = out; + out++; + + /* convert and copy a single label */ + r = dns_label_unescape(&domain, (char *) out, len); + if (r < 0) + return r; + + /* fill label length, move forward */ + *label_length = r; + out += r; + len -= r; + } while (r != 0); + + return out - buffer; +} |