diff options
| author | Roy Marples <roy@marples.name> | 2008-08-07 09:45:41 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2008-08-07 09:45:41 +0000 |
| commit | 18b8807b59062aec7bbb0c9f75916cebd5fe629e (patch) | |
| tree | 97282159363dcb3c378cb537cf023e5fb9e7f6b2 /dhcp.c | |
| parent | 4971c6237d01d56a1a6fb34df8568682c7638032 (diff) | |
| download | dhcpcd-18b8807b59062aec7bbb0c9f75916cebd5fe629e.tar.xz | |
Turns out my encoding was correct after all :)
I've now split it out into it's own function for easier maintenance though.
Diffstat (limited to 'dhcp.c')
| -rw-r--r-- | dhcp.c | 45 |
1 files changed, 32 insertions, 13 deletions
@@ -701,13 +701,37 @@ get_option_routes(const struct dhcp_message *dhcp) return routes; } +static size_t +encode_rfc1035(const char *src, uint8_t *dst, size_t len) +{ + const char *c = src; + uint8_t *p = dst; + uint8_t *lp = p++; + + while (c < src + len) { + if (*c == '\0') + break; + if (*c == '.') { + *lp = p - lp - 1; + if (*lp == 0) + return p - dst; + lp = p++; + } else + *p++ = (uint8_t) *c; + c++; + } + *lp = p - lp - 1; + *p++ = '\0'; + return p - dst; +} + ssize_t make_message(struct dhcp_message **message, const struct interface *iface, const struct dhcp_lease *lease, uint32_t xid, uint8_t type, const struct options *options) { struct dhcp_message *dhcp; - uint8_t *m, *p; + uint8_t *m, *lp, *p; uint8_t *n_params = NULL; time_t up = uptime() - iface->start_uptime; uint32_t ul; @@ -832,7 +856,8 @@ make_message(struct dhcp_message **message, } else { /* IETF DHC-FQDN option (81), RFC4702 */ *p++ = DHCP_FQDN; - *p++ = options->hostname[0] + 3; + lp = p; + *p++ = 3; /* * Flags: 0000NEOS * S: 1 => Client requests Server to update @@ -843,19 +868,13 @@ make_message(struct dhcp_message **message, * N: 1 => Client requests Server to not * update DNS */ - *p++ = (options->fqdn & 0x9); - /* FIXME: We should use DNS format as - * RFC4702 claims ASCII is deprecated. - * However I cannot find anything that says - * what this encoding actually is, so we - * use ASCII. - * To flip the encoding bit, set it like so - * *p++ = (options->fqdn & 0x9) | 0x4; */ + *p++ = (options->fqdn & 0x09) | 0x04; *p++ = 0; /* from server for PTR RR */ *p++ = 0; /* from server for A RR if S=1 */ - memcpy(p, options->hostname + 1, - options->hostname[0]); - p += options->hostname[0]; + ul = encode_rfc1035(options->hostname + 1, p, + options->hostname[0]); + *lp += ul; + p += ul; } } |
