summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-01-26 12:50:47 +0000
committerRoy Marples <roy@marples.name>2009-01-26 12:50:47 +0000
commit78a68b70693939736dedf197c67b66911a4726b9 (patch)
treedb48556e6b21e303471300c007184c81936b19d4
parent62aabbd9ee748b1c7b0156d651b7bfc015d64b3d (diff)
downloaddhcpcd-78a68b70693939736dedf197c67b66911a4726b9.tar.xz
Optimize code around NULL terminated hostname.
-rw-r--r--dhcp.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/dhcp.c b/dhcp.c
index d5869845..4bb47d31 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -719,28 +719,27 @@ get_option_routes(const struct dhcp_message *dhcp)
}
static size_t
-encode_rfc1035(const char *src, uint8_t *dst, size_t len)
+encode_rfc1035(const char *src, uint8_t *dst)
{
- const char *c = src;
uint8_t *p = dst;
uint8_t *lp = p++;
- if (len == 0)
+ if (*src == '\0')
return 0;
- while (c < src + len) {
- if (*c == '\0')
+ while (*src) {
+ if (*src == '\0')
break;
- if (*c == '.') {
+ if (*src == '.') {
/* Skip the trailing . */
- if (c == src + len - 1)
+ if (src[1] == '\0')
break;
*lp = p - lp - 1;
if (*lp == '\0')
return p - dst;
lp = p++;
} else
- *p++ = (uint8_t) *c;
- c++;
+ *p++ = (uint8_t)*src;
+ src++;
}
*lp = p - lp - 1;
*p++ = '\0';
@@ -894,16 +893,13 @@ make_message(struct dhcp_message **message,
if (options->hostname[0]) {
*p++ = DHO_HOSTNAME;
hp = strchr(options->hostname, '.');
- if (hp) {
- *p++ = hp - options->hostname;
- memcpy(p, options->hostname, hp - options->hostname);
- p += hp - options->hostname;
- } else {
+ if (hp)
+ len = hp - options->hostname;
+ else
len = strlen(options->hostname);
- *p++ = len;
- memcpy(p, options->hostname, len);
- p += len;
- }
+ *p++ = len;
+ memcpy(p, options->hostname, len);
+ p += len;
}
if (options->fqdn != FQDN_DISABLE) {
/* IETF DHC-FQDN option (81), RFC4702 */
@@ -923,8 +919,7 @@ make_message(struct dhcp_message **message,
*p++ = (options->fqdn & 0x09) | 0x04;
*p++ = 0; /* from server for PTR RR */
*p++ = 0; /* from server for A RR if S=1 */
- ul = encode_rfc1035(options->hostname, p,
- strlen(options->hostname));
+ ul = encode_rfc1035(options->hostname, p);
*lp += ul;
p += ul;
}