summaryrefslogtreecommitdiffstats
path: root/dhcp.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-08-07 09:45:41 +0000
committerRoy Marples <roy@marples.name>2008-08-07 09:45:41 +0000
commit18b8807b59062aec7bbb0c9f75916cebd5fe629e (patch)
tree97282159363dcb3c378cb537cf023e5fb9e7f6b2 /dhcp.c
parent4971c6237d01d56a1a6fb34df8568682c7638032 (diff)
downloaddhcpcd-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.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/dhcp.c b/dhcp.c
index 578ec112..0f8a1724 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -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;
}
}